feat(literate): add +literate/find-heading command
A command for jumping to an Org heading in your literate org config file. Close: #7716
This commit is contained in:
parent
d7075b2420
commit
d330642c2e
2 changed files with 37 additions and 0 deletions
|
@ -106,6 +106,41 @@
|
|||
;;;###autoload
|
||||
(defalias '+literate/reload #'doom/reload)
|
||||
|
||||
(defun +literate--flatten-imenu-index (index &optional prefix)
|
||||
"Flatten an org-mode imenu index."
|
||||
(let ((flattened '()))
|
||||
(dolist (item index flattened)
|
||||
(let* ((name (propertize (car item) 'face (intern (format "org-level-%d" (if prefix (+ 2 (cl-count ?/ prefix)) 1)))))
|
||||
(prefix (if prefix (concat prefix "/" name) name)))
|
||||
(if (imenu--subalist-p item)
|
||||
(setq flattened (append flattened (+literate--flatten-imenu-index (cdr item) prefix)))
|
||||
(push (cons prefix (cdr item)) flattened))))
|
||||
(nreverse flattened)))
|
||||
|
||||
(defvar imenu-auto-rescan)
|
||||
;;;###autoload
|
||||
(defun +literate/find-heading (&optional level)
|
||||
"Jump to a heading in your literate org config file."
|
||||
(interactive "P")
|
||||
(let* ((buffer (or (find-buffer-visiting +literate-config-file)
|
||||
(find-file-noselect +literate-config-file t))))
|
||||
(with-current-buffer buffer
|
||||
(let* ((imenu-auto-rescan t)
|
||||
(org-imenu-depth (or level 8))
|
||||
(index (+literate--flatten-imenu-index (imenu--make-index-alist))))
|
||||
(let ((c (current-window-configuration))
|
||||
(result nil))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(switch-to-buffer buffer)
|
||||
(if (modulep! :completion vertico)
|
||||
(setq result (consult-outline level))
|
||||
(let ((entry (assoc (completing-read "Go to heading: " index nil t) index)))
|
||||
(setq result entry)
|
||||
(imenu entry))))
|
||||
(unless result
|
||||
(set-window-configuration c))))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue