emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-icalendar.el: customizable vevent summary prefix
@ 2021-12-25 15:24 Mikhail Skorzhinskii
  2021-12-26 21:26 ` Nicolas Goaziou
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-25 15:24 UTC (permalink / raw)
  To: Org Mode


* lisp/ox-icalendar.el (org-icalendar-scheduled-summary-prepend):
configurable prefix for the scheduled headlines
* lisp/ox-icalendar.el (org-icalendar-deadline-summary-prepend):
configurable prefix for the headlines with a deadline
* lisp/ox-icalendar.el (org-icalendar-entry): use a configurable
headline prefixes (see above) instead of hardcoded ones
---
 lisp/ox-icalendar.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 68c5679ea..0a56e08e5 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -84,6 +84,17 @@ keyword."
   :group 'org-export-icalendar
   :type '(repeat (string :tag "Tag")))
 
+(defcustom org-icalendar-scheduled-summary-prepend "S: "
+  "String used for prepending summary in exported scheduled
headlines."
+  :group 'org-export-icalendar
+  :type 'string)
+
+
+(defcustom org-icalendar-deadline-summary-prepend "DL: "
+  "String used for prepending summary in exported deadlines."
+  :group 'org-export-icalendar
+  :type 'string)
+
 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
   "Contexts where iCalendar export should use a deadline time stamp.
 
@@ -607,7 +618,7 @@ inlinetask within the section."
                   (_ (memq 'event-if-not-todo use-deadline)))
                 (org-icalendar--vevent
                  entry deadline (concat "DL-" uid)
-                 (concat "DL: " summary) loc desc cat tz class)))
+                 (concat org-icalendar-deadline-summary-prepend
summary) loc desc cat tz class)))
          (let ((scheduled (org-element-property :scheduled entry))
                (use-scheduled (plist-get info :icalendar-use-
scheduled)))
            (and scheduled
@@ -618,7 +629,7 @@ inlinetask within the section."
                   (_ (memq 'event-if-not-todo use-scheduled)))
                 (org-icalendar--vevent
                  entry scheduled (concat "SC-" uid)
-                 (concat "S: " summary) loc desc cat tz class)))
+                 (concat org-icalendar-scheduled-summary-prepend
summary) loc desc cat tz class)))
          ;; When collecting plain timestamps from a headline and its
          ;; title, skip inlinetasks since collection will happen once
          ;; ENTRY is one of them.



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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2021-12-25 15:24 [PATCH] ox-icalendar.el: customizable vevent summary prefix Mikhail Skorzhinskii
@ 2021-12-26 21:26 ` Nicolas Goaziou
  2021-12-28 12:10   ` Mikhail Skorzhinskii
  0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2021-12-26 21:26 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Hello,

Thanks. Some comments follow.

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

> * lisp/ox-icalendar.el (org-icalendar-scheduled-summary-prepend):
> configurable prefix for the scheduled headlines

"New variable" is enough.

> * lisp/ox-icalendar.el (org-icalendar-deadline-summary-prepend):
> configurable prefix for the headlines with a deadline

Ditto.

> +(defcustom org-icalendar-scheduled-summary-prepend "S: "
> +  "String used for prepending summary in exported scheduled
> headlines."
> +  :group 'org-export-icalendar
> +  :type 'string)
> +
> +
> +(defcustom org-icalendar-deadline-summary-prepend "DL: "
> +  "String used for prepending summary in exported deadlines."
> +  :group 'org-export-icalendar
> +  :type 'string)
> +

Could you add missing :safe and :package-version keywords?

Regards,
-- 
Nicolas Goaziou


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2021-12-26 21:26 ` Nicolas Goaziou
@ 2021-12-28 12:10   ` Mikhail Skorzhinskii
  2022-07-31  7:16     ` Ihor Radchenko
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-28 12:10 UTC (permalink / raw)
  To: Org Mode

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

Hi Nicolas,

Thank you for the reviewing my suggestions. I've fixed issues you've
listed. I've attached new patch to this email.

Let me know what you think.

Thanks,
Mikhail

On Sun, 2021-12-26 at 22:26 +0100, Nicolas Goaziou wrote:
> Hello,
> 
> Thanks. Some comments follow.
> 
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
> 
> > * lisp/ox-icalendar.el (org-icalendar-scheduled-summary-prepend):
> > configurable prefix for the scheduled headlines
> 
> "New variable" is enough.
> 
> > * lisp/ox-icalendar.el (org-icalendar-deadline-summary-prepend):
> > configurable prefix for the headlines with a deadline
> 
> Ditto.
> 
> > +(defcustom org-icalendar-scheduled-summary-prepend "S: "
> > +  "String used for prepending summary in exported scheduled
> > headlines."
> > +  :group 'org-export-icalendar
> > +  :type 'string)
> > +
> > +
> > +(defcustom org-icalendar-deadline-summary-prepend "DL: "
> > +  "String used for prepending summary in exported deadlines."
> > +  :group 'org-export-icalendar
> > +  :type 'string)
> > +
> 
> Could you add missing :safe and :package-version keywords?
> 
> Regards,

[-- Attachment #2: 0003-ox-icalendar.el-customizable-vevent-summary-prefix.patch --]
[-- Type: text/x-patch, Size: 2401 bytes --]

From 6849f0dde1cc8fefbfea0271039e5066a3cb2746 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskiy@eml.cc>
Date: Sat, 12 Sep 2020 18:27:23 +0200
Subject: [PATCH 3/5] ox-icalendar.el: customizable vevent summary prefix

* lisp/ox-icalendar.el (org-icalendar-scheduled-summary-prepend): new
variable
* lisp/ox-icalendar.el (org-icalendar-deadline-summary-prepend): new
variable
* lisp/ox-icalendar.el (org-icalendar-entry): use a configurable
headline prefixes (see above) instead of hardcoded ones
---
 lisp/ox-icalendar.el | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 68c5679ea..189e35946 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -84,6 +84,21 @@ keyword."
   :group 'org-export-icalendar
   :type '(repeat (string :tag "Tag")))
 
+(defcustom org-icalendar-scheduled-summary-prepend "S: "
+  "String used for prepending summary in exported scheduled headlines."
+  :group 'org-export-icalendar
+  :type 'string
+  :package-version '(Org . "9.6")
+  :safe #'stringp)
+
+
+(defcustom org-icalendar-deadline-summary-prepend "DL: "
+  "String used for prepending summary in exported deadlines."
+  :group 'org-export-icalendar
+  :type 'string
+  :package-version '(Org . "9.6")
+  :safe #'stringp)
+
 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
   "Contexts where iCalendar export should use a deadline time stamp.
 
@@ -607,7 +622,7 @@ inlinetask within the section."
 		   (_ (memq 'event-if-not-todo use-deadline)))
 		 (org-icalendar--vevent
 		  entry deadline (concat "DL-" uid)
-		  (concat "DL: " summary) loc desc cat tz class)))
+		  (concat org-icalendar-deadline-summary-prepend summary) loc desc cat tz class)))
 	  (let ((scheduled (org-element-property :scheduled entry))
 		(use-scheduled (plist-get info :icalendar-use-scheduled)))
 	    (and scheduled
@@ -618,7 +633,7 @@ inlinetask within the section."
 		   (_ (memq 'event-if-not-todo use-scheduled)))
 		 (org-icalendar--vevent
 		  entry scheduled (concat "SC-" uid)
-		  (concat "S: " summary) loc desc cat tz class)))
+		  (concat org-icalendar-scheduled-summary-prepend summary) loc desc cat tz class)))
 	  ;; When collecting plain timestamps from a headline and its
 	  ;; title, skip inlinetasks since collection will happen once
 	  ;; ENTRY is one of them.
-- 
2.32.0


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2021-12-28 12:10   ` Mikhail Skorzhinskii
@ 2022-07-31  7:16     ` Ihor Radchenko
  2022-07-31  7:35       ` Mikhail Skorzhinskiy
  0 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-07-31  7:16 UTC (permalink / raw)
  To: Mikhail Skorzhinskii; +Cc: Org Mode

Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:

> Thank you for the reviewing my suggestions. I've fixed issues you've
> listed. I've attached new patch to this email.
>
> Let me know what you think.

Sorry again for the late reply.
The patch looks good, though you may also need to document the new
customization in etc/ORG-NEWS.

However, note that your previous patch is 15LOC, which is the maximum
contribution size we can accept without copyright assignment.
See https://orgmode.org/worg/org-contribute.html#copyright

Best,
Ihor


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-07-31  7:16     ` Ihor Radchenko
@ 2022-07-31  7:35       ` Mikhail Skorzhinskiy
  2022-07-31 13:02         ` Ihor Radchenko
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhinskiy @ 2022-07-31  7:35 UTC (permalink / raw)
  To: Org Mode

Thanks for review, Ihor. I have sent a copyright assignment request. Will resubmit the patches as soon as I complete the process.

-- 
  Mikhail Skorzhinskii
  mskorzhinskii@eml.cc

On Sun, Jul 31, 2022, at 09:16, Ihor Radchenko wrote:
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
>
>> Thank you for the reviewing my suggestions. I've fixed issues you've
>> listed. I've attached new patch to this email.
>>
>> Let me know what you think.
>
> Sorry again for the late reply.
> The patch looks good, though you may also need to document the new
> customization in etc/ORG-NEWS.
>
> However, note that your previous patch is 15LOC, which is the maximum
> contribution size we can accept without copyright assignment.
> See https://orgmode.org/worg/org-contribute.html#copyright
>
> Best,
> Ihor


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-07-31  7:35       ` Mikhail Skorzhinskiy
@ 2022-07-31 13:02         ` Ihor Radchenko
  2022-08-30 13:50           ` Mikhail Skorzhisnkii
  0 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-07-31 13:02 UTC (permalink / raw)
  To: Mikhail Skorzhinskiy; +Cc: Org Mode

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

> Thanks for review, Ihor. I have sent a copyright assignment request. Will resubmit the patches as soon as I complete the process.

Thanks! Note that FSF clerk should reply within 5 working days. If not,
please let us know.

Best,
Ihor


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-07-31 13:02         ` Ihor Radchenko
@ 2022-08-30 13:50           ` Mikhail Skorzhisnkii
  2022-08-31 12:09             ` Ihor Radchenko
                               ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-08-30 13:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

I have signed FSF papers. Attaching a rebased patch with additional changes to
ORG-NEWS

Ihor Radchenko <yantar92@gmail.com> writes:

> “Mikhail Skorzhinskiy” <mskorzhinskii@eml.cc> writes:
>
>> Thanks for review, Ihor. I have sent a copyright assignment request. Will
>> resubmit the patches as soon as I complete the process.
>
> Thanks! Note that FSF clerk should reply within 5 working days. If not,
> please let us know.
>
> Best,
> Ihor

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda.el-customize-outline-path-in-echo-area.patch --]
[-- Type: text/x-diff, Size: 5570 bytes --]

