What is the key combination to jump directly to the end of BODY of a headline in org-mode?
* Headline title A from here ▮
text text text
text text text
text text text
text text text
text text text
to HERE▮
* Headline title B
I'm not aware of a function that does this (someone will correct me if there is), but you can write your own by getting the :contents-end
property from an org element and going to that buffer location. Something similar to this:
(defun my/org-goto-end-of-contents ()
(interactive)
(let* ((elem (org-element-at-point))
(end-pos (org-element-property :contents-end elem)))
(goto-char end-pos)))
The important part being (org-element-property :content-end elem)
, which returns the value you're looking for. (Take a glance these two functions with C-h f
: org-element-property
and org-element-at-point
)
However, if you want this function to respect the empty line and the end of the buffer, you can spice it up by looking for blank lines, headings, etc:
(defun my/org-goto-end-of-contents ()
(interactive)
(let* ((elem (org-element-at-point))
(end-pos (org-element-property :contents-end elem)))
(goto-char end-pos)
(if (and (or (looking-at-p "[[:space:]]*$")
(org-at-heading-p))
(not (eobp)))
(left-char 1))))
Bind this function to your key of choice and you're good to go.
org-end-of-subtree
which seems to be equivalent to the first command here.
org-element-at-point
and its properties. Thanks, @orgtre!
Commented
Feb 21, 2023 at 6:24
The commands provided by kozina-adjacent go to the end of the current subtree, as does org-end-of-subtree
. However, if one has a heading with text under it followed by several subheadings, one might just want to go to the end of the text before the first subheading. For this I wrote the following command (it does as advertised with a universal argument prefix, but does other things too, and could be further improved):
(defun org-colviewx-beginning-of-contents (&optional arg)
"Go to first non-whitespace character of entry content.
Skips meta-data. When the entry content is only meta-data and
whitespace, go to the first subheading; but if there is no
subheading go to the end of of the last non-meta-data line of
entry, inserting it if necessary.
With a `\\[universal-argument]' prefix argument go to last \
non-whitespace
character instead. With a `\\[universal-argument] \
\\[universal-argument]' prefix argument go to
last non-whitespace character in subtree."
(interactive "P")
(let ((initial-level (org-current-level)))
(org-end-of-meta-data t)
(if (and (org-at-heading-p)
(= initial-level (org-current-level)))
(progn (backward-char)
(when (save-excursion
(backward-char)
(looking-at-p "[^ \n\t]"))
(newline)))
(cond
((equal arg '(4))
(if (re-search-forward "[ \n\t]*\n\\*" nil t)
(goto-char (match-beginning 0))
(org-end-of-subtree)
(re-search-backward "[^ \n\t]")
(goto-char (match-end 0))))
((equal arg '(16))
(org-end-of-subtree t)
(re-search-backward "[^ \n\t]")
(goto-char (match-end 0)))))
(when (called-interactively-p 'interactive)
(org-fold-show-context))))
org-end-of-subtree
function does!
C-e
cursor move to end of the headline title* Headline title HERE ▮
and not to the end of HEADLINE-BODY:...text text text text text text to HERE▮