Skip to main content
deleted 1 character in body
Source Link
itsjeyd
  • 14.9k
  • 3
  • 60
  • 87

Here's a functioncommand, based on @itsjeyd's answer, that is robust to the edge case listed in the comment to that answer (that is, when you're on the last heading/subtree):

(defun org-end-of-subtree ()
  (interactive)
  (let ((org-special-ctrl-a/e t))
    (if (condition-case nil
            (outline-forward-same-level 1)
          (error t))
        (progn
          (goto-char (point-max))
          (outline-back-to-heading))
      (outline-previous-visible-heading 1))
    (org-end-of-line 1)))

Here's a function, based on @itsjeyd's answer, that is robust to the edge case listed in the comment to that answer (that is, when you're on the last heading/subtree):

(defun org-end-of-subtree ()
  (interactive)
  (let ((org-special-ctrl-a/e t))
    (if (condition-case nil
            (outline-forward-same-level 1)
          (error t))
        (progn
          (goto-char (point-max))
          (outline-back-to-heading))
      (outline-previous-visible-heading 1))
    (org-end-of-line 1)))

Here's a command, based on @itsjeyd's answer, that is robust to the edge case listed in the comment to that answer (that is, when you're on the last heading/subtree):

(defun org-end-of-subtree ()
  (interactive)
  (let ((org-special-ctrl-a/e t))
    (if (condition-case nil
            (outline-forward-same-level 1)
          (error t))
        (progn
          (goto-char (point-max))
          (outline-back-to-heading))
      (outline-previous-visible-heading 1))
    (org-end-of-line 1)))
Source Link
Dan
  • 33.4k
  • 7
  • 106
  • 171

Here's a function, based on @itsjeyd's answer, that is robust to the edge case listed in the comment to that answer (that is, when you're on the last heading/subtree):

(defun org-end-of-subtree ()
  (interactive)
  (let ((org-special-ctrl-a/e t))
    (if (condition-case nil
            (outline-forward-same-level 1)
          (error t))
        (progn
          (goto-char (point-max))
          (outline-back-to-heading))
      (outline-previous-visible-heading 1))
    (org-end-of-line 1)))