Try which-func-mode' for
Org' and `pdf-tools'
This commit is contained in:
parent
29fff0ce0f
commit
b3323461ca
61
README.org
61
README.org
@ -4712,6 +4712,67 @@ it for this buffer is by typing {{{kbd(C-c C-e t U)}}} to export the it to a
|
||||
(global-set-key (kbd "C-c g") #'writegood-mode))
|
||||
#+end_src
|
||||
|
||||
** [[info:emacs#Which Function][Which-function-mode (info)]]
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: sec:which-function-mode
|
||||
:END:
|
||||
|
||||
The code in listing [[lst:setup-which-function-mode]] has stolen ideas from the
|
||||
following links:
|
||||
- [[https://list.orgmode.org/20240205.141235.268481480563517065.teika@gmx.com/][Show current org-mode headline in frame header]].
|
||||
- [[https://emacs.stackexchange.com/questions/30894/][Show current org-mode headline in modeline]].
|
||||
|
||||
#+caption[Setup ~which-function-mode~]:
|
||||
#+caption: Setup ~which-function-mode~.
|
||||
#+name: lst:setup-which-function-mode
|
||||
#+begin_src emacs-lisp -n :results silent
|
||||
;; https://emacs.stackexchange.com/questions/30894/
|
||||
;; https://list.orgmode.org/20240205.141235.268481480563517065.teika@gmx.com/
|
||||
|
||||
(defvar which-func-functions nil)
|
||||
|
||||
(defun which--org-function ()
|
||||
"Return level and title of the current headline.
|
||||
Return the document title when point is above the first headline."
|
||||
(interactive) ;; Keep this function interactive for debugging.
|
||||
(when (eq major-mode 'org-mode)
|
||||
(let (text)
|
||||
(unless (org-at-heading-p)
|
||||
(save-excursion
|
||||
(org-previous-visible-heading 1)
|
||||
(let ((eap (org-element-at-point)))
|
||||
(when (org-element-type-p eap 'keyword)
|
||||
(setq text (format "0|%s" (org-element-property :value eap)))))))
|
||||
(unless text
|
||||
(let* ((chain (org-get-outline-path t))
|
||||
(count (length chain)))
|
||||
(setq text (format "%s|%s" count (nth (1- count) chain)))))
|
||||
text)))
|
||||
|
||||
(add-to-list 'which-func-functions 'which--org-function)
|
||||
|
||||
(defun which--pdf-function ()
|
||||
"Return the title of the current headline.
|
||||
Return \"Front Matter\" when point is above the first headline."
|
||||
(interactive) ;; Keep this function interactive for debugging.
|
||||
(when (eq major-mode 'pdf-view-mode)
|
||||
(let* ((current-page (pdf-view-current-page))
|
||||
(outline (pdf-info-outline (current-buffer)))
|
||||
(hl-count (length outline))
|
||||
(hl-index 0)
|
||||
(hl-page 0)
|
||||
(old-title "Front Matter")
|
||||
(new-title old-title))
|
||||
(while (and (< hl-index hl-count) (< hl-page current-page))
|
||||
(setq old-title new-title)
|
||||
(setq hl-page (alist-get 'page (nth hl-index outline)))
|
||||
(setq new-title (alist-get 'title (nth hl-index outline)))
|
||||
(cl-incf hl-index))
|
||||
(if (< current-page hl-page) old-title new-title))))
|
||||
|
||||
(add-to-list 'which-func-functions 'which--pdf-function)
|
||||
#+end_src
|
||||
|
||||
* [[info:emacs#Saving Emacs Sessions][Saving Emacs sessions (info)]]
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: sec:desktop
|
||||
|
Loading…
Reference in New Issue
Block a user