Function: org-up-heading-safe

org-up-heading-safe is a byte-compiled function defined in org.el.gz.

Signature

(org-up-heading-safe)

Documentation

Move to the heading line of which the present line is a subheading.

Return the true heading level, as number or nil when there is no such heading.

When point is not at heading, go to the parent of the current heading. When point is at or inside an inlinetask, go to the containing heading.

This version will not throw an error. It will return the true level of the headline found, or nil if no higher level is found.

When no higher level is found, the still move point to the containing heading, if there is any in the accessible portion of the buffer.

When narrowing is in effect, ignore headings starting before the available portion of the buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-up-heading-safe ()
  "Move to the heading line of which the present line is a subheading.
Return the true heading level, as number or nil when there is no such
heading.

When point is not at heading, go to the parent of the current heading.
When point is at or inside an inlinetask, go to the containing
heading.

This version will not throw an error.  It will return the true level
of the headline found, or nil if no higher level is found.

When no higher level is found, the still move point to the containing
heading, if there is any in the accessible portion of the buffer.

When narrowing is in effect, ignore headings starting before the
available portion of the buffer."
  (let* ((current-heading (org-element-lineage
                           (org-element-at-point)
                           '(headline inlinetask)
                           'with-self))
         (parent (org-element-lineage current-heading 'headline)))
    (if (and parent
             (<= (point-min) (org-element-begin parent)))
        (progn
          (goto-char (org-element-begin parent))
          (org-element-property :true-level parent))
      (when (and current-heading
                 (<= (point-min) (org-element-begin current-heading)))
        (goto-char (org-element-begin current-heading))
        nil))))