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.

  • 1
    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 Jun 17 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 Jun 24 at 16:59
  • Please do not post a solution in the question post. Instead, please post it as a separate answer. – Dan Jul 15 at 0:31
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, privacy policy and cookie policy

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