From 6468b0402bf55ee21eb199395e41bc706fa17354 Mon Sep 17 00:00:00 2001 From: Mikhail Skorzhinskii Date: Sat, 12 Sep 2020 18:10:05 +0200 Subject: [PATCH 1/3] org-agenda.el: allow to customize outline path in echo area Some of the org-mode data bases auto-generate file names, so they don't carry a lot of information and can be noisy. Allowing user to show document titles instead could be useful. Showing titles is disabled by default. --- etc/ORG-NEWS | 7 +++++++ lisp/org-agenda.el | 10 +++++++++- lisp/org.el | 25 ++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 0ed626fb7..32f64d84e 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -11,6 +11,13 @@ See the end of the file for license conditions. Please send Org bug reports to mailto:emacs-orgmode@gnu.org. * Version 9.5 (not yet released) +** New options and settings +*** New option ~org-agenda-show-outline-path-prepend~ + +When set to 'title, will show document title in outline path in echo +area instead of file name. When set to nil will show only outline +path. + * Version 9.4 ** Incompatible changes *** Possibly broken internal file links: please check and fix diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 82fe6091c..25c9051e2 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -1044,6 +1044,14 @@ current item's tree, in an indirect buffer." :group 'org-agenda-startup :type 'boolean) +(defcustom org-agenda-show-outline-path-prepend t + "Non-nil means show outline path with document title (if present) in echo area instead of file name." + :group 'org-agenda-startup + :type '(choice + (const :tag "Show only outline path without file name or document title." nil) + (const :tag "Prepend outline path with file name." t) + (const :tag "Prepend outline path with title name. Fallback to file name is no title is present." title))) + (defcustom org-agenda-start-with-entry-text-mode nil "The initial value of entry-text-mode in a newly created agenda window." :group 'org-agenda-startup @@ -8777,7 +8785,7 @@ When called with a prefix argument, include all archive files as well." (org-agenda-tree-to-indirect-buffer nil) (org-agenda-show))) (and org-agenda-show-outline-path - (org-with-point-at m (org-display-outline-path t)))))) + (org-with-point-at m (org-display-outline-path org-agenda-show-outline-path-prepend)))))) (defun org-agenda-show-tags () "Show the tags applicable to the current item." diff --git a/lisp/org.el b/lisp/org.el index 020cfc873..d13d78dbf 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8024,10 +8024,24 @@ the default is \"/\"." (setf (substring fpath (- width 2)) ".."))) fpath)) -(defun org-display-outline-path (&optional file current separator just-return-string) +(defun org-get-title-from-file (file) + "Collect tilte from the provided `org-mode' FILE." + (let (title) + (when file + (with-current-buffer + (get-file-buffer file) + (pcase (org-collect-keywords '("TITLE")) + (`(("TITLE" . ,val)) + (setq title (car val))))) + title))) + + +(defun org-display-outline-path (&optional file-or-title current separator just-return-string) "Display the current outline path in the echo area. -If FILE is non-nil, prepend the output with the file name. +If FILE-OR-TITLE is 'title, prepend outline with file title. If +it is non-nil or title is not present in document, prepend +outline path with the file name. If CURRENT is non-nil, append the current heading to the output. SEPARATOR is passed through to `org-format-outline-path'. It separates the different parts of the path and defaults to \"/\". @@ -8035,6 +8049,8 @@ If JUST-RETURN-STRING is non-nil, return a string, don't display a message." (interactive "P") (let* (case-fold-search (bfn (buffer-file-name (buffer-base-buffer))) + (title (when (and file-or-title (string= file-or-title 'title)) + (org-get-title-from-file bfn))) (path (and (derived-mode-p 'org-mode) (org-get-outline-path))) res) (when current (setq path (append path @@ -8046,7 +8062,10 @@ If JUST-RETURN-STRING is non-nil, return a string, don't display a message." (org-format-outline-path path (1- (frame-width)) - (and file bfn (concat (file-name-nondirectory bfn) separator)) + (and file-or-title bfn (concat (if (and (string= file-or-title 'title) title) + title + (file-name-nondirectory bfn)) + separator)) separator)) (add-face-text-property 0 (length res) `((t :height ,(face-attribute 'default :height))) -- 2.28.0