From ceb6c9836032c92a792bf58aab91d74141664f50 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/2] 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-buffer): a function to collect the
document title from the org-mode buffer
* 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
---
 etc/ORG-NEWS       | 10 ++++++++++
 lisp/org-agenda.el | 11 ++++++++---
 lisp/org.el        | 25 ++++++++++++++++++++++---
 3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7dae03dc6..4405489bb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -290,6 +290,12 @@ level used for top level headings, much like how
 headings in HTML export.
 
 ** New options
+*** A new option for custom setting =org-agenda-show-outline-path= to show document title
+
+Settings =org-agenda-show-outline-path=  to ='title= will show title instead of
+the file name at the beginning of the outline. The title of the
+document can be set by special keyword =#+title:=.
+
 *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers
 
 Previously, all the drawers were always folded when opening an Org
@@ -320,6 +326,10 @@ event time when the alarm time is set to 0.  The default value is
 nil -- do not create alarms at the event time.
 
 ** New functions and changes in function arguments
+*** New function ~org-get-title-from-buffer~ to get ~#+TITLE:~ property
+
+A function to collect the document title from the org-mode buffer.
+
 *** ~org-fold-show-entry~ does not fold drawers by default anymore
 
 ~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index b98041ea8..f308f8f76 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1058,9 +1058,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."
