~protesilaos/denote

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
7 2

denote function doesn't sort keywords when called non-interactively

Details
Message ID
<166689879712.8.6808878344988686135.71824507@aboulafia.org>
DKIM signature
missing
Download raw message
Hi Prot, hope you're well!

I noticed that `denote' function doesn't sort keywords when called non-
interactively, even if `denote-sort-keywords' is set to t. In the code,
`denote-sort-keywords' is only used by `denote-keywords-prompt'
function, that's why keywords are sorted when `denote' is called
interactively, and unsorted when called non-interactively.

Is it on purpose?

Cheers,
-- 
Florian
Details
Message ID
<87czacy94f.fsf@protesilaos.com>
In-Reply-To
<166689879712.8.6808878344988686135.71824507@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Thu, 27 Oct 2022 19:26:35 +0000
>
> Hi Prot, hope you're well!

Hello Florian,

I am doing fine, thank you!

> I noticed that `denote' function doesn't sort keywords when called non-
> interactively, even if `denote-sort-keywords' is set to t. In the code,
> `denote-sort-keywords' is only used by `denote-keywords-prompt'
> function, that's why keywords are sorted when `denote' is called
> interactively, and unsorted when called non-interactively.
>
> Is it on purpose?

Good catch!  No, it was not on purpose.  I just made some changes.
Please test them and let me know if everything works as expected on your
end.

    commit a59a711f176723f87d0f3bff283e72b1f22bf4b5
    Author: Protesilaos Stavrou <info@protesilaos.com>
    Date:   Fri Oct 28 05:26:59 2022 +0300

        Add denote-keywords-sort function

        The intent is to abstract the task of sorting the keywords.  Before,
        it was handled by the 'denote-keywords-prompt', which meant that
        keywords were not sorted when the 'denote' function was called from
        Lisp.

        Thanks to Florian for bringing this matter to my attention:
        <https://lists.sr.ht/~protesilaos/denote/%3C166689879712.8.6808878344988686135.71824507%40aboulafia.org%3E>.

     README.org | 11 ++++++++++-
     denote.el  | 19 +++++++++++++------
     2 files changed, 23 insertions(+), 7 deletions(-)

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<166693939100.7.2697299917666868782.71911200@aboulafia.org>
In-Reply-To
<87czacy94f.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Le vendredi 28 octobre 2022 à 05:28 +0300, Protesilaos Stavrou -
info(a)protesilaos.com a écrit :
> Please test them and let me know if everything works as expected on
> your end.

Thanks!

There seems to be a little mistake (commit
a59a711f176723f87d0f3bff283e72b1f22bf4b5) :

- line 1389 : (kws (denote--keywords-sort keywords))
  denote--keywords-sort is undefined

- line 739 : its name is denote-keywords-sort instead

Cheers,
-- 
Florian
Details
Message ID
<87r0ysqwbi.fsf@protesilaos.com>
In-Reply-To
<166693939100.7.2697299917666868782.71911200@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Fri, 28 Oct 2022 06:43:07 +0000
>
> Le vendredi 28 octobre 2022 à 05:28 +0300, Protesilaos Stavrou -
> info(a)protesilaos.com a écrit :
>> Please test them and let me know if everything works as expected on
>> your end.
>
> Thanks!
>
> There seems to be a little mistake (commit
> a59a711f176723f87d0f3bff283e72b1f22bf4b5) :
>
> - line 1389 : (kws (denote--keywords-sort keywords))
>   denote--keywords-sort is undefined
>
> - line 739 : its name is denote-keywords-sort instead
>
> Cheers,

Oops!  I just pushed the change.  Thank you!

-- 
Protesilaos Stavrou
https://protesilaos.com

[PATCH] Re: denote function doesn't sort keywords when called non-interactively

Details
Message ID
<166738607395.7.4984032286065984949.73057415@aboulafia.org>
In-Reply-To
<87czacy94f.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou wrote :
> I just made some changes. Please test them and let me know if
> everything works as expected on yourend.

Hi Prot!

I noticed that denote-rename-file function didn't sort keywords as
well.

You'll find a trivial patch as an attachment to this email.

Cheers,
-- 
Florian

Re: [PATCH] Re: denote function doesn't sort keywords when called non-interactively

Details
Message ID
<87zgd97g7b.fsf@protesilaos.com>
In-Reply-To
<166738607395.7.4984032286065984949.73057415@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Wed,  2 Nov 2022 10:47:49 +0000
>
> Protesilaos Stavrou wrote :
>> I just made some changes. Please test them and let me know if
>> everything works as expected on yourend.
>
> Hi Prot!

Hello Florian!

> I noticed that denote-rename-file function didn't sort keywords as
> well.

Correct!

> You'll find a trivial patch as an attachment to this email.

> [... 26 lines elided]

I installed it.  Thank you!  I followed it up with commit bbd0b79 as the
same had to be done in a few other places.

I noticed that 'denote-keywords-add' and 'denote-keywords-remove' do not
sort keywords.  I need to investigate this further.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com

Re: [PATCH] Re: denote function doesn't sort keywords when called non-interactively

Details
Message ID
<166746941702.7.8302903706773121576.73287583@aboulafia.org>
In-Reply-To
<87zgd97g7b.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou - info(a)protesilaos.com wrote:
> I installed it.  Thank you!  I followed it up with commit bbd0b79 as
> the same had to be done in a few other places.

Thanks!

However I think you reverted my commit changes (877e2053) by your next
commit (bbd0b79):
https://git.sr.ht/~protesilaos/denote/commit/bbd0b79162eabf02d984a7c14841a13a9f9edf61#denote.el-2-4

Moreover, I think that every time we call denote-keywords-prompt, we
call denote-keywords-sort on the result. Maybe we could call denote-
keywords-sort into denote-keywords-prompt function?

Cheers,
-- 
Florian

Re: [PATCH] Re: denote function doesn't sort keywords when called non-interactively

Details
Message ID
<87o7tojqdw.fsf@protesilaos.com>
In-Reply-To
<166746941702.7.8302903706773121576.73287583@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
Patch: +9 -7
> From: florian.denote@aboulafia.org
> Date: Thu,  3 Nov 2022 09:56:51 +0000
>
> Protesilaos Stavrou - info(a)protesilaos.com wrote:
>> I installed it.  Thank you!  I followed it up with commit bbd0b79 as
>> the same had to be done in a few other places.
>
> Thanks!
>
> However I think you reverted my commit changes (877e2053) by your next
> commit (bbd0b79):
> https://git.sr.ht/~protesilaos/denote/commit/bbd0b79162eabf02d984a7c14841a13a9f9edf61#denote.el-2-4

Mea culpa!

> Moreover, I think that every time we call denote-keywords-prompt, we
> call denote-keywords-sort on the result. Maybe we could call denote-
> keywords-sort into denote-keywords-prompt function?

Yes, I noticed.  I was not sure how to deal with the case of the
'denote' command's interactive and non-interactive uses.  Though I found
'called-interactively-p', which seems to be what I was missing.

What do you think about the following diff?


  denote.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/denote.el b/denote.el
index b96cfb1..d951392 100644
--- a/denote.el
+++ b/denote.el
@@ -745,8 +745,8 @@ (defun denote-keywords-prompt ()
`crm-sepator', which typically is a comma.  In such a case, the
output is sorted with `string-lessp'.

To sort the return value, use `denote-keywords-sort'."
  (denote--keywords-crm (denote-keywords)))
Process the return value with `denote-keywords-sort'."
  (denote-keywords-sort (denote--keywords-crm (denote-keywords))))

(defun denote-keywords-sort (keywords)
  "Sort KEYWORDS if `denote-sort-keywords' is non-nil.
@@ -1478,7 +1478,9 @@ (defun denote (&optional title keywords file-type subdirectory date template)
     (append args nil)))
  (let* ((title (or title ""))
         (file-type (denote--valid-file-type (or file-type denote-file-type)))
         (kws (denote-keywords-sort keywords))
         (kws (if (called-interactively-p 'interactive)
                  keywords
                (denote-keywords-sort keywords)))
         (date (if (or (null date) (string-empty-p date))
                   (current-time)
                 (denote--valid-date date)))
@@ -1717,7 +1719,7 @@ (defun denote-keywords-add (keywords)

Rename the file without further prompt so that its name reflects
the new front matter, per `denote-rename-file-using-front-matter'."
  (interactive (list (denote-keywords-sort (denote-keywords-prompt))))
  (interactive (list (denote-keywords-prompt)))
  ;; A combination of if-let and let, as we need to take into account
  ;; the scenario in which there are no keywords yet.
  (if-let* ((file (buffer-file-name))
@@ -2075,7 +2077,7 @@ (defun denote-dired-rename-marked-files ()
  the user option `denote-file-type')."
  (interactive nil dired-mode)
  (if-let ((marks (dired-get-marked-files)))
      (let ((keywords (denote-keywords-sort (denote-keywords-prompt))))
      (let ((keywords (denote-keywords-prompt)))
        (when (yes-or-no-p "Add front matter or rewrite front matter of keywords (buffers are not saved)?")
          (progn
            (dolist (file marks)
@@ -2220,7 +2222,7 @@ (defun denote-add-front-matter (file title keywords)
   (list
    (buffer-file-name)
    (denote-title-prompt)
    (denote-keywords-sort (denote-keywords-prompt))))
    (denote-keywords-prompt)))
  (when (denote-file-is-writable-and-supported-p file)
    (denote--add-front-matter
     file title keywords
@@ -3121,7 +3123,7 @@ (defun denote-org-capture ()

Consult the manual for template samples."
  (let* ((title (denote-title-prompt))
         (keywords (denote-keywords-sort (denote-keywords-prompt)))
         (keywords (denote-keywords-prompt))
         (front-matter (denote--format-front-matter
                        title (denote--date nil 'org) keywords
                        (format-time-string denote-id-format nil) 'org)))


-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)