Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Display where you are in your org tree
(require 'cl)
(defun org-get-header-list (&optional buffer)
"Get the headers of an org buffer as a flat list of headers and levels.
Buffer will default to the current buffer.
Thanks to
for this function!
(with-current-buffer (or buffer (current-buffer))
(let ((tree (org-element-parse-buffer 'headline)))
(lambda (el) (list
(org-element-property :raw-value el) ; get the header text
(org-element-property :begin el) ; get where the header starts
(org-element-property :end el) ; get where the header ends
(org-element-property :level el) ; get depth
;; >> could add other properties here
(defun tw/test-if-between (p e)
"Test if p lies between the second and third elements of e"
(and (>= p (second e))
(<= p (nth 2 e))))
(defun tw/org-where ()
"Display where you are in your org tree"
(mapconcat 'first
(remove-if-not (lambda (x) (tw/test-if-between (point) x))
" > ")))
;; Map this to C-c SPC.
;; (defun my-org-hook ()
;; (define-key org-mode-map (kbd "C-c SPC") 'tw/org-where)
;; )
;; (add-hook 'org-mode-hook 'my-org-hook)
;; Pressing C-c SPC in an org mode buffer should give you
;; "Level 1 > Level 2 > Level 5", etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment