Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-10-23 Thread Mikhail Skorzhisnkii
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  writes:

> Mikhail Skorzhisnkii  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 
>> 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 
>&g

Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-09-08 Thread Mikhail Skorzhisnkii
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  writes:

> Mikhail Skorzhisnkii  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.
>From 47c61b597a3064755964d763621616d184c351ad Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii 
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
-   '

Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-09-05 Thread Mikhail Skorzhisnkii
Resubmitting this patch with better commit message.

Mikhail Skorzhisnkii  writes:

> I have signed FSF papers. Attaching a rebased patch with additional changes to
> ORG-NEWS
>
> Ihor Radchenko  writes:
>
>> “Mikhail Skorzhinskiy”  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]…
>From 38c940230e84af34f023a17033fbbe0723e25b0d Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii 
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



Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-09-05 Thread Mikhail Skorzhisnkii
Thanks for your comment, Ihor. I have addressed your comments, see some 
comments inline. Attaching new version of the patch.

Ihor Radchenko  writes:

> Mikhail Skorzhisnkii  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 ( file current separator 
>> just-return-string)
>> +(defun org-get-title-from-buffer ( 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 ( 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)))
>> +

Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-09-05 Thread Mikhail Skorzhisnkii
Ah, sorry — probably forgot to attach it, yes. See the second patch here in the 
attachment.

Ihor Radchenko  writes:

> Mikhail Skorzhisnkii  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?
>From 686a1d813ec8962bff993add1305015eb2788213 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii 
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"
(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 '

Re: [PATCH] org-agenda.el: customise outline path in echo area

2022-08-30 Thread Mikhail Skorzhisnkii
I have signed the FSF papers now and we can continue the review of this work 
now.

I am attaching updated and rebased patch for this and another e-mail thread, 
since these two patches are depend on each other. I have additionally tested 
the functionality of these changes by verifying that it works as expected on my 
setup;

• Tried to use org-agenda on buffers with and without title property set
• Tried to call org-refile and see if refiling will happen
• `make test' passes

I have *not* tried to see if it will work on buffers without file 
representation, but the component tests for refile should cover that.

Let me know what you think.

  Thanks,
  Mikhail Skorzhinskii

Ihor Radchenko  writes:

> Mikhail Skorzhinskii  writes:
>
>> Thank you for your comments once again. I’ve changed string= to eq and
>> it appears to be working OK.
>>
>> I’ve also renamed “title” variable to “title-prop” for better
>> readability. The -prop suffix should show the reader that it was
>> extracted from the file, and thus cost some CPU/IO.
>>
>> I’ve attached an updated version to this email. Would love to hear what
>> you think.
>
> Thanks! And sorry for the late reply. Your patch fell through the cracks
> in my todo list.
>
>> * lisp/org-agenda.el (org-agenda-show-outline-path): add an option to
>> show document title in outline path (instead of file name)
>> * lisp/org.el (org-get-title-from-file): a function to collect the
>> document title from the org-mode file
>> * lisp/org.el (org-display-outline-path): add logic that will collect a
>> document title and put it into the outline path if
>> org-agenda-show-outline-path set to ’title
>
> It would make sense to document the new customization in ORG-NEWS.
>
>> +(defun org-get-title-from-file (file)
>> +  “Collect tilte from the provided `org-mode’ FILE.”
>> +  (let (title)
>   ^ typo
>> +(when file
>> +  (with-current-buffer
>> +  (get-file-buffer file)
>> +(pcase (org-collect-keywords ’(“TITLE”))
>> +  (`((“TITLE” . ,val))
>> +   (setq title (car val)
>> +  title)))
>
> Note that this function behavior is underfined when FILE buffer does not
> exist. It would be better to accept buffer as argument.
>
> Best,
> Ihor
>From 646af66fa88fbcc2b1f2848a14dd5c262763ef98 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii 
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 an option 'title
* lisp/org-refile.el (org-refile-get-targets): start refile target
outline with document title (#+title) instead of file name
---
 etc/ORG-NEWS |  4 
 lisp/org-refile.el   | 16 +---
 testing/lisp/test-org.el | 37 -
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4405489bb..df2c882bb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -290,6 +290,10 @@ 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
 
 Settings =org-agenda-show-outline-path=  to ='title= will show title instead of
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 01f0dfa46..14bd81a2b 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,13 @@ converted to a headline before refiling."
(and (buffer-file-name (buffer-base-buffer))
 (file-name-nondirectory

Re: [PATCH] ox-icalendar.el: customizable vevent summary prefix

2022-08-30 Thread Mikhail Skorzhisnkii
I have signed FSF papers. Attaching a rebased patch with additional changes to
ORG-NEWS

Ihor Radchenko  writes:

> “Mikhail Skorzhinskiy”  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
>From ceb6c9836032c92a792bf58aab91d74141664f50 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii 
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 ( file current separator just-return-string)
+(defun org-get-title-from-buffer ( 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 ( 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 

Re: [PATCH] org-refile.el: show refile targets with doc. title

2022-08-30 Thread Mikhail Skorzhisnkii
I have signed the FSF papers. However for the simplicity I will send renewed 
patch in different thread. You may consider this thread to be closed.q

E-Mail thread I am going to use is: 


  Thanks,
  Mikhail Skorzhinskii

Ihor Radchenko  writes:

> Mikhail Skorzhinskii  writes:
>
>> Thank you for reviewing the changes. Sorry for the sloppy patch, I’ve
>> retested everything and added a few additional fixes, there were more
>> problems.
>
> Thanks! And sorry for the slow review. Your email was lost near the tail
> of the todo list.
>
>> I’ve added a couple of test cases too. (BTW, test framework is awesome
>> and really easy to use!)
>
> Great!
>
>> * lisp/org-refile.el (org-refile-use-outline-path): add an option ’title
>> * lisp/org-refile.el (org-refile-get-targets): start refile target
>> outline with document title (#+title) instead of file name
>
> Note that changes like this should be detailed in etc/ORG-NEWS
>
>> -  (const :tag “Start with buffer name” buffer-name)))
>> +  (const :tag “Start with buffer name” buffer-name)
>> +  (const :tag “Start with document title” title)))
>
> You also need to document the new option in the docstring.
>
>> +  ;; 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 `(((,filename) :level . 1
>> +   (member (file-name-nondirectory filename)
>> +   (mapcar #’car (org-refile-get-targets)))
>
> It would also make sense to add a test when document is a temporary
> buffer without filename and also does not contain a title.
>
> Finally, your patch is exceeding 15LOC. You need to do copyright
> paperwork to get the patch merged. See
> 
>
> Best,
> Ihor


Re: [PATCH] org-agenda.el: agenda*: add lost argument

2022-08-30 Thread Mikhail Skorzhisnkii
This patch is no longer needed, as the bug was fixed in other commit.

Ihor Radchenko  writes:

> Mikhail Skorzhinskii  writes:
>
>> * lisp/org-agenda.el (org-agenda): add lost argument for agenda*
>
> Thanks! I am not able to apply your patch onto main. Could you resend,
> preferably adding the patch as an attachment and adding TINYCHANGE
> cookie (you do not seem to have the copyright assignment)?
>
> See 
>
> Best,
> Ihor


Re: Bug: Entries with 0 minutes logged triggers clocking overlap [9.5 (nil @ /home/eddie/.emacs.d/.local/straight/build-26.3/org-mode/)]

2021-03-06 Thread Mikhail Skorzhisnkii
Hi, Eddie,

I am not against fixing clocking overlap, however I personally deal with
this by not clocking zero time at all. Are you aware about the existence
of `org-clock-out-remove-zero-time-clocks'? Setting this variable to
non-nil will remove clock lines when the resulting time is zero.

  Kind regards,
  Mikhail Skorzhinskii


Re: [org-save-all-org-buffers] Saving is not reliable?

2020-12-13 Thread Mikhail Skorzhisnkii
I found the bug. The bug was mostly my own creation. There was a 
small (but very destructive) bug in doom emacs distribution. Fixed 
that bug and sent them a pull requested: 
https://github.com/hlissner/doom-emacs/pull/4424


Basically I made a small snippet for agenda that makes side window 
of agenda staticly sized, really small and includes only very 
small portion of context related to agenda entry. And to correctly 
possition it in frame, I've used wonderful doom emacs popup 
syntax:


 (set-popup-rule! "^*org-agenda-side\*"
   :side 'top
   :size 0.15
   :autosave t
   :quit t)

Turns out :autosave ignores indirect buffers and sets 
buffer-modified-p state to nil. Hope this is the end of my quest, 
My previous solution was also very clunky.


Mikhail Skorzhinskii


Samuel Wales  writes:

an undo-boundary bug can make something unexpected get undone as 
part
of a batch or make an org operation require two undos.  the 
agenda is

one place where these bugs have existed.


On 12/9/20, Eric S Fraga  wrote:

On Wednesday,  9 Dec 2020 at 11:16, Mikhail Skorzhisnkii wrote:

It's kind of reproduction scenario. Basically I need to
modify buffer from search-type agenda.


In the past, anecdotally I have seen something similar: adjust 
the
scheduled date for an entry via the agenda view and ask to save 
all org
buffers.  The change to the scheduled date is sometimes 
forgotten.  I
haven't tried with emacs -Q so it could, as in Mikhail's case, 
be
configuration dependent and it's also not entirely reproducible 
(i.e. it

sometimes happens, sometimes doesn't).

But I've not seen this happen recently so maybe it was a bug 
along the
way.  Sorry for vagueness but I thought I'd chime in just in 
case it

helps.
--
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-160-g7c8dce





--
---
Mikhail Skorzhinskii



Re: [org-save-all-org-buffers] Saving is not reliable?

2020-12-09 Thread Mikhail Skorzhisnkii

Hi, Kyle,

Thank you for finding time to take a look at this. I have 
experienced data loss once again, so you're right. This is not 
indirect buffers, i.e. my fix is not working. I was just lucky.


Fortunately I managed to capture the moment in emacs when it 
happens. It's kind of reproduction scenario. Basically I need to 
modify buffer from search-type agenda. For example, search for 
tags and then change TODO state or add a note. Then use 
`org-save-all-org-buffers`. Function will report that it is done 
its job and buffers will be marked as non-modified. But in fact 
they are modified and unsaved.


I can't reproduce this in emacs without my configuration (i.e. 
only emacs and most recent org-mode). So it must be something that 
interfere with buffer "modified" state. I guess I need to review 
every hook related to buffer saving. I think (but unsure) it is 
start happening when I have start enabling follow-mode in agenda 
from start up.


For the time being I have applied advice from this stack overflow 
question: 
https://stackoverflow.com/questions/3215866/how-to-force-emacs-to-save-even-if-it-thinks-no-changes-need-to-be-saved


 (defadvice save-buffer (before save-buffer-always activate)
   "always save buffer"
   (set-buffer-modified-p t))

It looks like it helps me. I'll report back to this thread when I 
find the offender. I guess I'm calling (set-buffer-modified-p nil) 
somewhere unknowingly.


Mikhail Skorzhinskii

Kyle Meyer  writes:


Mikhail Skorzhisnkii writes:


Hello forum,

I start noticing some time ago that saving org-mode buffers 
works

unreliably in my setup. Most of the time I am using function
`org-save-all-org-buffers' from core org.


Unreliable in that some Org buffers are left in a modified 
state?


[...]
Possibly there is something wrong in my customisations. But 
without a
reproduction scenario, I don't see a way to prove it. However, 
after I
made a tiny change to the function, I stopped seeing these 
problems at

all. Here is the fix I have applied:

,
| diff --git a/lisp/org.elf b/lisp/org.el
| index df3f377f6..448dc4a88 100644
| --- a/lisp/org.el
| +++ b/lisp/org.el
| @@ -15229,7 +15229,9 @@ The value is a list, with zero or 
more of the symbols `effort', `appt',

|"Save all Org buffers without user confirmation."
|(interactive)
|(message "Saving all Org buffers...")
| -  (save-some-buffers t (lambda () (derived-mode-p 
'org-mode)))

| +  (save-some-buffers t (lambda ()
| + (and (derived-mode-p 'org-mode)
| +  (not (buffer-base-buffer)
|(when (featurep 'org-id) (org-id-locations-save))
|(message "Saving all Org buffers... done"))
`

My theory was that `save-some-buffers' may work unreliably with 
indirect
buffers, so I've excluded them from the saving. Again, I have 
tried to
prove it by using indirect buffer and saving it instead of base 
buffer.
But it worked without a problem. So even if my theory is 
correct, bug
not reproducing every time. Nevertheless I am having this 
change already
for two weeks and I don't have reproduction of this bug. 
Previously I've

noticed loosing data every day or so.


Hmm, I may be completely missing something, but for what it's 
worth, I'd
be surprised if indirect buffers are the culprit.  When you save 
an
indirect buffer directly, it should just save the base buffer. 
And in
any case, save-some-buffers should skip indirect buffers.  Here 
is the
relevant handling from save-some-buffers, with the key line 
marked:


(setq files-done
  (map-y-or-n-p
   (lambda (buffer)
 (and (buffer-live-p buffer)
  (buffer-modified-p buffer)
  (not (buffer-base-buffer buffer))  ; <- skip 
  indirect buffers

  (or
   (buffer-file-name buffer)
   (with-current-buffer buffer
 (or (eq buffer-offer-save 'always)
 (and pred buffer-offer-save
  (> (buffer-size) 0)
  (or (not (functionp pred))
  (with-current-buffer buffer (funcall 
  pred)))

  (if arg
  t
(setq queried t)
(if (buffer-file-name buffer)
(format "Save file %s? "
(buffer-file-name buffer))
  (format "Save buffer %s? "
  (buffer-name buffer))
   (lambda (buffer)
 (with-current-buffer buffer
   (save-buffer)))
   (buffer-list)
   '("buffer" "buffers" "save")
   save-some-buffers-action-alist))



--
---
Mikhail Skorzhinskii



[org-save-all-org-buffers] Saving is not reliable?

2020-12-07 Thread Mikhail Skorzhisnkii
Hello forum,

I start noticing some time ago that saving org-mode buffers works
unreliably in my setup. Most of the time I am using function
`org-save-all-org-buffers' from core org. Unfortunately I don't have a
good reproduction scenarios of this bug. In fact I don't have
reproduction scenario at all. It just happens sometimes: I am sure I
saved all org buffers I had, then restart emacs and then I see that some
changes were not actually saved.

Possibly there is something wrong in my customisations. But without a
reproduction scenario, I don't see a way to prove it. However, after I
made a tiny change to the function, I stopped seeing these problems at
all. Here is the fix I have applied:

,
| diff --git a/lisp/org.elf b/lisp/org.el
| index df3f377f6..448dc4a88 100644
| --- a/lisp/org.el
| +++ b/lisp/org.el
| @@ -15229,7 +15229,9 @@ The value is a list, with zero or more of the symbols 
`effort', `appt',
|"Save all Org buffers without user confirmation."
|(interactive)
|(message "Saving all Org buffers...")
| -  (save-some-buffers t (lambda () (derived-mode-p 'org-mode)))
| +  (save-some-buffers t (lambda ()
| + (and (derived-mode-p 'org-mode)
| +  (not (buffer-base-buffer)
|(when (featurep 'org-id) (org-id-locations-save))
|(message "Saving all Org buffers... done"))
`

My theory was that `save-some-buffers' may work unreliably with indirect
buffers, so I've excluded them from the saving. Again, I have tried to
prove it by using indirect buffer and saving it instead of base buffer.
But it worked without a problem. So even if my theory is correct, bug
not reproducing every time. Nevertheless I am having this change already
for two weeks and I don't have reproduction of this bug. Previously I've
noticed loosing data every day or so.

I don't suggest to apply this patch, but may be someone have\had the
same problem or have a deeper insight how indirect buffers work and why
my fix may be a working solution?

  Kind regards,
  Mikhail Skorzhinskii


Re: generate an org file for today's appointments

2020-12-03 Thread Mikhail Skorzhisnkii
I'd suggest to use function "org-agenda-write". You can export 
your agenda views to org files too! However, the formatting will 
be different. Probably something like:


* Event A
 SCHEDULED: <2020-12-03 Thu 10:00-12:00>
* Event B
 SCHEDULED: <2020-12-03 Thu 10:00-11:00>
* Event C
 SCHEDULED: <2020-12-03 Thu 14:00-15:30>
* Event D
 SCHEDULED: <2020-12-03 Thu 20:00-21:30>

I personally do this to generate separate org-file and then 
generate ics file based on that and upload this ics file through 
WebDAV to my calendar server.


Mikhail Skorzhinskii

Alan Schmitt  writes:


Hello,

I have my calendars converted to org files (using ical2orgpy), 
and as I
include them as agenda files, I have this nice view in 
org-agenda:


   9:10.. now - - - - - - - - - - - - - - - - - 
   - - - - - - - -

  AlanWork:   10:00-12:00 Event A -
  Chris:  10:00-11:00 Event B -
  10:00.. 
  12:00.. 
  AlanWork:   14:00-15:30 Event C -
  14:00.. 
  16:00.. 
  18:00.. 
  Alan:   20:00-21:30 Event D -

Is there a way to piggy-back on all the work that org-agenda 
already did

to generate something like:

** 10:00 Event A
** 10:00 Event B
** 14:00 Event C
** 20:00 Event D

This would then be inserted in my daily journal file.

I guess the alternative is using org-element to extract the 
information
from the calendars in org format, but it seems to me org-agenda 
already

did all the hard work.

Do you have suggestions to do this?

Thanks,

Alan




Re: Clock tables and two ways to categorize tasks

2020-11-19 Thread Mikhail Skorzhisnkii

Hi Marcin,

I tried to solve this issue for myself. My first attempt to solve 
it was to understand which tags are interesting and then make a 
template with as many tables as there were interesting tag 
combinations. But then I faced another problem: sometimes I am 
using different set of tags and templates don't work as good as 
they could.


To mitigate that problem, I've tried different approach. I made a 
small package that generates me reports for past week or past 
month. It's working for me, but there are a lot of rough edges 
around it. Basically it collects headers with clocks, copies them 
to separate file, rearrange them and generate clock tables. You 
can try it here:


 https://github.com/mskorzhinskiy/org-ir

Another way would be to write your own clock table sorter. See 
this post on reddit:


 
https://www.reddit.com/r/emacs/comments/jp5ear/sorting_org_clocktables_by_category_instead_of/

And just for future references, in case Reddit someday will go 
down:


 Code from /u/jp5ear: 
 https://gist.github.com/blockynight/5eebe8323b68e02f436c0440320dc926
 Org-mode manual: https://orgmode.org/manual/The-clock-table.html 
 (see :formatter parameter)


Mikhail Skorzhinskii

Marcin Borkowski  writes:


Hi all,

here's the problem I'd like to solve.  I clock various tasks, 
and then
generate a clock table.  So far, so good.  But now I'd like to 
know

better where my time goes.  Most tasks I do have a few similar
components: discussion/research, writing code, testing, etc.  I 
thought
that I could create subheadlines under each of the tasks and 
give them
tags like :discuss:, :code:, :test:, :debug: and so on.  (Not 
very
convenient, but doable, maybe with a bit of Elisp to automate 
the

process.)

Now, I'd like to prepare two clock tables: one where I see how 
much time
every task took, and one where I can see how much time I spent 
coding,
testing, debugging, emailing etc.  I can see in the docs that 
there is
the ~:match~ option, but if I understand it correctly, it can 
only
restrict the table to /one/ tag, so I'd need to have as many 
tables as

I have tags - not optimal.

Any ideas?  Should I use something else than tags for that?

TIA,



--
---
Mikhail Skorzhinskii



Re: Folding headings which contain only blank lines

2020-10-16 Thread Mikhail Skorzhisnkii

Hi,

Patch ee3c3b554799c9f0fbe387848cd9eec7e9ab9d95 breaks unfolding 
when

org-cycle-separator-lines set to -1.

How to reproduce:
 1. Set org-cycle-separator-lines to -1;
 2. Try to fold and then unfold "Test" in the following file:
#+begin_example
,* Test 1
,** Test 2




,* Test 3
#+end_example

Unfolding will not unfold Test1 with 
ee3c3b554799c9f0fbe387848cd9eec7e9ab9d95 applied. Reverting this 
patch makes it working back. Is there are any other way to fix 
this? Or may be this can be made as a customisation option?


Bastien  writes:


Hi Dmitrii,

Dmitrii Korobeinikov  writes:

When everything is folded (e.g. on startup), ellipses show 
after every
heading which has anything in it at all. This is true as well 
for the
headings containing only one or more blank lines. And while you 
can
unfold such lines, you can't fold them back unless you use 
Shift-Tab.
This appears to be inconsistent. Shouldn't it be possible to 
tab fold

such headings too?


this should be fixed now (in ee3c3b554), thanks for reporting 
this.



Kind regards,
 Mikhail Skorzhinskii