In org-mode, I need a function to move point to the last row of a named table of arbitrary length.
Example:
From anywhere in the buffer, I would like to go to:
#+NAME: table-with-unique-name
|---+---------|
| X | Y |
|---+---------|
| a | some |
| b | random |
| c | content | <--first cell in this row
|---+---------|
So:
- I there a more elegant way to go to a named table than to isearch for
#+NAME: table-with-unique-name
andnext-line
?
EDIT: ok, so I'm going with a function that searches for the #+NAME: table-with-unique-name
line and goes to next-line
but that, too, is giving me trouble. With this function:
(defun test-goto-table ()
(interactive)
(goto-char (point-min))
(re-search-forward "^#\\+NAME: table-with-unique-name")
(next-line))
I can successfully go to the table if it exists but if the search fails, point ends up in the beginning of the buffer. Is there a way to wrap re-search-forward
or some other smart way to search the whole buffer? [Resolved by using save-excursion
. See "Edit 2" for working function.]
- [Answered] Once at the table, how can I go to the last line? (I know
there's a function called
org-table-goto-line
but I can't get it to go to last line, only to a specific line number.)
EDIT 2: This works to goto specific cell of a table with a unique name:
(defun tracktable-exists-p ()
(save-excursion
(goto-char (point-min))
(re-search-forward "^#\\+NAME: table-with-unique-name" nil t)))
(defun test-goto-cell ()
(interactive)
(if (tracktable-exists-p)
(let ((tabel "^#\\+NAME: table-with-unique-name"))
(goto-char (point-min))
(re-search-forward tabel nil t)
(show-subtree) ; necessary if the table is hidden in a subtree
(goto-char (org-table-end))
(previous-line 2) ; the dotted line in the bottom is not recognized as part of the table by 'org-table-goto-column' so go two lines up.
(org-table-goto-column 1))
(message "table-with-unique-name doesn't exist")))
Marco Wahl resolved the hard part, so accepting answer.