Search code examples
emacsorg-modespacemacs

how to get column name and field name at point in org-table


table like this:

|  Time | ---AAA ---  | ---BBB ---  |
|-------+-------------+-------------+
|  9:45 |             |             |
| 10:00 |             |             |
| 10:15 |  i am here  |             |
| 10:30 |             |             |
| 10:45 |             |             |
|-------+-------------+-------------+

When I typed at line "i am here", is there any build-in functions to do this?

get-current-column-name(),return "AAA"
get-current-line-name(),return "10:15"

Solution

  • I can not find any build-in function, so I write them, hope it helps

    (defun dindom/org-table-get-current-colname()
      "get current column name if in org table"
      (if (org-table-p)
          (org-table-get 1 nil)
        (message "not in table!")
        )
      )
    
    (defun dindom/org-table-get-current-linename()
      "get current line name if in org table"
      (if (org-table-p)
          (org-table-get nil 1)
        (message "not in table!")
        )
      )
    

    or use org-table-get-field:

    (defun dindom/org-table-get-current-linename()
      "get current line name if in org table"
      (if (org-table-p)
          (save-excursion
            (org-table-get-field 1)
            )
        (message "not in table!")
        )
      )