@@ -9424,7 +9429,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 858123e67..fd76af48a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7396,10 +7396,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-buffer (&optional buffer)
+  "Collect title from the provided `org-mode' BUFFER."
+  (let* ((buffer (or buffer (current-buffer)))
+         (buffer (or (buffer-base-buffer buffer)
+                     buffer))
+         title)
+    (with-current-buffer buffer
+      (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 \"/\".
@@ -7407,6 +7421,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-buffer)))
 	 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
 	 res)
     (when current (setq path (append path
@@ -7418,7 +7434,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.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-30 13:50           ` Mikhail Skorzhisnkii
@ 2022-08-31 12:09             ` Ihor Radchenko
  2022-09-05 18:50               ` Mikhail Skorzhisnkii
  2022-08-31 12:11             ` Ihor Radchenko
                               ` (2 subsequent siblings)
  3 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-08-31 12:09 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> I have signed FSF papers. Attaching a rebased patch with additional changes to
> ORG-NEWS

Thanks!

> Subject: [PATCH 1/2] 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)

Please follow the commit message conventions as described in
https://orgmode.org/worg/org-contribute.html#commit-messages In
particular, start sentences from capital letters, end them with ".",
separate sentences with double space, and quote lisp symbols as
`symbol'.

> * lisp/org.el (org-get-title-from-buffer): a function to collect the
                                             New
> document title from the org-mode buffer
                                         .


> * 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

This is not what the patch does.  From this message, it looks like
`org-agenda-show-outline-path' is affecting the output of
`org-display-outline-path', which is not true.

>  (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."

This is not very clear. I'd rather put more detailed explanation as in
the defcustom :type spec below.

>    :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)))
> -(defun org-display-outline-path (&optional file current separator just-return-string)
> +(defun org-get-title-from-buffer (&optional buffer)
> +  "Collect title from the provided `org-mode' BUFFER."
> +  (let* ((buffer (or buffer (current-buffer)))
> +         (buffer (or (buffer-base-buffer buffer)
> +                     buffer))

Why not just

(or (buffer-base-buffer buffer)
    buffer
    (current-buffer))

> +         title)
> +    (with-current-buffer buffer
> +      (pcase (org-collect-keywords '("TITLE"))
> +        (`(("TITLE" . ,val))
> +         (setq title (car val)))))
> +    title))

Extra `title' variable is unnecessary here. You can simply do 

    (with-current-buffer buffer
      (pcase (org-collect-keywords '("TITLE"))
        (`(("TITLE" ,val . _))
         val)))

Also, what will happen in a file like

#+TITLE: Begin title
#+TITLE: .. end 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 \"/\".
> @@ -7407,6 +7421,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))

can be simply (eq file-or-title 'title)

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-30 13:50           ` Mikhail Skorzhisnkii
  2022-08-31 12:09             ` Ihor Radchenko
@ 2022-08-31 12:11             ` Ihor Radchenko
  2022-09-01  7:29               ` Bastien
  2022-08-31 12:13             ` Ihor Radchenko
  2022-09-05 19:28             ` Mikhail Skorzhisnkii
  3 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-08-31 12:11 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii, Bastien; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> I have signed FSF papers. Attaching a rebased patch with additional changes to
> ORG-NEWS

Bastien, could you kindly check the FSF records?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-30 13:50           ` Mikhail Skorzhisnkii
  2022-08-31 12:09             ` Ihor Radchenko
  2022-08-31 12:11             ` Ihor Radchenko
@ 2022-08-31 12:13             ` Ihor Radchenko
  2022-09-05 18:59               ` Mikhail Skorzhisnkii
  2022-09-05 19:28             ` Mikhail Skorzhisnkii
  3 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-08-31 12:13 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> Subject: [PATCH 1/2] org-agenda.el: customize outline path in echo area

I do not see the second patch. Did you forget to attach it?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-31 12:11             ` Ihor Radchenko
@ 2022-09-01  7:29               ` Bastien
  0 siblings, 0 replies; 20+ messages in thread
From: Bastien @ 2022-09-01  7:29 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Mikhail Skorzhisnkii, Org Mode

Hi Ihor,

Ihor Radchenko <yantar92@gmail.com> writes:

> Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:
>
>> I have signed FSF papers. Attaching a rebased patch with additional changes to
>> ORG-NEWS
>
> Bastien, could you kindly check the FSF records?

Yes, I confirm Mikhail is on the FSF records.  Mikhail, thanks for
contributing!

-- 
 Bastien


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-31 12:09             ` Ihor Radchenko
@ 2022-09-05 18:50               ` Mikhail Skorzhisnkii
  2022-09-08  5:40                 ` Ihor Radchenko
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-09-05 18:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

Thanks for your comment, Ihor. I have addressed your comments, see some comments inline. Attaching new version of the patch.

Ihor Radchenko <yantar92@gmail.com> writes:

> Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:
>
>> I have signed FSF papers. Attaching a rebased patch with additional changes to
>> ORG-NEWS
>
> Thanks!
>
>> Subject: [PATCH 1/2] 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)
>
> Please follow the commit message conventions as described in
> <https://orgmode.org/worg/org-contribute.html#commit-messages> In
> particular, start sentences from capital letters, end them with “.”,
> separate sentences with double space, and quote lisp symbols as
> `symbol’.
>
>> * lisp/org.el (org-get-title-from-buffer): a function to collect the
>                                              New
>> document title from the org-mode buffer
>                                          .

Sorry — missed these rules. Fixed now.

>> * 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
>
> This is not what the patch does.  From this message, it looks like
> `org-agenda-show-outline-path’ is affecting the output of
> `org-display-outline-path’, which is not true.

Hm, for me it doesn’t look like it from my perspectrive, but my command of the
English is not that good. I have reworded it. Is it better now?

Feel free to reword it on final apply or let me know if you would like to
improve — I will someone to proofread it.

>>  (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.”
>
> This is not very clear. I’d rather put more detailed explanation as in
> the defcustom :type spec below.

Fixed.

>>    :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)))
>> -(defun org-display-outline-path (&optional file current separator just-return-string)
>> +(defun org-get-title-from-buffer (&optional buffer)
>> +  “Collect title from the provided `org-mode’ BUFFER.”
>> +  (let* ((buffer (or buffer (current-buffer)))
>> +         (buffer (or (buffer-base-buffer buffer)
>> +                     buffer))
>
> Why not just
>
> (or (buffer-base-buffer buffer)
>     buffer
>     (current-buffer))

Applied your suggestion.

>> +         title)
>> +    (with-current-buffer buffer
>> +      (pcase (org-collect-keywords ’(“TITLE”))
>> +        (`((“TITLE” . ,val))
>> +         (setq title (car val)))))
>> +    title))
>
> Extra `title’ variable is unnecessary here. You can simply do
>
>     (with-current-buffer buffer
>       (pcase (org-collect-keywords ’(“TITLE”))
>         (`((“TITLE” ,val . _))
>          val)))

Indeed — remnant of previous implementation iteration. Applied your suggestion.

> Also, what will happen in a file like
>
> #+TITLE: Begin title
> #+TITLE: .. end title
>
> ?

Hm, never did this myself. Now concatenate the list of property values. I have
tested it and space as a separator looks good, if the intention of several
titles is to have one big title.

But what if several titles are title and subtitles? We can provide a way control
that behaviour, but my gut feeling that it would be a rather confusing.

>> +(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 \”/\“.
>> @@ -7407,6 +7421,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))
>
> can be simply (eq file-or-title ’title)

Indeed. Fixed.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda.el-customize-outline-path-in-echo-area.patch --]
[-- Type: text/x-diff, Size: 5685 bytes --]

From ebad0bb39221217233283905f39b99644b07f36b Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Sat, 12 Sep 2020 18:10:05 +0200
Subject: [PATCH 1/2] 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-buffer): A new function to collect the
document title from the org-mode buffer.
* lisp/org.el (org-display-outline-path): Show document title (#+TITLE
value) and outline path in echo area if customisation option is set to
'title. Fallback to file name if there is document title is absent.
---
 etc/ORG-NEWS       | 10 ++++++++++
 lisp/org-agenda.el | 12 +++++++++---
 lisp/org.el        | 25 ++++++++++++++++++++++---
 3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7dae03dc6..529fea41a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -290,6 +290,12 @@ level used for top level headings, much like how
 headings in HTML export.
 
 ** New options
+*** A new option for custom setting =org-agenda-show-outline-path= to show document title
+
+Setting =org-agenda-show-outline-path= to ='title= will show title
+instead of the file name at the beginning of the outline. The title of
+the document can be set by special keyword =#+title:=.
+
 *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers
 
 Previously, all the drawers were always folded when opening an Org
@@ -320,6 +326,10 @@ event time when the alarm time is set to 0.  The default value is
 nil -- do not create alarms at the event time.
 
 ** New functions and changes in function arguments
+*** New function ~org-get-title-from-buffer~ to get ~#+TITLE:~ property
+
+A function to collect the document title from the org-mode buffer.
+
 *** ~org-fold-show-entry~ does not fold drawers by default anymore
 
 ~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS.
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index b98041ea8..aad7f279e 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1058,9 +1058,15 @@ 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 outline path with prepended document
+title.  Fallback to file name is no title is present."
   :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."
@@ -9424,7 +9430,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 858123e67..1babd5d8d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7396,10 +7396,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-buffer (&optional buffer)
+  "Collect title from the provided `org-mode' BUFFER.
+
+Returns nil if there are no #+TITLE property."
+  (let ((buffer (or (buffer-base-buffer)
+                    buffer
+                    (current-buffer))))
+    (with-current-buffer buffer
+      (pcase (org-collect-keywords '("TITLE"))
+        (`(("TITLE" . ,val))
+         (mapconcat 'identity val " "))))))
+
+(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 \"/\".
@@ -7407,6 +7421,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 (eq file-or-title 'title)
+                       (org-get-title-from-buffer)))
 	 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
 	 res)
     (when current (setq path (append path
@@ -7418,7 +7434,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.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-31 12:13             ` Ihor Radchenko
@ 2022-09-05 18:59               ` Mikhail Skorzhisnkii
  0 siblings, 0 replies; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-09-05 18:59 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

Ah, sorry — probably forgot to attach it, yes. See the second patch here in the attachment.

Ihor Radchenko <yantar92@gmail.com> writes:

> Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:
>
>> Subject: [PATCH 1/2] org-agenda.el: customize outline path in echo area
>
> I do not see the second patch. Did you forget to attach it?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-refile.el-show-refile-targets-with-doc.-title.patch --]
[-- Type: text/x-diff, Size: 6012 bytes --]

From 686a1d813ec8962bff993add1305015eb2788213 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Mon, 21 Sep 2020 14:53:13 +0200
Subject: [PATCH 2/2] org-refile.el: show refile targets with doc. title

* lisp/org-refile.el (org-refile-use-outline-path): Add new option
'title
* lisp/org-refile.el (org-refile-get-targets): Start refile target
outline with document title (#+TITLE) instead of file name if
corresponding customization is set to 'title. Fallback to filename if
title is absent.
---
 etc/ORG-NEWS             |  6 ++++++
 lisp/org-refile.el       | 15 ++++++++++++---
 testing/lisp/test-org.el | 37 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 529fea41a..51471428c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -290,6 +290,12 @@ level used for top level headings, much like how
 headings in HTML export.
 
 ** New options
+*** A new option for custom setting =org-refile-use-outline-path= to show document title in refile targets
+
+Setting =org-refile-use-outline-path= to ='title= will show title
+instead of the file name in refile targets. If the documen do not have
+a title, the filename will be used, similar to ='file= option.
+
 *** A new option for custom setting =org-agenda-show-outline-path= to show document title
 
 Setting =org-agenda-show-outline-path= to ='title= will show title
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 01f0dfa46..88fe13f23 100644
--- a/lisp/org-refile.el
+++ b/lisp/org-refile.el
@@ -158,7 +158,8 @@ When `buffer-name', use the buffer name."
 	  (const :tag "Yes" t)
 	  (const :tag "Start with file name" file)
 	  (const :tag "Start with full file path" full-file-path)
-	  (const :tag "Start with buffer name" buffer-name)))
+	  (const :tag "Start with buffer name" buffer-name)
+	  (const :tag "Start with document title" title)))
 
 (defcustom org-outline-path-complete-in-steps t
   "Non-nil means complete the outline path in hierarchical steps.
@@ -317,6 +318,9 @@ converted to a headline before refiling."
 		 (push (list (and (buffer-file-name (buffer-base-buffer))
                                   (file-truename (buffer-file-name (buffer-base-buffer))))
                              f nil nil) tgs))
+	       (when (eq org-refile-use-outline-path 'title)
+		 (push (list (or (org-get-title-from-buffer)
+                                 (and f (file-name-nondirectory f))) f nil nil) tgs))
 	       (org-with-wide-buffer
 		(goto-char (point-min))
 		(setq org-outline-path-cache nil)
@@ -343,7 +347,12 @@ converted to a headline before refiling."
                                            (and (buffer-file-name (buffer-base-buffer))
                                                 (file-name-nondirectory
                                                  (buffer-file-name (buffer-base-buffer))))))
-				   (`full-file-path
+                                   (`title (list
+                                            (or (org-get-title-from-buffer)
+                                                (and (buffer-file-name (buffer-base-buffer))
+                                                     (file-name-nondirectory
+                                                      (buffer-file-name (buffer-base-buffer)))))))
+                                   (`full-file-path
 				    (list (buffer-file-name
 					   (buffer-base-buffer))))
 				   (`buffer-name
@@ -631,7 +640,7 @@ this function appends the default value from
 	 (tbl (mapcar
 	       (lambda (x)
 		 (if (and (not (member org-refile-use-outline-path
-				       '(file full-file-path)))
+				       '(file full-file-path title)))
 			  (not (equal filename (nth 1 x))))
 		     (cons (concat (car x) extra " ("
 				   (file-name-nondirectory (nth 1 x)) ")")
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index b14cbeb26..b85dd7dea 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6728,7 +6728,42 @@ Paragraph<point>"
    (org-test-with-temp-text "* H1"
      (let* ((org-refile-use-outline-path 'buffer-name)
 	    (org-refile-targets `((nil :level . 1))))
-       (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
+       (member (buffer-name) (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title', return extracted
+  ;; document title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+        (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' validate that
+  ;; deeper levels are correctly reported too (the same behaviour as
+  ;; 'file)
+  (should
+   (equal '("T" "T/H1" "T/H1/H2" "T/H1/H2/H3" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1\n** H2\n*** H3\n* H1"
+       (let ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :maxlevel . 3))))
+         (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document do not
+  ;; have an extracted document title, return just the file name
+  (should
+   (org-test-with-temp-text-in-file "* H1"
+     (let* ((filename (buffer-file-name))
+            (org-refile-use-outline-path 'title)
+            (org-refile-targets `((nil :level . 1))))
+       (member (file-name-nondirectory filename)
+               (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document is a
+  ;; temporary buffer without a file, it is still possible to extract
+  ;; a title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text "#+title: T\n* H1\n** H2"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+      (mapcar #'car (org-refile-get-targets)))))))
 
 
 \f
-- 
2.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-08-30 13:50           ` Mikhail Skorzhisnkii
                               ` (2 preceding siblings ...)
  2022-08-31 12:13             ` Ihor Radchenko
@ 2022-09-05 19:28             ` Mikhail Skorzhisnkii
  2022-09-08  5:33               ` Ihor Radchenko
  3 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-09-05 19:28 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

Resubmitting this patch with better commit message.

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> I have signed FSF papers. Attaching a rebased patch with additional changes to
> ORG-NEWS
>
> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> “Mikhail Skorzhinskiy” <mskorzhinskii@eml.cc> writes:
>>
>>> Thanks for review, Ihor. I have sent a copyright assignment request. Will
>>> resubmit the patches as soon as I complete the process.
>>
>> Thanks! Note that FSF clerk should reply within 5 working days. If not,
>> please let us know.
>>
>> Best,
>> Ihor
>
> [2. text/x-diff; 0001-org-agenda.el-customize-outline-path-in-echo-area.patch]…

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-icalendar.el-customize-vevent-summary-prefix.patch --]
[-- Type: text/x-diff, Size: 3320 bytes --]

From 38c940230e84af34f023a17033fbbe0723e25b0d Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskiy@eml.cc>
Date: Sat, 12 Sep 2020 18:27:23 +0200
Subject: [PATCH] ox-icalendar.el: customize vevent summary prefix

* lisp/ox-icalendar.el (org-icalendar-scheduled-summary-prepend): A new
customization option to control summary prefix in exported scheduled
events.
* lisp/ox-icalendar.el (org-icalendar-deadline-summary-prepend): A new
customization option to control summary prefix in exported deadline
events.
* lisp/ox-icalendar.el (org-icalendar-entry): Use configurable summary
prefixes for scheduled and deadline events, instead of hardcoded ones.
---
 etc/ORG-NEWS         |  7 +++++++
 lisp/ox-icalendar.el | 19 +++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7dae03dc6..b40820c4a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -290,6 +290,13 @@ level used for top level headings, much like how
 headings in HTML export.
 
 ** New options
+*** A new custom settings =org-icalendar-scheduled-summary-prepend= and =org-icalendar-deadline-summary-prepend=
+
+These setting allow users to define prefixes for exported summary
+lines in ICS exports. Potential use would be to disable prefixes all
+together or be a little bit mode verbose (e.g. "Deadline: " instead of
+"DL: ").
+
 *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers
 
 Previously, all the drawers were always folded when opening an Org
diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 352d16335..912e19e6c 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -98,6 +98,21 @@ keyword."
   :group 'org-export-icalendar
   :type '(repeat (string :tag "Tag")))
 
+(defcustom org-icalendar-scheduled-summary-prepend "S: "
+  "String used for prepending summary in exported scheduled headlines."
+  :group 'org-export-icalendar
+  :type 'string
+  :package-version '(Org . "9.6")
+  :safe #'stringp)
+
+
+(defcustom org-icalendar-deadline-summary-prepend "DL: "
+  "String used for prepending summary in exported deadlines."
+  :group 'org-export-icalendar
+  :type 'string
+  :package-version '(Org . "9.6")
+  :safe #'stringp)
+
 (defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
   "Contexts where iCalendar export should use a deadline time stamp.
 
@@ -621,7 +636,7 @@ inlinetask within the section."
 		   (_ (memq 'event-if-not-todo use-deadline)))
 		 (org-icalendar--vevent
 		  entry deadline (concat "DL-" uid)
-		  (concat "DL: " summary) loc desc cat tz class)))
+		  (concat org-icalendar-deadline-summary-prepend summary) loc desc cat tz class)))
 	  (let ((scheduled (org-element-property :scheduled entry))
 		(use-scheduled (plist-get info :icalendar-use-scheduled)))
 	    (and scheduled
@@ -632,7 +647,7 @@ inlinetask within the section."
 		   (_ (memq 'event-if-not-todo use-scheduled)))
 		 (org-icalendar--vevent
 		  entry scheduled (concat "SC-" uid)
-		  (concat "S: " summary) loc desc cat tz class)))
+		  (concat org-icalendar-scheduled-summary-prepend summary) loc desc cat tz class)))
 	  ;; When collecting plain timestamps from a headline and its
 	  ;; title, skip inlinetasks since collection will happen once
 	  ;; ENTRY is one of them.
-- 
2.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-09-05 19:28             ` Mikhail Skorzhisnkii
@ 2022-09-08  5:33               ` Ihor Radchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Ihor Radchenko @ 2022-09-08  5:33 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> Resubmitting this patch with better commit message.

Thanks!
Applied onto main with amendments.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=eb5ef0ae1424a725f933ef3929e5396a2ab727ab

I have changed the variable names to end with more conventional
"-prefix". Also, I fixed some grammar issues and reworded the
docstrings a bit.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-09-05 18:50               ` Mikhail Skorzhisnkii
@ 2022-09-08  5:40                 ` Ihor Radchenko
  2022-09-08 20:10                   ` Mikhail Skorzhisnkii
  0 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-09-08  5:40 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

>> Also, what will happen in a file like
>>
>> #+TITLE: Begin title
>> #+TITLE: .. end title
>>
>> ?
>
> Hm, never did this myself. Now concatenate the list of property values. I have
> tested it and space as a separator looks good, if the intention of several
> titles is to have one big title.
>
> But what if several titles are title and subtitles? We can provide a way control
> that behaviour, but my gut feeling that it would be a rather confusing.

See org-clock-get-file-title. You can move that function into org.el and
rename to org-get-file-title.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-09-08  5:40                 ` Ihor Radchenko
@ 2022-09-08 20:10                   ` Mikhail Skorzhisnkii
  2022-09-09 10:13                     ` Ihor Radchenko
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-09-08 20:10 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

Thank you for suggestion, I seen an announcement about this function, but somehow forgot about it.

Sending next version of these patches. Changes from the next version:

• Removed my version of title gathering into one existing in org-clock.el
• Split org-clock-get-file-title renaming into separate commit
• More grammar and wording fixes in changelogs

      Thanks,
      Mikhail

Ihor Radchenko <yantar92@gmail.com> writes:

> Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:
>
>>> Also, what will happen in a file like
>>>
>>> #+TITLE: Begin title
>>> #+TITLE: .. end title
>>>
>>> ?
>>
>> Hm, never did this myself. Now concatenate the list of property values. I have
>> tested it and space as a separator looks good, if the intention of several
>> titles is to have one big title.
>>
>> But what if several titles are title and subtitles? We can provide a way control
>> that behaviour, but my gut feeling that it would be a rather confusing.
>
> See org-clock-get-file-title. You can move that function into org.el and
> rename to org-get-file-title.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-org-refile.el-show-refile-targets-with-a-title.patch --]
[-- Type: text/x-diff, Size: 6145 bytes --]

From 47c61b597a3064755964d763621616d184c351ad Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Mon, 21 Sep 2020 14:53:13 +0200
Subject: [PATCH 3/3] org-refile.el: show refile targets with a title

* lisp/org-refile.el (org-refile-get-targets): Use a document
title (#+TITLE) instead of file or buffer name in outline path, if
a corresponding customisation option is set to 'title. Fallback to a
filename if there is no title in the document.
* lisp/org-refile.el (org-refile-use-outline-path): Add a new option
'title, see above
---
 etc/ORG-NEWS             |  6 ++++++
 lisp/org-refile.el       | 17 ++++++++++++++---
 testing/lisp/test-org.el | 37 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 8f57d252f..cc63b679d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -295,6 +295,12 @@ Use the header argument =:var x=code-block[]= or
 to pass the contents of a named code block as a string argument.
 
 ** New options
+*** A new option for custom setting =org-refile-use-outline-path= to show document title in refile targets
+
+Setting =org-refile-use-outline-path= to ='title= will show title
+instead of the file name in refile targets. If the documen do not have
+a title, the filename will be used, similar to ='file= option.
+
 *** A new option for custom setting =org-agenda-show-outline-path= to show document title
 
 Setting =org-agenda-show-outline-path= to ='title= will show title
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 16cff25bd..64f4ef7da 100644
--- a/lisp/org-refile.el
+++ b/lisp/org-refile.el
@@ -160,7 +160,8 @@ When `buffer-name', use the buffer name."
 	  (const :tag "Yes" t)
 	  (const :tag "Start with file name" file)
 	  (const :tag "Start with full file path" full-file-path)
-	  (const :tag "Start with buffer name" buffer-name)))
+	  (const :tag "Start with buffer name" buffer-name)
+	  (const :tag "Start with document title" title)))
 
 (defcustom org-outline-path-complete-in-steps t
   "Non-nil means complete the outline path in hierarchical steps.
@@ -319,6 +320,11 @@ converted to a headline before refiling."
 		 (push (list (and (buffer-file-name (buffer-base-buffer))
                                   (file-truename (buffer-file-name (buffer-base-buffer))))
                              f nil nil) tgs))
+               (when (eq org-refile-use-outline-path 'title)
+                 (push (list (or (org-get-title)
+                                 (and f (file-name-nondirectory f)))
+                             f nil nil)
+                       tgs))
 	       (org-with-wide-buffer
 		(goto-char (point-min))
 		(setq org-outline-path-cache nil)
@@ -345,7 +351,12 @@ converted to a headline before refiling."
                                            (and (buffer-file-name (buffer-base-buffer))
                                                 (file-name-nondirectory
                                                  (buffer-file-name (buffer-base-buffer))))))
-				   (`full-file-path
+                                   (`title (list
+                                            (or (org-get-title)
+                                                (and (buffer-file-name (buffer-base-buffer))
+                                                     (file-name-nondirectory
+                                                      (buffer-file-name (buffer-base-buffer)))))))
+                                   (`full-file-path
 				    (list (buffer-file-name
 					   (buffer-base-buffer))))
 				   (`buffer-name
@@ -633,7 +644,7 @@ this function appends the default value from
 	 (tbl (mapcar
 	       (lambda (x)
 		 (if (and (not (member org-refile-use-outline-path
-				       '(file full-file-path)))
+				       '(file full-file-path title)))
 			  (not (equal filename (nth 1 x))))
 		     (cons (concat (car x) extra " ("
 				   (file-name-nondirectory (nth 1 x)) ")")
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 004e89732..d7412f080 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6728,7 +6728,42 @@ Paragraph<point>"
    (org-test-with-temp-text "* H1"
      (let* ((org-refile-use-outline-path 'buffer-name)
 	    (org-refile-targets `((nil :level . 1))))
-       (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
+       (member (buffer-name) (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title', return extracted
+  ;; document title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+        (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' validate that
+  ;; deeper levels are correctly reported too (the same behaviour as
+  ;; 'file)
+  (should
+   (equal '("T" "T/H1" "T/H1/H2" "T/H1/H2/H3" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1\n** H2\n*** H3\n* H1"
+       (let ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :maxlevel . 3))))
+         (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document do not
+  ;; have an extracted document title, return just the file name
+  (should
+   (org-test-with-temp-text-in-file "* H1"
+     (let* ((filename (buffer-file-name))
+            (org-refile-use-outline-path 'title)
+            (org-refile-targets `((nil :level . 1))))
+       (member (file-name-nondirectory filename)
+               (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document is a
+  ;; temporary buffer without a file, it is still possible to extract
+  ;; a title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text "#+title: T\n* H1\n** H2"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+      (mapcar #'car (org-refile-get-targets)))))))
 
 
 \f
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-agenda.el-show-document-title-in-outline-path.patch --]
[-- Type: text/x-diff, Size: 5024 bytes --]

From 62684b478ae5ceb03f66967fbebcc4d6163c826c Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Sat, 12 Sep 2020 18:10:05 +0200
Subject: [PATCH 2/3] org-agenda.el: show document title in outline path

* lisp/org-agenda.el (org-agenda-show-outline-path): Add an option to
show a document title at start of an outline path, instead of a file or
a buffer name.
* lisp/org.el (org-display-outline-path): Show a document title (#+TITLE
value) and an outline path in an echo area if the customisation option
is set to 'title. Fallback to a file or a buffer name if the document
title is absent.
---
 etc/ORG-NEWS       |  9 ++++-----
 lisp/org-agenda.el | 12 +++++++++---
 lisp/org.el        | 12 +++++++++---
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 44f0024fb..8f57d252f 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -295,12 +295,11 @@ Use the header argument =:var x=code-block[]= or
 to pass the contents of a named code block as a string argument.
 
 ** New options
-*** New custom settings =org-icalendar-scheduled-summary-prefix= and =org-icalendar-deadline-summary-prefix=
+*** A new option for custom setting =org-agenda-show-outline-path= to show document title
 
-These settings allow users to define prefixes for exported summary
-lines in ICS exports.  The customization can be used to disable
-the prefixes completely or make them a little bit more verbose
-(e.g. "Deadline: " instead of the default "DL: ").
+Setting =org-agenda-show-outline-path= to ='title= will show title
+instead of the file name at the beginning of the outline. The title of
+the document can be set by special keyword =#+title:=.
 
 *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers
 
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 053232078..c817aefd0 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1061,9 +1061,15 @@ 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 outline path with prepended document
+title.  Fallback to file name is no title is present."
   :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."
@@ -9427,7 +9433,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 f3f9c4096..c2b8a2a40 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7429,10 +7429,12 @@ Returns nil if there are no #+TITLE property."
         (unless (string= "" title)
           title)))))
 
-(defun org-display-outline-path (&optional file current separator just-return-string)
+(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 \"/\".
@@ -7440,6 +7442,7 @@ 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 (eq file-or-title 'title) (org-get-title)))
 	 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
 	 res)
     (when current (setq path (append path
@@ -7451,7 +7454,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.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-org-clock.el-rename-org-clock-get-file-title.patch --]
[-- Type: text/x-diff, Size: 4026 bytes --]

From 5b15f886b22dc542220b48ae9659c4c2d56dea78 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Thu, 8 Sep 2022 21:29:23 +0200
Subject: [PATCH 1/3] org-clock.el: rename org-clock-get-file-title

* lisp/org.el (org-get-title): A new function to collect a document
title from an org-mode buffer, based on a org-clock-get-file-title
implementation.
* lisp/org.el (org-get-file-title): Moved from the org-clock.el to the
org.el and renamed, preserving the same behaviour and function
signature.
* lisp/org-clock.el (org-clock-get-file-title): Moved and renamed, see
above.
---
 etc/ORG-NEWS      |  8 ++++++++
 lisp/org-clock.el | 12 +-----------
 lisp/org.el       | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3c98e8ba0..44f0024fb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -332,6 +332,10 @@ event time when the alarm time is set to 0.  The default value is
 nil -- do not create alarms at the event time.
 
 ** New functions and changes in function arguments
+*** New function ~org-get-title~ to get ~#+TITLE:~ property from buffers
+
+A function to collect the document title from the org-mode buffer.
+
 *** ~org-fold-show-entry~ does not fold drawers by default anymore
 
 ~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS.
@@ -399,6 +403,10 @@ Previously, executing PlantUML src blocks always exported to a file.  Now, if
 exported and an ASCII graph will be inserted below the src block.
 
 ** Removed or renamed functions and variables
+*** Rename ~org-clock-get-file-title~ to ~org-get-file-title~
+
+This function is now part of the =org.el= file.
+
 *** =org-plantump-executable-args= is renamed and applies to jar as well
 
 The new variable name is =org-plantuml-args=.  It now applies to both
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index b432c7df7..ef0ef2021 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2473,16 +2473,6 @@ the currently selected interval size."
 	  (org-update-dblock)
 	  t)))))
 
-(defun org-clock-get-file-title (file-name)
-  "Get the file title from FILE-NAME as a string.
-Return short FILE-NAME if #+title keyword is not found."
-  (with-current-buffer (find-file-noselect file-name)
-    (org-macro-initialize-templates)
-    (let ((title (assoc-default "title" org-macro-templates)))
-      (if (null title)
-          (file-name-nondirectory file-name)
-        title))))
-
 ;;;###autoload
 (defun org-dblock-write:clocktable (params)
   "Write the standard clocktable."
@@ -2739,7 +2729,7 @@ from the dynamic block definition."
 			     "\n")
 
                      (if filetitle
-                         (org-clock-get-file-title file-name)
+                         (org-get-file-title file-name)
                        (file-name-nondirectory file-name))
 		     (if level?    "| " "") ;level column, maybe
 		     (if timestamp "| " "") ;timestamp column, maybe
diff --git a/lisp/org.el b/lisp/org.el
index 34560c83f..f3f9c4096 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7409,6 +7409,26 @@ the default is \"/\"."
 	(setf (substring fpath (- width 2)) "..")))
     fpath))
 
+(defun org-get-file-title (file-name)
+  "Collect title from `org-mode' FILE-NAME.
+
+Return file name if title does not exist."
+  (or (org-get-title (find-file-noselect file-name))
+      (file-name-nondirectory file-name)))
+
+(defun org-get-title (&optional buffer)
+  "Collect title from the provided `org-mode' BUFFER.
+
+Returns nil if there are no #+TITLE property."
+  (let ((buffer (or (buffer-base-buffer)
+                    buffer
+                    (current-buffer))))
+    (with-current-buffer buffer
+      (org-macro-initialize-templates)
+      (let ((title (assoc-default "title" org-macro-templates)))
+        (unless (string= "" title)
+          title)))))
+
 (defun org-display-outline-path (&optional file current separator just-return-string)
   "Display the current outline path in the echo area.
 
-- 
2.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-09-08 20:10                   ` Mikhail Skorzhisnkii
@ 2022-09-09 10:13                     ` Ihor Radchenko
  2022-10-23 19:15                       ` Mikhail Skorzhisnkii
  0 siblings, 1 reply; 20+ messages in thread
From: Ihor Radchenko @ 2022-09-09 10:13 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> Thank you for suggestion, I seen an announcement about this function, but somehow forgot about it.
>
> Sending next version of these patches. Changes from the next version:

Thanks!

> Subject: [PATCH 3/3] org-refile.el: show refile targets with a title
>
> * lisp/org-refile.el (org-refile-get-targets): Use a document
> title (#+TITLE) instead of file or buffer name in outline path, if
> a corresponding customisation option is set to 'title. Fallback to a
> filename if there is no title in the document.

Please use 2 spaces between sentences in docstrings, comments, and
commit messages. Also, end sentences with ".". See
https://orgmode.org/worg/org-contribute.html#commit-messages and
https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html

>  (defcustom org-outline-path-complete-in-steps t
>    "Non-nil means complete the outline path in hierarchical steps.
> @@ -319,6 +320,11 @@ converted to a headline before refiling."
>  		 (push (list (and (buffer-file-name (buffer-base-buffer))
>                                    (file-truename (buffer-file-name (buffer-base-buffer))))
>                               f nil nil) tgs))
> +               (when (eq org-refile-use-outline-path 'title)
> +                 (push (list (or (org-get-title)
> +                                 (and f (file-name-nondirectory f)))
> +                             f nil nil)
> +                       tgs))

We have very too many whens in this function. It will be more succinct
to use a single (pcase org-refile-use-outline-path ...) instead.

> +  ;; When `org-refile-use-outline-path' is `title', return extracted
> +  ;; document title
> +  (should
> +   (equal '("T" "T/H1")
> +     (org-test-with-temp-text-in-file "#+title: T\n* H1"

You may as well add a test when multiple #+title lines are present.

> From 62684b478ae5ceb03f66967fbebcc4d6163c826c Mon Sep 17 00:00:00 2001
> From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
> Date: Sat, 12 Sep 2020 18:10:05 +0200
> Subject: [PATCH 2/3] org-agenda.el: show document title in outline path
                                     ^Show
> * lisp/org.el (org-display-outline-path): Show a document title (#+TITLE
> value) and an outline path in an echo area if the customisation option
> is set to 'title. Fallback to a file or a buffer name if the document
                  ^  Fallback ;; (double space between sentences)
> title is absent.

>  ** New options
> -*** New custom settings =org-icalendar-scheduled-summary-prefix= and =org-icalendar-deadline-summary-prefix=

This is removing an existing NEWS entry. I guess it is not intentional.

> +*** A new option for custom setting =org-agenda-show-outline-path= to show document title
>  
>  (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 outline path with prepended document
> +title.  Fallback to file name is no title is present."
>    :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)))

I think you can leave
(const :tag "Show outline path with prepended document title." title)

This text will be displayed in drop menu in cutomize interface alongside
with the full docstring. Mentioning the fallback in the docstring should
be good enough.

> From 5b15f886b22dc542220b48ae9659c4c2d56dea78 Mon Sep 17 00:00:00 2001
> From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
> Date: Thu, 8 Sep 2022 21:29:23 +0200
> Subject: [PATCH 1/3] org-clock.el: rename org-clock-get-file-title
                                    ^Rename

> * lisp/org.el (org-get-title): A new function to collect a document
> title from an org-mode buffer, based on a org-clock-get-file-title
> implementation.

`org-clock-get-file-title'. Elisp symbols should be quoted.

>  ** New functions and changes in function arguments
> +*** New function ~org-get-title~ to get ~#+TITLE:~ property from buffers

We generally use ~code~ for Elisp symbols and =#+TITLE:= for verbatim
non-code text. (This has not been consistently followed in etc/NEWS, but
at least please change ~#+TITLE~ to =#+TITLE=). See
doc/Documentation_Standards.org

>  ** Removed or renamed functions and variables
> +*** Rename ~org-clock-get-file-title~ to ~org-get-file-title~
> +
> +This function is now part of the =org.el= file.

You do not need to mention this. org-clock-get-file-title was
introduced in recent commits on main. Main is development branch, and we
do not need to document changes on the changes made after the last
release.

>  ;;;###autoload
>  (defun org-dblock-write:clocktable (params)
>    "Write the standard clocktable."
> @@ -2739,7 +2729,7 @@ from the dynamic block definition."
>  			     "\n")
>  
>                       (if filetitle
> -                         (org-clock-get-file-title file-name)
> +                         (org-get-file-title file-name)
>                         (file-name-nondirectory file-name))
>  		     (if level?    "| " "") ;level column, maybe
>  		     (if timestamp "| " "") ;timestamp column, maybe

This may introduce a compiler warning. I suggest running make after
applying your patch and fix possible compiler warnings. (I suspect that
you may need to add declare-function on top of org-clock.el)

> +(defun org-get-file-title (file-name)
> +  "Collect title from `org-mode' FILE-NAME.
> +
> +Return file name if title does not exist."
> +  (or (org-get-title (find-file-noselect file-name))
> +      (file-name-nondirectory file-name)))
> +
> +(defun org-get-title (&optional buffer)
> +  "Collect title from the provided `org-mode' BUFFER.
> +
> +Returns nil if there are no #+TITLE property."
> +  (let ((buffer (or (buffer-base-buffer)
> +                    buffer
> +                    (current-buffer))))
> +    (with-current-buffer buffer
> +      (org-macro-initialize-templates)
> +      (let ((title (assoc-default "title" org-macro-templates)))
> +        (unless (string= "" title)
> +          title)))))

These two functions can be merged into a single `org-get-title' that
accepts buffer or file-name as an optional argument.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-09-09 10:13                     ` Ihor Radchenko
@ 2022-10-23 19:15                       ` Mikhail Skorzhisnkii
  2022-10-25  6:59                         ` Ihor Radchenko
  0 siblings, 1 reply; 20+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-10-23 19:15 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode

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

Hi, Ihor,

Sorry for the delay with fixes, took some time before I got time to finish this. Thanks for your review and looking forward for the next iteration. See new version in the attachment. Comments are inline.

Ihor Radchenko <yantar92@gmail.com> writes:

> Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:
>
>> Thank you for suggestion, I seen an announcement about this function, but somehow forgot about it.
>>
>> Sending next version of these patches. Changes from the next version:
>
> Thanks!
>
>> Subject: [PATCH 3/3] org-refile.el: show refile targets with a title
>>
>> * lisp/org-refile.el (org-refile-get-targets): Use a document
>> title (#+TITLE) instead of file or buffer name in outline path, if
>> a corresponding customisation option is set to ’title. Fallback to a
>> filename if there is no title in the document.
>
> Please use 2 spaces between sentences in docstrings, comments, and
> commit messages. Also, end sentences with “.”. See
> <https://orgmode.org/worg/org-contribute.html#commit-messages> and
> <https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html>
>

Fixed.

>>  (defcustom org-outline-path-complete-in-steps t
>>    “Non-nil means complete the outline path in hierarchical steps.
>> @@ -319,6 +320,11 @@ converted to a headline before refiling.”
>>  		 (push (list (and (buffer-file-name (buffer-base-buffer))
>>                                    (file-truename (buffer-file-name (buffer-base-buffer))))
>>                               f nil nil) tgs))
>> +               (when (eq org-refile-use-outline-path ’title)
>> +                 (push (list (or (org-get-title)
>> +                                 (and f (file-name-nondirectory f)))
>> +                             f nil nil)
>> +                       tgs))
>
> We have very too many whens in this function. It will be more succinct
> to use a single (pcase org-refile-use-outline-path …) instead.

Yes. But then I will be refactoring quite a lot of (working) code that I have not actually touching.

I would prefer doing that in the separate patch. You’ve suggested some changes in my patches which could be applied to some other places in org-mode files I have seen. May be once we finish this discussion I would send a new series of patches with restyling?

>> +  ;; When `org-refile-use-outline-path’ is `title’, return extracted
>> +  ;; document title
>> +  (should
>> +   (equal ’(“T” “T/H1”)
>> +     (org-test-with-temp-text-in-file “#+title: T\n* H1”
>
> You may as well add a test when multiple #+title lines are present.

Added.

>> From 62684b478ae5ceb03f66967fbebcc4d6163c826c Mon Sep 17 00:00:00 2001
>> From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
>> Date: Sat, 12 Sep 2020 18:10:05 +0200
>> Subject: [PATCH 2/3] org-agenda.el: show document title in outline path
>                                      ^Show

Fixed.

>> * lisp/org.el (org-display-outline-path): Show a document title (#+TITLE
>> value) and an outline path in an echo area if the customisation option
>> is set to ’title. Fallback to a file or a buffer name if the document
>                   ^  Fallback ;; (double space between sentences)

Fixed.

>> title is absent.
>
>>  ** New options
>> -*** New custom settings `org-icalendar-scheduled-summary-prefix' and `org-icalendar-deadline-summary-prefix'
>
> This is removing an existing NEWS entry. I guess it is not intentional.

Yes. Sorry about that — fixed.

>> +*** A new option for custom setting `org-agenda-show-outline-path' to show document title
>>
>>  (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 outline path with prepended document
>> +title.  Fallback to file name is no title is present.”
>>    :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)))
>
> I think you can leave
> (const :tag “Show outline path with prepended document title.” title)
>
> This text will be displayed in drop menu in cutomize interface alongside
> with the full docstring. Mentioning the fallback in the docstring should
> be good enough.

Agreed. Fixed.

>> From 5b15f886b22dc542220b48ae9659c4c2d56dea78 Mon Sep 17 00:00:00 2001
>> From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
>> Date: Thu, 8 Sep 2022 21:29:23 +0200
>> Subject: [PATCH 1/3] org-clock.el: rename org-clock-get-file-title
>                                     ^Rename

Fixed.

>> * lisp/org.el (org-get-title): A new function to collect a document
>> title from an org-mode buffer, based on a org-clock-get-file-title
>> implementation.
>
> `org-clock-get-file-title’. Elisp symbols should be quoted.

Done. (on a side note, all my email clients show ` and ’ quite differently. I wonder why.)

>>  ** New functions and changes in function arguments
>> +*** New function `org-get-title' to get `#+TITLE:' property from buffers
>
> We generally use `code' for Elisp symbols and `#+TITLE:' for verbatim
> non-code text. (This has not been consistently followed in etc/NEWS, but
> at least please change `#+TITLE' to `#+TITLE'). See
> doc/Documentation_Standards.org

Ah, yes. There are many occasions in the ORG-NEWS where this is not followed. Would you be interested in the patch fixing these irregularities?

And if you do, would you prefer to have a fixed-up commits for these ones or just one big commit? I recently learned about existence of git absorb and couldn’t recommend it enough.

>>  ** Removed or renamed functions and variables
>> +*** Rename `org-clock-get-file-title' to `org-get-file-title'
>> +
>> +This function is now part of the `org.el' file.
>
> You do not need to mention this. org-clock-get-file-title was
> introduced in recent commits on main. Main is development branch, and we
> do not need to document changes on the changes made after the last
> release.

OK. Fixed, left only a note about new function. I would say some users may find it interesting. I had a function that extracts title for many-many years. Used it for displaying document title in the frame title.

>>  ;;;###autoload
>>  (defun org-dblock-write:clocktable (params)
>>    “Write the standard clocktable.”
>> @@ -2739,7 +2729,7 @@ from the dynamic block definition.“
>>  			     ”\n“)
>>
>>                       (if filetitle
>> -                         (org-clock-get-file-title file-name)
>> +                         (org-get-file-title file-name)
>>                         (file-name-nondirectory file-name))
>>  		     (if level?    ”| “ ”“) ;level column, maybe
>>  		     (if timestamp ”| “ ”“) ;timestamp column, maybe
>
> This may introduce a compiler warning. I suggest running make after
> applying your patch and fix possible compiler warnings. (I suspect that
> you may need to add declare-function on top of org-clock.el)

Hm, I have tried it on the latest stable emacs (28.2) and it does not produce me a warning. `make compile' was just clean. Could you please refer me to the library/documentation why would I need to call `declare-function'? This is something from cl library?

>> +(defun org-get-file-title (file-name)
>> +  “Collect title from `org-mode’ FILE-NAME.
>> +
>> +Return file name if title does not exist.”
>> +  (or (org-get-title (find-file-noselect file-name))
>> +      (file-name-nondirectory file-name)))
>> +
>> +(defun org-get-title (&optional buffer)
>> +  “Collect title from the provided `org-mode’ BUFFER.
>> +
>> +Returns nil if there are no #+TITLE property.”
>> +  (let ((buffer (or (buffer-base-buffer)
>> +                    buffer
>> +                    (current-buffer))))
>> +    (with-current-buffer buffer
>> +      (org-macro-initialize-templates)
>> +      (let ((title (assoc-default “title” org-macro-templates)))
>> +        (unless (string= “” title)
>> +          title)))))
>
> These two functions can be merged into a single `org-get-title’ that
> accepts buffer or file-name as an optional argument.

Merged, but a little bit differently. Now the function accepts buffer or file. Also, I removed the basebuffer logic, because this logic is already included in the `org-macro-initialize-templates'.

Thanks,
Mikhail Skorzhinskii

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-org-refile.el-Show-refile-targets-with-a-title.patch --]
[-- Type: text/x-diff, Size: 6996 bytes --]

From 870f01312242fcbc56a66efb3a10d5bcf42144d6 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Mon, 21 Sep 2020 14:53:13 +0200
Subject: [PATCH 3/3] org-refile.el: Show refile targets with a title

* lisp/org-refile.el (org-refile-get-targets): Use a document
title (#+TITLE) instead of file or buffer name in outline path, if a
corresponding customisation option is set to 'title.  Fallback to a
filename if there is no title in the document.

* lisp/org-refile.el (org-refile-use-outline-path): Add a new option
'title, see above.
---
 etc/ORG-NEWS             |  6 +++++
 lisp/org-refile.el       | 17 ++++++++++---
 testing/lisp/test-org.el | 55 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 7b64f1b9d..2a2501c45 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -324,6 +324,12 @@ value of ~org-babel-clojure-backend~. For example:
 #+end_src
 
 ** New options
+*** A new option for custom setting ~org-refile-use-outline-path~ to show document title in refile targets
+
+Setting ~org-refile-use-outline-path~ to ~'title~ will show title
+instead of the file name in refile targets. If the documen do not have
+a title, the filename will be used, similar to ~'file~ option.
+
 *** A new option for custom setting ~org-agenda-show-outline-path~ to show document title
 
 Setting ~org-agenda-show-outline-path~ to ~'title~ will show title
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index edab0b225..6dd76d380 100644
--- a/lisp/org-refile.el
+++ b/lisp/org-refile.el
@@ -160,7 +160,8 @@ When `buffer-name', use the buffer name."
 	  (const :tag "Yes" t)
 	  (const :tag "Start with file name" file)
 	  (const :tag "Start with full file path" full-file-path)
-	  (const :tag "Start with buffer name" buffer-name)))
+	  (const :tag "Start with buffer name" buffer-name)
+	  (const :tag "Start with document title" title)))
 
 (defcustom org-outline-path-complete-in-steps t
   "Non-nil means complete the outline path in hierarchical steps.
@@ -319,6 +320,11 @@ converted to a headline before refiling."
 		 (push (list (and (buffer-file-name (buffer-base-buffer))
                                   (file-truename (buffer-file-name (buffer-base-buffer))))
                              f nil nil) tgs))
+               (when (eq org-refile-use-outline-path 'title)
+                 (push (list (or (org-get-title)
+                                 (and f (file-name-nondirectory f)))
+                             f nil nil)
+                       tgs))
 	       (org-with-wide-buffer
 		(goto-char (point-min))
 		(setq org-outline-path-cache nil)
@@ -345,7 +351,12 @@ converted to a headline before refiling."
                                            (and (buffer-file-name (buffer-base-buffer))
                                                 (file-name-nondirectory
                                                  (buffer-file-name (buffer-base-buffer))))))
-				   (`full-file-path
+                                   (`title (list
+                                            (or (org-get-title)
+                                                (and (buffer-file-name (buffer-base-buffer))
+                                                     (file-name-nondirectory
+                                                      (buffer-file-name (buffer-base-buffer)))))))
+                                   (`full-file-path
 				    (list (buffer-file-name
 					   (buffer-base-buffer))))
 				   (`buffer-name
@@ -633,7 +644,7 @@ this function appends the default value from
 	 (tbl (mapcar
 	       (lambda (x)
 		 (if (and (not (member org-refile-use-outline-path
-				       '(file full-file-path)))
+				       '(file full-file-path title)))
 			  (not (equal filename (nth 1 x))))
 		     (cons (concat (car x) extra " ("
 				   (file-name-nondirectory (nth 1 x)) ")")
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 4a6a3a0b0..334022c98 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6821,7 +6821,60 @@ Paragraph<point>"
    (org-test-with-temp-text "* H1"
      (let* ((org-refile-use-outline-path 'buffer-name)
 	    (org-refile-targets `((nil :level . 1))))
-       (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
+       (member (buffer-name) (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title', return extracted
+  ;; document title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+        (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' validate that
+  ;; deeper levels are correctly reported too (the same behaviour as
+  ;; 'file)
+  (should
+   (equal '("T" "T/H1" "T/H1/H2" "T/H1/H2/H3" "T/H1")
+     (org-test-with-temp-text-in-file "#+title: T\n* H1\n** H2\n*** H3\n* H1"
+       (let ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :maxlevel . 3))))
+         (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document do not
+  ;; have an extracted document title, return just the file name
+  (should
+   (org-test-with-temp-text-in-file "* H1"
+     (let* ((filename (buffer-file-name))
+            (org-refile-use-outline-path 'title)
+            (org-refile-targets `((nil :level . 1))))
+       (member (file-name-nondirectory filename)
+               (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and document is a
+  ;; temporary buffer without a file, it is still possible to extract
+  ;; a title
+  (should
+   (equal '("T" "T/H1")
+     (org-test-with-temp-text "#+title: T\n* H1\n** H2"
+      (let* ((org-refile-use-outline-path 'title)
+             (org-refile-targets `((nil :level . 1))))
+      (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and there are two
+  ;; title keywords in the file, titles are concatenated into a single
+  ;; one.
+  (should
+   (equal '("T1 T2" "T1 T2/H1")
+     (org-test-with-temp-text "#+title: T1\n#+title: T2\n* H1\n** H2"
+       (let* ((org-refile-use-outline-path 'title)
+              (org-refile-targets `((nil :level . 1))))
+       (mapcar #'car (org-refile-get-targets))))))
+  ;; When `org-refile-use-outline-path' is `title' and there are two
+  ;; title keywords in the file, titles are concatenated into a single
+  ;; one even if they are in the middle of the file.
+  (should
+   (equal '("T1 T2" "T1 T2/H1")
+     (org-test-with-temp-text "#+title: T1\n* H1\n** H2\n#+title: T2\n"
+       (let* ((org-refile-use-outline-path 'title)
+              (org-refile-targets `((nil :level . 1))))
+       (mapcar #'car (org-refile-get-targets)))))))
 
 
 \f
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-agenda.el-Show-document-title-in-outline-path.patch --]
[-- Type: text/x-diff, Size: 4645 bytes --]

From 12da8c1ccd1efa9c4f1282d213a46f93bf10410d Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Sat, 12 Sep 2020 18:10:05 +0200
Subject: [PATCH 2/3] org-agenda.el: Show document title in outline path

* lisp/org-agenda.el (org-agenda-show-outline-path): Add an option to
show a document title at start of an outline path, instead of a file or
a buffer name.

* lisp/org.el (org-display-outline-path): Show a document title (#+TITLE
value) and an outline path in an echo area if the customisation option
is set to 'title.  Fallback to a file or a buffer name if the document
title is absent.
---
 etc/ORG-NEWS       |  6 ++++++
 lisp/org-agenda.el | 12 +++++++++---
 lisp/org.el        | 12 +++++++++---
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e96aa482b..7b64f1b9d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -324,6 +324,12 @@ value of ~org-babel-clojure-backend~. For example:
 #+end_src
 
 ** New options
+*** A new option for custom setting ~org-agenda-show-outline-path~ to show document title
+
+Setting ~org-agenda-show-outline-path~ to ~'title~ will show title
+instead of the file name at the beginning of the outline. The title of
+the document can be set by special keyword =#+title:=.
+
 *** New custom settings =org-icalendar-scheduled-summary-prefix= and =org-icalendar-deadline-summary-prefix=
 
 These settings allow users to define prefixes for exported summary
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 3bac53965..6c0be68ac 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1068,9 +1068,15 @@ 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 outline path with prepended document
+title.  Fallback to file name is no title is present."
   :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." title)))
 
 (defcustom org-agenda-start-with-entry-text-mode nil
   "The initial value of entry-text-mode in a newly created agenda window."
@@ -9468,7 +9474,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 f51e6d6d9..e93a81210 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7437,10 +7437,12 @@ Returns nil if there are no #+TITLE property."
         (unless (string= "" title)
           title)))))
 
-(defun org-display-outline-path (&optional file current separator just-return-string)
+(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 \"/\".
@@ -7448,6 +7450,7 @@ 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 (eq file-or-title 'title) (org-get-title)))
 	 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
 	 res)
     (when current (setq path (append path
@@ -7459,7 +7462,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.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-org-clock.el-Rename-org-clock-get-file-title.patch --]
[-- Type: text/x-diff, Size: 3363 bytes --]

From 669bb68aae3da16d0336bb7e6e1950bb716c8719 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskii@eml.cc>
Date: Thu, 8 Sep 2022 21:29:23 +0200
Subject: [PATCH 1/3] org-clock.el: Rename org-clock-get-file-title

* lisp/org.el (org-get-title): A new function to collect a document
title from an org-mode buffer, based on a `org-clock-get-file-title'
implementation.

* lisp/org-clock.el (org-clock-get-file-title): Removed
---
 etc/ORG-NEWS      |  4 ++++
 lisp/org-clock.el | 13 ++-----------
 lisp/org.el       | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c18c03725..e96aa482b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -361,6 +361,10 @@ event time when the alarm time is set to 0.  The default value is
 nil -- do not create alarms at the event time.
 
 ** New functions and changes in function arguments
+*** New function ~org-get-title~ to get =#+TITLE:= property from buffers
+
+A function to collect the document title from the org-mode buffer.
+
 *** ~org-fold-show-entry~ does not fold drawers by default anymore
 
 ~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS.
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 6332399bb..e98a34f0d 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2484,16 +2484,6 @@ the currently selected interval size."
 	  (org-update-dblock)
 	  t)))))
 
-(defun org-clock-get-file-title (file-name)
-  "Get the file title from FILE-NAME as a string.
-Return short FILE-NAME if #+title keyword is not found."
-  (with-current-buffer (find-file-noselect file-name)
-    (org-macro-initialize-templates)
-    (let ((title (assoc-default "title" org-macro-templates)))
-      (if (null title)
-          (file-name-nondirectory file-name)
-        title))))
-
 ;;;###autoload
 (defun org-dblock-write:clocktable (params)
   "Write the standard clocktable."
@@ -2750,7 +2740,8 @@ from the dynamic block definition."
 			     "\n")
 
                      (if filetitle
-                         (org-clock-get-file-title file-name)
+                         (or (org-get-title file-name)
+                             (file-name-nondirectory file-name))
                        (file-name-nondirectory file-name))
 		     (if level?    "| " "") ;level column, maybe
 		     (if timestamp "| " "") ;timestamp column, maybe
diff --git a/lisp/org.el b/lisp/org.el
index 8191f0860..f51e6d6d9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7423,6 +7423,20 @@ the default is \"/\"."
 	(setf (substring fpath (- width 2)) "..")))
     fpath))
 
+(defun org-get-title (&optional buffer-or-file)
+  "Collect title from the provided `org-mode' BUFFER-OR-FILE.
+
+Returns nil if there are no #+TITLE property."
+  (let ((buffer (cond ((bufferp buffer-or-file) buffer-or-file)
+                      ((stringp buffer-or-file) (find-file-noselect
+                                                 buffer-or-file))
+                      (t (current-buffer)))))
+    (with-current-buffer buffer
+      (org-macro-initialize-templates)
+      (let ((title (assoc-default "title" org-macro-templates)))
+        (unless (string= "" title)
+          title)))))
+
 (defun org-display-outline-path (&optional file current separator just-return-string)
   "Display the current outline path in the echo area.
 
-- 
2.35.1


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

* Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix
  2022-10-23 19:15                       ` Mikhail Skorzhisnkii
@ 2022-10-25  6:59                         ` Ihor Radchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Ihor Radchenko @ 2022-10-25  6:59 UTC (permalink / raw)
  To: Mikhail Skorzhisnkii; +Cc: Ihor Radchenko, Org Mode

Mikhail Skorzhisnkii <mskorzhinskii@eml.cc> writes:

> Hi, Ihor,
>
> Sorry for the delay with fixes, took some time before I got time to finish this. Thanks for your review and looking forward for the next iteration. See new version in the attachment. Comments are inline.

Thanks!
Applied onto main with minor amendments (typos).
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d4e7bcb4bd87afbcb08a013111ebc976e3cf3b58
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=55767b792ee7dce41e43e6a48d48813dd9ad7f7c
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c3aa6a6d43fd621bf82c4510c7a63dca7768e6dd

>>>  (defcustom org-outline-path-complete-in-steps t
>>>    “Non-nil means complete the outline path in hierarchical steps.
>>> @@ -319,6 +320,11 @@ converted to a headline before refiling.”
>>>  		 (push (list (and (buffer-file-name (buffer-base-buffer))
>>>                                    (file-truename (buffer-file-name (buffer-base-buffer))))
>>>                               f nil nil) tgs))
>>> +               (when (eq org-refile-use-outline-path ’title)
>>> +                 (push (list (or (org-get-title)
>>> +                                 (and f (file-name-nondirectory f)))
>>> +                             f nil nil)
>>> +                       tgs))
>>
>> We have very too many whens in this function. It will be more succinct
>> to use a single (pcase org-refile-use-outline-path …) instead.
>
> Yes. But then I will be refactoring quite a lot of (working) code that I have not actually touching.
>
> I would prefer doing that in the separate patch. You’ve suggested some changes in my patches which could be applied to some other places in org-mode files I have seen. May be once we finish this discussion I would send a new series of patches with restyling?

That would be great.

>> We generally use `code' for Elisp symbols and `#+TITLE:' for verbatim
>> non-code text. (This has not been consistently followed in etc/NEWS, but
>> at least please change `#+TITLE' to `#+TITLE'). See
>> doc/Documentation_Standards.org
>
> Ah, yes. There are many occasions in the ORG-NEWS where this is not followed. Would you be interested in the patch fixing these irregularities?

Yes.

> And if you do, would you prefer to have a fixed-up commits for these ones or just one big commit? I recently learned about existence of git absorb and couldn’t recommend it enough.

We do not modify git logs on savannah servers.
Doing so would break user mirrors and could break commit links in the
mailing list.

>>>                       (if filetitle
>>> -                         (org-clock-get-file-title file-name)
>>> +                         (org-get-file-title file-name)
>>>                         (file-name-nondirectory file-name))
>>>  		     (if level?    ”| “ ”“) ;level column, maybe
>>>  		     (if timestamp ”| “ ”“) ;timestamp column, maybe
>>
>> This may introduce a compiler warning. I suggest running make after
>> applying your patch and fix possible compiler warnings. (I suspect that
>> you may need to add declare-function on top of org-clock.el)
>
> Hm, I have tried it on the latest stable emacs (28.2) and it does not produce me a warning. `make compile' was just clean. Could you please refer me to the library/documentation why would I need to call `declare-function'? This is something from cl library?

If there is no warning, I was wrong.

declare-function is used when we do not explicitly require the library
containing that function but know for sure that the function will be
defined on runtime. See 13.15 Telling the Compiler that a Function is
Defined section of Elisp manual.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2022-10-25  8:24 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-25 15:24 [PATCH] ox-icalendar.el: customizable vevent summary prefix Mikhail Skorzhinskii
2021-12-26 21:26 ` Nicolas Goaziou
2021-12-28 12:10   ` Mikhail Skorzhinskii
2022-07-31  7:16     ` Ihor Radchenko
2022-07-31  7:35       ` Mikhail Skorzhinskiy
2022-07-31 13:02         ` Ihor Radchenko
2022-08-30 13:50           ` Mikhail Skorzhisnkii
2022-08-31 12:09             ` Ihor Radchenko
2022-09-05 18:50               ` Mikhail Skorzhisnkii
2022-09-08  5:40                 ` Ihor Radchenko
2022-09-08 20:10                   ` Mikhail Skorzhisnkii
2022-09-09 10:13                     ` Ihor Radchenko
2022-10-23 19:15                       ` Mikhail Skorzhisnkii
2022-10-25  6:59                         ` Ihor Radchenko
2022-08-31 12:11             ` Ihor Radchenko
2022-09-01  7:29               ` Bastien
2022-08-31 12:13             ` Ihor Radchenko
2022-09-05 18:59               ` Mikhail Skorzhisnkii
2022-09-05 19:28             ` Mikhail Skorzhisnkii
2022-09-08  5:33               ` Ihor Radchenko

Code repositories for project(s) associated with this public 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).