emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-agenda.el: customise outline path in echo area
@ 2021-12-25 15:24 Mikhail Skorzhinskii
  2021-12-26 13:44 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-25 15:24 UTC (permalink / raw)
  To: Org Mode


* lisp/org-agenda.el (org-agenda-show-outline-path): add an option to
show document title in outline path (instead of file name)
* lisp/org.el (org-get-title-from-file): a function to collect the
document title from the org-mode file
* lisp/org.el (org-display-outline-path): add logic that will collect a
document title and put it into the outline path if
org-agenda-show-outline-path set to 'title
---
 lisp/org-agenda.el | 11 ++++++++---
 lisp/org.el        | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 721ef2ced..817354659 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1045,9 +1045,14 @@ current item's tree, in an indirect buffer."
   :type 'boolean)
 
 (defcustom org-agenda-show-outline-path t
-  "Non-nil means show outline path in echo area after line motion."
+  "Non-nil means show outline path in echo area after line motion.
+
+If set to 'title, show document title."
   :group 'org-agenda-startup
-  :type 'boolean)
+  :type '(choice
+         (const :tag "Don't show outline path in agenda view." nil)
+         (const :tag "Show outline path with prepended file name." t)
+         (const :tag "Show outline path with prepended document title.
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."
@@ -9354,7 +9359,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))))))
 
 (defun org-agenda-show-tags ()
   "Show the tags applicable to the current item."
diff --git a/lisp/org.el b/lisp/org.el
index ce4e08eab..eab3aed3c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8166,10 +8166,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 \"/\".
@@ -8177,6 +8191,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
@@ -8188,7 +8204,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)
                            `(:height ,(face-attribute 'default
:height))



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-agenda.el: customise outline path in echo area
  2021-12-25 15:24 [PATCH] org-agenda.el: customise outline path in echo area Mikhail Skorzhinskii
@ 2021-12-26 13:44 ` Ihor Radchenko
  2021-12-26 13:49   ` Mikhail Skorzhinskiy
  2021-12-28 12:01   ` Mikhail Skorzhinskii
  0 siblings, 2 replies; 6+ messages in thread
From: Ihor Radchenko @ 2021-12-26 13:44 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

Thanks for the patch! The addition looks reasonable to me.

