diff --git a/README.org b/README.org index 0b1ab2a..07884fe 100644 --- a/README.org +++ b/README.org @@ -4721,8 +4721,10 @@ it for this buffer is by typing {{{kbd(C-c C-e t U)}}} to export the it to a :CUSTOM_ID: sec:which-function-mode :END: -The code in listing [[lst:setup-which-function-mode]] has stolen ideas from the -following links: +The post [[https://codelearn.me/2024/02/02/emacs-which-function-mode.html][Emacs: which-function-mode]] claims that ~which-function-mode~ works in +~org-mode~. This is true in case all document headlines are simple, but is not +true in case document headlines contain links. 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]]. @@ -4735,30 +4737,32 @@ following links: (defvar which-func-functions nil) -(defun which--org-function () +(defun which-func-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. + (interactive) ;; Keep this function interactive for fixing. (when (eq major-mode 'org-mode) (let (text) + ;; Handle point eventually above the first headline. (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))))))) + ;; Handle point anywhere else. (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) +(add-to-list 'which-func-functions 'which-func-org-function) -(defun which--pdf-function () +(defun which-func-pdf-view-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. + (interactive) ;; Keep this function interactive for fixing. (when (eq major-mode 'pdf-view-mode) (let* ((current-page (pdf-view-current-page)) (outline (pdf-info-outline (current-buffer))) @@ -4774,7 +4778,7 @@ Return \"Front Matter\" when point is above the first headline." (cl-incf hl-index)) (if (< current-page hl-page) old-title new-title)))) -(add-to-list 'which-func-functions 'which--pdf-function) +(add-to-list 'which-func-functions 'which-func-pdf-view-function) #+end_src * [[info:emacs#Saving Emacs Sessions][Saving Emacs sessions (info)]]