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
|
@ -485,6 +485,8 @@
|
||||||
:desc "Browse emacs.d" "E" #'doom/browse-in-emacsd
|
:desc "Browse emacs.d" "E" #'doom/browse-in-emacsd
|
||||||
:desc "Find file" "f" #'find-file
|
:desc "Find file" "f" #'find-file
|
||||||
:desc "Find file from here" "F" #'+default/find-file-under-here
|
:desc "Find file from here" "F" #'+default/find-file-under-here
|
||||||
|
(:when (modulep! :config literate)
|
||||||
|
:desc "Open heading in literate config" "h" #'+literate/find-heading)
|
||||||
:desc "Locate file" "l" #'locate
|
:desc "Locate file" "l" #'locate
|
||||||
:desc "Find file in private config" "p" #'doom/find-file-in-private-config
|
:desc "Find file in private config" "p" #'doom/find-file-in-private-config
|
||||||
:desc "Browse private config" "P" #'doom/open-private-config
|
:desc "Browse private config" "P" #'doom/open-private-config
|
||||||
|
|
|
@ -106,6 +106,41 @@
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defalias '+literate/reload #'doom/reload)
|
(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
|
;;; Hooks
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue