* [PATCH] org-refile.el: show refile targets with doc. title
@ 2021-12-25 15:23 Mikhail Skorzhinskii
2021-12-26 13:59 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-25 15:23 UTC (permalink / raw)
To: Org Mode
* 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
---
lisp/org-refile.el | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 678759e10..8ff1b2f5b 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,8 @@ 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 (org-get-title-from-file (file-truename
(buffer-file-name (buffer-base-buffer)))) f nil nil) tgs))
(org-with-wide-buffer
(goto-char (point-min))
(setq org-outline-path-cache nil)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org-refile.el: show refile targets with doc. title
2021-12-25 15:23 [PATCH] org-refile.el: show refile targets with doc. title Mikhail Skorzhinskii
@ 2021-12-26 13:59 ` Ihor Radchenko
2021-12-28 11:59 ` Mikhail Skorzhinskii
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2021-12-26 13:59 UTC (permalink / raw)
To: Mikhail Skorzhinskii; +Cc: Org Mode
Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
> * lisp/org-refile.el (org-refile-use-outline-path): add an option
> 'title
This is an interesting idea. However, your patch may break things quite
badly. Look at `org-refile-get-location'. It expects a very specific
format for the refile targets and treats 'file/'full-file-path values
specially.
Can you add tests for your new value of org-refile-use-outline-path and
make sure that they do not fail after applying your patch?
Best,
Ihor
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org-refile.el: show refile targets with doc. title
2021-12-26 13:59 ` Ihor Radchenko
@ 2021-12-28 11:59 ` Mikhail Skorzhinskii
2022-05-28 2:33 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Mikhail Skorzhinskii @ 2021-12-28 11:59 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 937 bytes --]
Hi Ihor,
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.
I've added a couple of test cases too. (BTW, test framework is awesome
and really easy to use!)
I've attached new patch to this email. Let me know what you think.
Thanks,
Mikhail
On Sun, 2021-12-26 at 21:59 +0800, Ihor Radchenko wrote:
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> writes:
>
> > * lisp/org-refile.el (org-refile-use-outline-path): add an option
> > 'title
>
> This is an interesting idea. However, your patch may break things
> quite
> badly. Look at `org-refile-get-location'. It expects a very specific
> format for the refile targets and treats 'file/'full-file-path values
> specially.
>
> Can you add tests for your new value of org-refile-use-outline-path
> and
> make sure that they do not fail after applying your patch?
>
> Best,
> Ihor
>
>
[-- Attachment #2: 0002-org-refile.el-show-refile-targets-with-doc.-title.patch --]
[-- Type: text/x-patch, Size: 5080 bytes --]
From e6d3aae4a75e50423924e0eacbcd94cdea7dafe8 Mon Sep 17 00:00:00 2001
From: Mikhail Skorzhinskii <mskorzhinskiy@eml.cc>
Date: Mon, 21 Sep 2020 14:53:13 +0200
Subject: [PATCH 2/5] 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
---
lisp/org-refile.el | 18 +++++++++++++++---
testing/lisp/test-org.el | 29 ++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 678759e10..644e9f497 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-file (file-truename (buffer-file-name (buffer-base-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,15 @@ 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-file
+ (file-truename
+ (buffer-file-name (buffer-base-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 +643,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 056ea7d87..a6df00baf 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6435,7 +6435,34 @@ 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* ((filename (buffer-file-name))
+ (org-refile-use-outline-path 'title)
+ (org-refile-targets `(((,filename) :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 `(((,filename) :level . 1))))
+ (member (file-name-nondirectory filename)
+ (mapcar #'car (org-refile-get-targets)))))))
\f
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org-refile.el: show refile targets with doc. title
2021-12-28 11:59 ` Mikhail Skorzhinskii
@ 2022-05-28 2:33 ` Ihor Radchenko
2022-08-30 13:53 ` Mikhail Skorzhisnkii
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-05-28 2:33 UTC (permalink / raw)
To: Mikhail Skorzhinskii; +Cc: Org Mode
Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> 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
https://orgmode.org/worg/org-contribute.html#copyright
Best,
Ihor
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] org-refile.el: show refile targets with doc. title
2022-05-28 2:33 ` Ihor Radchenko
@ 2022-08-30 13:53 ` Mikhail Skorzhisnkii
0 siblings, 0 replies; 5+ messages in thread
From: Mikhail Skorzhisnkii @ 2022-08-30 13:53 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Mikhail Skorzhinskii, Org Mode
[-- Attachment #1: Type: text/plain, Size: 2179 bytes --]
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: <https://lists.gnu.org/archive/html/emacs-orgmode/2022-06/msg00230.html>
Thanks,
Mikhail Skorzhinskii
Ihor Radchenko <yantar92@gmail.com> writes:
> Mikhail Skorzhinskii <mskorzhinskiy@eml.cc> 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
> <https://orgmode.org/worg/org-contribute.html#copyright>
>
> Best,
> Ihor
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-30 16:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-25 15:23 [PATCH] org-refile.el: show refile targets with doc. title Mikhail Skorzhinskii
2021-12-26 13:59 ` Ihor Radchenko
2021-12-28 11:59 ` Mikhail Skorzhinskii
2022-05-28 2:33 ` Ihor Radchenko
2022-08-30 13:53 ` Mikhail Skorzhisnkii
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).