11

In org-mode whenever I have point on heading it shows me in the mini buffer the full hierarchy. For example, if I have the following in a Org file:

* lvl1
** lvl2
*** lvl3
    some text

And I put point on lvl3 it shows /lvl1/lvl2/lvl3 in the mini buffer. Is there a specific function I can call to obtain this information? I sometimes need to retrieve context and with this it would be easier, no need to move point to the heading.

2
  • What version of org-mode are you using?
    – Melioratus
    Jun 5, 2018 at 19:07
  • 1
    @Melioratus I forgot to mention that I'am using spacemacs. I'am using the org layer and org-version tell me the version is "9.1.13".
    – plx
    Jun 6, 2018 at 7:31

2 Answers 2

17

org-get-outline-path will return a list with the heading hierarchy.

org-format-outline-path will take such a path and format it for display. This is what goes into your mini-buffer.

1
  • 4
    To test this, add an emacs-lisp code block after "some text" in your sample file with content: (org-get-outline-path t), place cursor after the parenthesis, and press C-x C-e.
    – Heikki
    Jun 5, 2018 at 19:22
0

org-display-outline-path displays (or optionally returns a string of) the hierarchy already formatted.

It also has a few optional parameters to customize its behaviour (defaults included in parenthesis):

  • include file name? (no)
  • current heading? (no)
  • custom separator (defaults to "/")
  • just return a string rather than display it? (no).

To obtain a formatted string of the heading including the curret one (lvl3):

(org-display-outline-path nil t "/" t)

=> #( "lvl1/lvl2/lvl3" ...<text properties> )

To strip the text properties from it -- just the string:

(substring-no-properties (org-display-outline-path nil t "/" t))

=> "lvl1/lvl2/lvl3"


IMO this method is simpler than using org-get-outline-path, append current heading (lvl3) and joining it with string-join.

The function org-display-outline-path seems to have been available since around version 7.9.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.