> +        (title (when (and file-or-title (string= file-or-title
> 'title))
> ...
> +          (and file-or-title bfn (concat (if (and (string= file-or-
> title 'title) title)

(string= file-or-title 'title) will match FILE-OR-TITLE values "title"
and 'title. I am not sure if it is what you intended to achieve.
Probably, a simple (eq file-or-title 'title) would be sufficient.

Best,
Ihor


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-agenda.el: customise outline path in echo area
  2021-12-26 13:44 ` Ihor Radchenko
@ 2021-12-26 13:49   ` Mikhail Skorzhinskiy
  2021-12-26 14:01     ` Ihor Radchenko
  2021-12-28 12:01   ` Mikhail Skorzhinskii
  1 sibling, 1 reply; 6+ messages in thread
From: Mikhail Skorzhinskiy @ 2021-12-26 13:49 UTC (permalink / raw)
  To: Org Mode

Glad to hear that.

Should I resubmit the patch in this thread? I agree with your change.

Thanks, Mikhail

-- 
  Mikhail Skorzhinskiy
  mskorzhinskiy@eml.cc

On Sun, Dec 26, 2021, at 16:44, Ihor Radchenko wrote:
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
>
> Thanks for the patch! The addition looks reasonable to me.
>
>> +        (title (when (and file-or-title (string= file-or-title
>> 'title))
>> ...
>> +          (and file-or-title bfn (concat (if (and (string= file-or-
>> title 'title) title)
>
> (string= file-or-title 'title) will match FILE-OR-TITLE values "title"
> and 'title. I am not sure if it is what you intended to achieve.
> Probably, a simple (eq file-or-title 'title) would be sufficient.
>
> Best,
> Ihor


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-agenda.el: customise outline path in echo area
  2021-12-26 13:49   ` Mikhail Skorzhinskiy
@ 2021-12-26 14:01     ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2021-12-26 14:01 UTC (permalink / raw)
  To: Mikhail Skorzhinskiy; +Cc: Org Mode

"Mikhail Skorzhinskiy" <mskorzhinskiy@eml.cc> writes:

> Should I resubmit the patch in this thread? I agree with your change.

Yes. Just reply to my message with the new version of the patch.

Best,
Ihor


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-agenda.el: customise outline path in echo area
  2021-12-26 13:44 ` Ihor Radchenko
  2021-12-26 13:49   ` Mikhail Skorzhinskiy
@ 2021-12-28 12:01   ` Mikhail Skorzhinskii
  2022-06-11  8:32     ` Ihor Radchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-28 12:01 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]

Hi Ihor,

Thank you for your comments once again. I've changed string= to eq and
it appears to be working OK.

I've also renamed "title" variable to "title-prop" for better
readability. The -prop suffix should show the reader that it was
extracted from the file, and thus cost some CPU/IO.

I've attached an updated version to this email. Would love to hear what
you think.

Thanks,
Mikhail

On Sun, 2021-12-26 at 21:44 +0800, Ihor Radchenko wrote:
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
> 
> Thanks for the patch! The addition looks reasonable to me.
> 
> > +        (title (when (and file-or-title (string= file-or-title
> > 'title))
> > ...
> > +          (and file-or-title bfn (concat (if (and (string= file-
> > or-
> > title 'title) title)
> 
> (string= file-or-title 'title) will match FILE-OR-TITLE values
> "title"
> and 'title. I am not sure if it is what you intended to achieve.
> Probably, a simple (eq file-or-title 'title) would be sufficient.
> 
> Best,
> Ihor

[-- Attachment #2: 0001-org-agenda.el-customize-outline-path-in-echo-area.patch --]
[-- Type: text/x-patch, Size: 4228 bytes --]

From 1a09ea522b51f2a418b58f0f6122c578a836f69f Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskiy@eml.cc>
Date: Sat, 12 Sep 2020 18:10:05 +0200
Subject: [PATCH 1/5] org-agenda.el: customize outline path in echo area

* lisp/org-agenda.el (org-agenda-show-outline-path): add an option to
show document title in outline path (instead of file name)
* lisp/org.el (org-get-title-from-file): a function to collect the
document title from the org-mode file
* lisp/org.el (org-display-outline-path): add logic that will collect a
document title and put it into the outline path if
org-agenda-show-outline-path set to 'title
---
 lisp/org-agenda.el | 11 ++++++++---
 lisp/org.el        | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 721ef2ced..817354659 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1045,9 +1045,14 @@ current item's tree, in an indirect buffer."
   :type 'boolean)
 
 (defcustom org-agenda-show-outline-path t
-  "Non-nil means show outline path in echo area after line motion."
+  "Non-nil means show outline path in echo area after line motion.
+
+If set to 'title, show document title."
   :group 'org-agenda-startup
-  :type 'boolean)
+  :type '(choice
+	  (const :tag "Don't show outline path in agenda view." nil)
+	  (const :tag "Show outline path with prepended file name." t)
+	  (const :tag "Show outline path with prepended document title. 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."
@@ -9354,7 +9359,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))))))
 
 (defun org-agenda-show-tags ()
   "Show the tags applicable to the current item."
diff --git a/lisp/org.el b/lisp/org.el
index ce4e08eab..8790c72ab 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8166,10 +8166,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 \"/\".
@@ -8177,6 +8191,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-prop (when (and file-or-title (eq 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
@@ -8188,7 +8204,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 (eq file-or-title 'title) title-prop)
+					      title-prop
+					    (file-name-nondirectory bfn))
+				 separator))
 	   separator))
     (add-face-text-property 0 (length res)
 			    `(:height ,(face-attribute 'default :height))
-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-agenda.el: customise outline path in echo area
  2021-12-28 12:01   ` Mikhail Skorzhinskii
@ 2022-06-11  8:32     ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2022-06-11  8:32 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

> Thank you for your comments once again. I've changed string= to eq and
> it appears to be working OK.
>
> I've also renamed "title" variable to "title-prop" for better
> readability. The -prop suffix should show the reader that it was
> extracted from the file, and thus cost some CPU/IO.
>
> I've attached an updated version to this email. Would love to hear what
> you think.

Thanks! And sorry for the late reply. Your patch fell through the cracks
in my todo list.

> * lisp/org-agenda.el (org-agenda-show-outline-path): add an option to
> show document title in outline path (instead of file name)
> * lisp/org.el (org-get-title-from-file): a function to collect the
> document title from the org-mode file
> * lisp/org.el (org-display-outline-path): add logic that will collect a
> document title and put it into the outline path if
> org-agenda-show-outline-path set to 'title

It would make sense to document the new customization in ORG-NEWS.

> +(defun org-get-title-from-file (file)
> +  "Collect tilte from the provided `org-mode' FILE."
> +  (let (title)
              ^ typo
> +    (when file
> +      (with-current-buffer
> +	  (get-file-buffer file)
> +	(pcase (org-collect-keywords '("TITLE"))
> +	  (`(("TITLE" . ,val))
> +	   (setq title (car val)))))
> +      title)))

Note that this function behavior is underfined when FILE buffer does not
exist. It would be better to accept buffer as argument.

Best,
Ihor


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-11  8:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-25 15:24 [PATCH] org-agenda.el: customise outline path in echo area Mikhail Skorzhinskii
2021-12-26 13:44 ` Ihor Radchenko
2021-12-26 13:49   ` Mikhail Skorzhinskiy
2021-12-26 14:01     ` Ihor Radchenko
2021-12-28 12:01   ` Mikhail Skorzhinskii
2022-06-11  8:32     ` Ihor Radchenko

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).