0

Is there a quick way to show where a paragraph is sitting in the document structure hierarchy?

* Chapter 1
...
* Chapter 5
** Section 4
...
paragraph X

I would like to tell that paragraph X is sitting under Chapter 5, Section 4 without having to navigate the cursor away from the text.

4
  • 2
    There is a built-in function called org-display-outline-path, which can be activated interactively with M-x ... or can be activated with the SPC keyboard shortcut if the cursor is at the beginning of a heading and org-use-speed-commands is non-nil.
    – lawlist
    Commented Jun 17, 2019 at 18:34
  • 1
    @lawlist this is almost correct except org-display-outline-path doesn't include the current headline. The question suggests it should.
    – jagrg
    Commented Jun 24, 2019 at 16:59
  • Please do not post a solution in the question post. Instead, please post it as a separate answer.
    – Dan
    Commented Jul 15, 2019 at 0:31
  • @jagrg org-display-outline-path has support for an optional argument to specify whether to include the current headline. one can either evaluate a lisp function interactively, or define a custom function and use (org-display-outline-path nil t)
    – hedy
    Commented Sep 2, 2023 at 1:57

2 Answers 2

2

Your function is not defined correctly. You don't need the code inside the interactive line, and you don't need the hook function. This should work fine I think:

(defun org-show-position-in-text () ;; display outline path of hierarchical headings
  (interactive)
  (message (mapconcat #'identity (org-get-outline-path t) "/")))
0

My half-successful attempt:

(defun org-show-position-in-text () ;; display outline path of hierarchical headings
  (interactive (mapconcat #'identity (org-get-outline-path t) "/")))

(add-hook 'org-mode-hook 'org-show-position-in-text)

The above function just about does the job. Only that it throws the error Wrong type argument: listp before showing the full path to the heading.

Please refer to @John Kitchin's answer for the correct code.

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.