~protesilaos/denote

7 2

Making denote-rename-file honor denote-prompts

Details
Message ID
<166521684647.7.5483179875879361874.67576870@aboulafia.org>
DKIM signature
missing
Download raw message
Hi Prot!

Thank you very much for your awesome Denote package, and for the clever
file-naming scheme.

I try to use this scheme for PDF file as well, and following the advice
of the manual, I heavily used denote-rename-file.

However, I noticed that this function didn't follow denote-prompts user
option, by design I think. 

For example, I'd like to create my own interactive function, asking for
the date as well (as the date of the last modification or of the
creation of the file isn't accurate enough):

(defun my/denote-rename-file ()
    (interactive)
    (let ((denote-prompts '(title keywords date)))
      (call-interactively 'denote-rename-file)))

What do you think of the idea of making denote-rename-file be affected
by denote-prompts?

Cheers,
-- 
Florian
Details
Message ID
<87zge6wsk1.fsf@protesilaos.com>
In-Reply-To
<166521684647.7.5483179875879361874.67576870@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Sat,  8 Oct 2022 08:14:01 +0000
>
> Hi Prot!

Hello Florian!

> Thank you very much for your awesome Denote package, and for the clever
> file-naming scheme.

You are welcome!

> I try to use this scheme for PDF file as well, and following the advice
> of the manual, I heavily used denote-rename-file.
>
> However, I noticed that this function didn't follow denote-prompts user
> option, by design I think. 

Indeed.  It always asks for a title and keywords.  The idea here is that
the 'denote-prompts' are not always relevant:

1. The renaming always happens in-place.  There is no switching between
   directories.  So the subdirectories' prompt would not be applicable,
   even if enabled.

2. There is an option for a template prompt (per 'denote-templates').
   Again, this is not pertinent to the task of renaming.

3. Same idea for the prompt for a file type, as the renaming operation
   respects the underlying file type.

This means that only the date prompt is a useful addition in this
context.

> For example, I'd like to create my own interactive function, asking for
> the date as well (as the date of the last modification or of the
> creation of the file isn't accurate enough):
>
> (defun my/denote-rename-file ()
>     (interactive)
>     (let ((denote-prompts '(title keywords date)))
>       (call-interactively 'denote-rename-file)))
>
> What do you think of the idea of making denote-rename-file be affected
> by denote-prompts?

I think asking for a date is useful.  Given the multiple renaming
commands we have, this might require quite a few changes to work
uniformly.  Let me look into the specifics and I will get back to you
with my findings.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<166522542985.9.12365290529941922263.67590827@aboulafia.org>
In-Reply-To
<87zge6wsk1.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou wrote:
> 
> 
> Indeed.  It always asks for a title and keywords.  The idea here is
> that the 'denote-prompts' are not always relevant:
> 
> 1. [...] the subdirectories' prompt would not be applicable [...]
> 
> 2. [...] an option for a template prompt [...] is not pertinent to
> the task of renaming.
> 
> 3. Same idea for the prompt for a file type [...]
> 
> This means that only the date prompt is a useful addition in this
> context.

It makes sense! It didn't occur to me that other possible options of
`denote-prompts' were irrelevant, outside of `date'. You're totally
right.

> > What do you think of the idea of making denote-rename-file be
> > affected by denote-prompts?
> 
> I think asking for a date is useful.  Given the multiple renaming
> commands we have, this might require quite a few changes to work
> uniformly.  Let me look into the specifics and I will get back to you
> with my findings.

Thank you very much!

Regards,
-- 
Florian
Details
Message ID
<87pmf2sdjy.fsf@protesilaos.com>
In-Reply-To
<166522542985.9.12365290529941922263.67590827@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Sat,  8 Oct 2022 10:37:05 +0000
>
> Protesilaos Stavrou wrote:
>> 
>> 
>> Indeed.  It always asks for a title and keywords.  The idea here is
>> that the 'denote-prompts' are not always relevant:
>> 
>> 1. [...] the subdirectories' prompt would not be applicable [...]
>> 
>> 2. [...] an option for a template prompt [...] is not pertinent to
>> the task of renaming.
>> 
>> 3. Same idea for the prompt for a file type [...]
>> 
>> This means that only the date prompt is a useful addition in this
>> context.
>
> It makes sense! It didn't occur to me that other possible options of
> `denote-prompts' were irrelevant, outside of `date'. You're totally
> right.

Very well!  I just added an optional DATE argument to the command
'denote-rename-file'.  Excerpt from its documentation:

    If FILE has a Denote-compliant identifier, retain it while
    updating the TITLE and KEYWORDS fields of the file name.  Else
    create an identifier based on the following conditions:

    - If FILE does not have an identifier and optional DATE is
      non-nil (such as with a prefix argument), invoke the function
      `denote-prompt-for-date-return-id'.  It prompts for a date and
      uses it to derive the identifier.

    - If FILE does not have an identifier and optional DATE is
      nil (this is the case without a prefix argument), use the file
      attributes to determine the last modified date and format it as
      an identifier.

    - As a fallback, derive an identifier from the current time.

Can you try it?  Remember that we never touch existing identifiers,
otherwise that will definitely lead to broken links.  Hence the DATE
only works for files without an identifier.

For the sake of completeness, below are the commits that made this
possible.  Everything is also documented in the manual:


commit 2ac68a135b818aae35437d3d70d3fe6daf2757f1
Author: Protesilaos Stavrou <info@protesilaos.com>
Date:   Sat Oct 8 14:40:25 2022 +0300

    Implement denote-prompt-for-date-return-id

    This is a function that might prove useful elsewhere in denote.el or
    for users that want to extend Denote.

 README.org | 7 +++++++
 denote.el  | 6 ++++++
 2 files changed, 13 insertions(+)


commit 582f38c642ad6cc35ac93b082617e1f387e67caf
Author: Protesilaos Stavrou <info@protesilaos.com>
Date:   Sat Oct 8 14:55:42 2022 +0300

    Add optional DATE in function that returns identifier

 README.org | 24 ++++++++++++++++++++----
 denote.el  | 19 +++++++++++++++++--
 2 files changed, 37 insertions(+), 6 deletions(-)


commit 31e6bcb2ebbc718783feddd27f157711dcad624b
Author: Protesilaos Stavrou <info@protesilaos.com>
Date:   Sat Oct 8 15:21:40 2022 +0300

    Add optional DATE to denote-rename-file

    Thanks to Florian for suggesting the idea on the mailing list:
    <https://lists.sr.ht/~protesilaos/denote/%3C166521684647.7.5483179875879361874.67576870%40aboulafia.org%3E>.

    For the technicalities that enabled this change, see commits 2ac68a1,
    582f38c.

 README.org | 31 ++++++++++++++++++++++---------
 denote.el  | 23 +++++++++++++++++------
 2 files changed, 39 insertions(+), 15 deletions(-)


-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<166525097789.8.7630122932993258535.67669291@aboulafia.org>
In-Reply-To
<87pmf2sdjy.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Le samedi 08 octobre 2022 à 15:30 +0300, Protesilaos Stavrou -
info(a)protesilaos.com a écrit :
> Can you try it?  Remember that we never touch existing identifiers,
> otherwise that will definitely lead to broken links.  Hence the DATE
> only works for files without an identifier.

Thank you very much, I'll try it!

However, I slightly disagree with the assumption that touching existing
identifiers will lead to broken links, as it is only true for Denote
notes, and not for non-note files (e.g. PDF) which Denote will never
manage.

Of course, for non-note files, touching identifiers OR title OR keyword
will lead to broken links if you use Org links, as the filename will
change (and you can't use `denote:' links).

That's why, in my opinion, you could change the DATE for non-note files
with the same consequences as changing the title or keywords.

Regards,
-- 
Florian
Details
Message ID
<87czb1bour.fsf@protesilaos.com>
In-Reply-To
<166525097789.8.7630122932993258535.67669291@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Sat,  8 Oct 2022 17:42:55 +0000
>
> Le samedi 08 octobre 2022 à 15:30 +0300, Protesilaos Stavrou -
> info(a)protesilaos.com a écrit :
>> Can you try it?  Remember that we never touch existing identifiers,
>> otherwise that will definitely lead to broken links.  Hence the DATE
>> only works for files without an identifier.
>
> Thank you very much, I'll try it!

You are welcome!

> However, I slightly disagree with the assumption that touching existing
> identifiers will lead to broken links, as it is only true for Denote
> notes, and not for non-note files (e.g. PDF) which Denote will never
> manage.
>
> Of course, for non-note files, touching identifiers OR title OR keyword
> will lead to broken links if you use Org links, as the filename will
> change (and you can't use `denote:' links).
>
> That's why, in my opinion, you could change the DATE for non-note files
> with the same consequences as changing the title or keywords.

It is possible to link to non-note files though.  Perhaps we should
reconsider this approach, but we need to think about the consequences.

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<166541553534.6.13577775458645460041.67997221@aboulafia.org>
In-Reply-To
<87czb1bour.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Protesilaos Stavrou - info(a)protesilaos.com wrote:
> > > Can you try it?  Remember that we never touch existing
> > > identifiers,
> > > otherwise that will definitely lead to broken links.  Hence the
> > > DATE only works for files without an identifier.
> > 
> > Thank you very much, I'll try it!
> 
> You are welcome!

Hi Prot,

I tried the new version of denote-rename-file function (which accepts
universal argument), and it works perfectly, thanks!

Reading your code, I learnt some tricks about interactive calls and
universal argument, I'm glad I read your commits.

> > That's why, in my opinion, you could change the DATE for non-note
> > files with the same consequences as changing the title or keywords.
> 
> It is possible to link to non-note files though.  Perhaps we should
> reconsider this approach, but we need to think about the
> consequences.

I wasn't aware that `denote:' links worked for non-note files. Sorry
about that!

Cheers,
-- 
Florian
Details
Message ID
<87k057bort.fsf@protesilaos.com>
In-Reply-To
<166541553534.6.13577775458645460041.67997221@aboulafia.org> (view parent)
DKIM signature
missing
Download raw message
> From: florian.denote@aboulafia.org
> Date: Mon, 10 Oct 2022 15:25:28 +0000
>
> Protesilaos Stavrou - info(a)protesilaos.com wrote:
>> > > Can you try it?  Remember that we never touch existing
>> > > identifiers,
>> > > otherwise that will definitely lead to broken links.  Hence the
>> > > DATE only works for files without an identifier.
>> > 
>> > Thank you very much, I'll try it!
>> 
>> You are welcome!
>
> Hi Prot,

Hello Florian,

> I tried the new version of denote-rename-file function (which accepts
> universal argument), and it works perfectly, thanks!

Very well!

> Reading your code, I learnt some tricks about interactive calls and
> universal argument, I'm glad I read your commits.

I think the Denote code is fairly accessible in this way.  Most
functions are small and have a documentation string which should, at the
very least, provide an idea of their intended functionality.

Even commands such as 'denote-rename-file', which are a bit harder in
terms of code, have detailed documentation which helps makes things more
approachable.

And if something is unclear, you are welcome to ask me about it.

>> > That's why, in my opinion, you could change the DATE for non-note
>> > files with the same consequences as changing the title or keywords.
>> 
>> It is possible to link to non-note files though.  Perhaps we should
>> reconsider this approach, but we need to think about the
>> consequences.
>
> I wasn't aware that `denote:' links worked for non-note files. Sorry
> about that!

No need to be sorry: you did nothing wrong.  If you need to edit an
existing identifier, you will have to do it manually.

I think this approach saves us from unnecessary trouble and code
complexity.  It also is a "social contract" we have with users: we will
not break identifiers.  They can trust that those will work.

All the best,
Prot

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