Last active
March 9, 2018 21:20
-
-
Save the-ted/cce2c170f8d4dfc60f06073cb73dfe10 to your computer and use it in GitHub Desktop.
Display where you are in your org tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 http://emacs.stackexchange.com/questions/17622/how-can-i-walk-an-org-mode-tree | |
for this function! | |
" | |
(with-current-buffer (or buffer (current-buffer)) | |
(let ((tree (org-element-parse-buffer 'headline))) | |
(org-element-map | |
tree | |
'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" | |
(interactive) | |
(message | |
(mapconcat 'first | |
(remove-if-not (lambda (x) (tw/test-if-between (point) x)) | |
(org-get-header-list)) | |
" > "))) | |
;; | |
;; 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