~protesilaos/denote

16 2

patch to create journal entries on a different date

Details
Message ID
<m2h6m9ze97.fsf@m4x.org>
DKIM signature
missing
Download raw message
Hello,

Here is a small patch to add an optional time argument to create journal
entries, so that one may create them on dates other than today. I often
write notes in a paper notebook, and this is useful for me to later add
them as journal entries.
Details
Message ID
<m2edhdzc3n.fsf@m4x.org>
In-Reply-To
<m2h6m9ze97.fsf@m4x.org> (view parent)
DKIM signature
missing
Download raw message
Hello,

On 2023-10-29 15:37, alan.schmitt@polytechnique.org writes:

> Here is a small patch to add an optional time argument to create journal
> entries, so that one may create them on dates other than today. I often
> write notes in a paper notebook, and this is useful for me to later add
> them as journal entries.

As a follow-up, there is another feature I use quite a bit with my
journal entries, it’s linking to them (creating them if necessary). Is
it something that could be added to denote-journal-extras, or should I
simply code it in my config? If the latter, making
`denote-journal-extras--entry-today` public would be very useful.

Best,

Alan
Details
Message ID
<87cywsd60q.fsf@protesilaos.com>
In-Reply-To
<m2h6m9ze97.fsf@m4x.org> (view parent)
DKIM signature
missing
Download raw message
> From: alan.schmitt@polytechnique.org
> Date: Sun, 29 Oct 2023 15:37:08 +0100
>
> Hello,

Hello Alan,

> Here is a small patch to add an optional time argument to create journal
> entries, so that one may create them on dates other than today. I often
> write notes in a paper notebook, and this is useful for me to later add
> them as journal entries.

This is a good idea! We have the 'denote-date-prompt' that we can use here.

> [... 39 lines elided]

>  ;;;###autoload
> -(defun denote-journal-extras-new-entry ()
> +(defun denote-journal-extras-new-entry (&optional time)
>    "Create a new journal entry in variable `denote-journal-extras-directory'.
>  Use `denote-journal-extras-keyword' as a keyword for the newly
> -created file."
> +created file. Use TIME if specified, or the current time otherwise."
>    (interactive)
>    (let ((denote-user-enforced-denote-directory (denote-journal-extras-directory)))
>      (denote
> -     (denote-journal-extras-daily--title-format)
> +     (denote-journal-extras-daily--title-format time)
>       `(,denote-journal-extras-keyword)
>       nil nil nil
>       (denote-journal-extras--get-template))
>      (run-hooks 'denote-journal-extras-hook)))

Note here that the TIME argument is not available interactively. We
should have it in that scenario, since this is an interactive function.

Here is a proof of concept:

    (defun test (&optional date)
      "Do stuff.
    With optional DATE as a prefix argument, call
    `denote-date-prompt' and used to record a journal entry for the
    given day.  Also see `denote-date-prompt-use-org-read-date'.

    When called from Lisp, DATE is a string as explained in the
    documentation of the `denote' command."
      (interactive
       (when current-prefix-arg
         (list (denote-date-prompt))))
      (message "%s" date))
      
> [... 12 lines elided]

>  ;;;###autoload
> -(defun denote-journal-extras-new-or-existing-entry ()
> +(defun denote-journal-extras-new-or-existing-entry (&optional time)
>    "Locate an existing journal entry or create a new one.
>  A journal entry is one that has `denote-journal-extras-keyword' as
>  part of its file name.
> +Use TIME if specified, or the current time otherwise.
>  
> -If there are multiple journal entries for the current date,
> +If there are multiple journal entries for the current or given date,
>  prompt for one using minibuffer completion.  If there is only
>  one, visit it outright.  If there is no journal entry, create one
>  by calling `denote-journal-extra-new-entry'."
>    (interactive)
> -  (let ((files (denote-journal-extras--entry-today)))
> +  (let ((files (denote-journal-extras--entry-today time)))
>      (cond
>       ((length> files 1)
>        (find-file (completing-read "Select journal entry: " files nil :require-match)))
>       (files
>        (find-file (car files)))
>       (t
> -      (call-interactively 'denote-journal-extras-new-entry)))))
> +      (denote-journal-extras-new-entry time)))))
>  
>  (provide 'denote-journal-extras)
>  ;;; denote-journal-extras.el ends here

Same as above for the 'interactive' spec.

Please let me know if you need me to tweak things further.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<87a5rwd5q9.fsf@protesilaos.com>
In-Reply-To
<m2edhdzc3n.fsf@m4x.org> (view parent)
DKIM signature
missing
Download raw message
> From: Alan Schmitt <alan.schmitt@polytechnique.org>
> Date: Sun, 29 Oct 2023 16:23:40 +0100
>
> Hello,

Hi Alan,

> On 2023-10-29 15:37, alan.schmitt@polytechnique.org writes:
>
>> Here is a small patch to add an optional time argument to create journal
>> entries, so that one may create them on dates other than today. I often
>> write notes in a paper notebook, and this is useful for me to later add
>> them as journal entries.
>
> As a follow-up, there is another feature I use quite a bit with my
> journal entries, it’s linking to them (creating them if necessary). Is
> it something that could be added to denote-journal-extras, or should I
> simply code it in my config? If the latter, making
> `denote-journal-extras--entry-today` public would be very useful.

We can in principle do that. For the linking, it would make sense to
limit the file selection prompt to only journal entries. Check how I did
it with the 'denote-link-with-signature'.

The "link and create if necessary" is another interesting option. We do
that already, so it is a matter of adapting what we have.

That granted, I am also fine if we just make a function public and
document how to get the rest. Though since we have already added such
functionality elsewhere, it now feels arbitrary to not complete the set.

I can write the code in the coming days. I have not been as active this
week due to an arm injury. Already typing this is hard, but I don't want
to leave too many issues to accumulate.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<m2jzr010j4.fsf@m4x.org>
In-Reply-To
<87cywsd60q.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello Prot,

On 2023-11-02 08:27, Protesilaos Stavrou <info@protesilaos.com> writes:

> Note here that the TIME argument is not available interactively. We
> should have it in that scenario, since this is an interactive function.
>
> Here is a proof of concept:

Thank you very much for this, here is a new patch.
Details
Message ID
<m2h6m410bj.fsf@m4x.org>
In-Reply-To
<87a5rwd5q9.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello Prot,

On 2023-11-02 08:33, Protesilaos Stavrou <info@protesilaos.com> writes:

> I can write the code in the coming days. I have not been as active this
> week due to an arm injury. Already typing this is hard, but I don't want
> to leave too many issues to accumulate.

I will look at it. Please take the time to heal.

Best,

Alan
Details
Message ID
<87lebf76ux.fsf@protesilaos.com>
In-Reply-To
<87cywsd60q.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Thu,  2 Nov 2023 08:27:17 +0200

> [... 84 lines elided]

> Please let me know if you need me to tweak things further.

Hello again Alan,

I just pushed commit 0f13f0f which implements this feature. I noticed
that it would require quite a few changes so I went ahead and did it
myself while I had time.

Please let me know if it works for you.

Have a nice day,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<m2zfzvuuqw.fsf@m4x.org>
In-Reply-To
<87lebf76ux.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello Prot,

On 2023-11-03 07:17, Protesilaos Stavrou <info@protesilaos.com> writes:

> I just pushed commit 0f13f0f which implements this feature. I noticed
> that it would require quite a few changes so I went ahead and did it
> myself while I had time.
>
> Please let me know if it works for you.

Thanks a lot. I did some quick testing and everything seems to work.

Best,

Alan
Details
Message ID
<m2wmuzup66.fsf@m4x.org>
In-Reply-To
<87a5rwd5q9.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello Prot,

On 2023-11-02 08:33, Protesilaos Stavrou <info@protesilaos.com> writes:

>> As a follow-up, there is another feature I use quite a bit with my
>> journal entries, it’s linking to them (creating them if necessary). Is
>> it something that could be added to denote-journal-extras, or should I
>> simply code it in my config? If the latter, making
>> `denote-journal-extras--entry-today` public would be very useful.
>
> We can in principle do that. For the linking, it would make sense to
> limit the file selection prompt to only journal entries. Check how I did
> it with the 'denote-link-with-signature'.

Here is a patch that links to a journal entry, creating it if necessary.
Details
Message ID
<87a5rq83jc.fsf@protesilaos.com>
In-Reply-To
<m2wmuzup66.fsf@m4x.org> (view parent)
DKIM signature
missing
Download raw message
> From: Alan Schmitt <alan.schmitt@polytechnique.org>
> Date: Fri,  3 Nov 2023 11:06:09 +0100
>
> Hello Prot,

Hello Alan,

> On 2023-11-02 08:33, Protesilaos Stavrou <info@protesilaos.com> writes:
>
>>> As a follow-up, there is another feature I use quite a bit with my
>>> journal entries, it’s linking to them (creating them if necessary). Is
>>> it something that could be added to denote-journal-extras, or should I
>>> simply code it in my config? If the latter, making
>>> `denote-journal-extras--entry-today` public would be very useful.
>>
>> We can in principle do that. For the linking, it would make sense to
>> limit the file selection prompt to only journal entries. Check how I did
>> it with the 'denote-link-with-signature'.
>
> Here is a patch that links to a journal entry, creating it if necessary.

Thank you! I don't have time to test right now. I just want to let you
know I have seen this and will check it out as soon as possible.
Hopefully later today. Will then merge it. After this we are ready for
Denote version 2.1.0.

More to follow!
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<874jhwss66.fsf@protesilaos.com>
In-Reply-To
<87a5rq83jc.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
> From: Protesilaos Stavrou <info@protesilaos.com>
> Date: Tue,  7 Nov 2023 08:45:43 +0200

> [... 20 lines elided]

>> Here is a patch that links to a journal entry, creating it if necessary.
>
> Thank you! I don't have time to test right now. I just want to let you
> know I have seen this and will check it out as soon as possible.
> Hopefully later today. Will then merge it. After this we are ready for
> Denote version 2.1.0.
>
> More to follow!

Hello again Alan,

I took a look at the patch. A couple of notes:

1. The 'interactive' spec needs to account for both prefix arguments:

    (interactive
     (pcase current-prefix-arg
       ('(16) (list (denote-date-prompt) :id-only))
       ('(4) (list (denote-date-prompt)))))

2. The above is relevant if we keep the code as-is. Though I wonder
   about the ergonomics of this command. My expectation was for it to
   prompt for a journal file and create it if missing. Here we have to
   consider what happens at the "or create" phase. We need to consult
   the 'denote-journal-extras-title-format' to check if the user wants
   to be prompted for a title. Otherwise create a new entry for the
   given date. This raises a problem about the "given date" part,
   because we have the DATE argument as well...

   My impression is that we need to review how this command should work.
   I am not sure, so just thinking out loud here:

   - Prompt for a date. If a journal entry exists, link to it. If not,
     create it. If many exist, ask for one among them and link to it.

   - If 'denote-journal-extras-title-format' is configured to accept an
     arbitrary string, then prompt for a date and do the filtering as
     above but ask for a title when a new note has to be created and
     linked to.
   
   - Anything else?

To avoid potential problems, I suggest we do this work after I release
Denote version 2.1.0. I hope to do it this week.

What do you think?

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<m2edh0ppsc.fsf@mac-03220211.irisa.fr>
In-Reply-To
<874jhwss66.fsf@protesilaos.com> (view parent)
DKIM signature
missing
Download raw message
Hello Prot,

On 2023-11-08 07:57, Protesilaos Stavrou <info@protesilaos.com> writes:

> I took a look at the patch. A couple of notes:
>
> 1. The 'interactive' spec needs to account for both prefix arguments:
>
>     (interactive
>      (pcase current-prefix-arg
>        ('(16) (list (denote-date-prompt) :id-only))
>        ('(4) (list (denote-date-prompt)))))

Ah, yes. I’m really not used to interactive specifications…

> 2. The above is relevant if we keep the code as-is. Though I wonder
>    about the ergonomics of this command. My expectation was for it to
>    prompt for a journal file and create it if missing. Here we have to
>    consider what happens at the "or create" phase. We need to consult
>    the 'denote-journal-extras-title-format' to check if the user wants
>    to be prompted for a title. Otherwise create a new entry for the
>    given date. This raises a problem about the "given date" part,
>    because we have the DATE argument as well...
>
>    My impression is that we need to review how this command should work.
>    I am not sure, so just thinking out loud here:
>
>    - Prompt for a date. If a journal entry exists, link to it. If not,
>      create it. If many exist, ask for one among them and link to it.
>
>    - If 'denote-journal-extras-title-format' is configured to accept an
>      arbitrary string, then prompt for a date and do the filtering as
>      above but ask for a title when a new note has to be created and
>      linked to.
>    
>    - Anything else?

What I mean to achieve is the following:
- link to a journal entry if there is one (choosing one if need be)
- otherwise, behave as if `denote-journal-extras-new-entry' was called
  and link to the created entry.

In particular, this means that the user may be prompted for a title if
`denote-journal-extras-title-format' is set accordingly, and templates
may be used.

I thought this is what the patch I proposed did, but I still have a lot
of emacs-lisp to learn.

> To avoid potential problems, I suggest we do this work after I release
> Denote version 2.1.0. I hope to do it this week.
>
> What do you think?

Yes, this is fine with me, there is no hurry.

Best,

Alan
Details
Message ID
<m2sf2ojr71.fsf@mac-03220211.irisa.fr>
In-Reply-To
<874jhwss66.fsf@protesilaos.com> (view parent)
DKIM signature
pass
Download raw message
Hello,

On 2023-11-08 07:57, Protesilaos Stavrou <info@protesilaos.com> writes:

> To avoid potential problems, I suggest we do this work after I release
> Denote version 2.1.0. I hope to do it this week.

Should we resume the discussion here, or do you prefer I submit a patch
on github?

(I just noticed the repository on sr.ht is not up to date. Is it
deprecated?)

Best,

Alan
Details
Message ID
<87fryol5en.fsf@protesilaos.com>
In-Reply-To
<m2sf2ojr71.fsf@mac-03220211.irisa.fr> (view parent)
DKIM signature
pass
Download raw message
> From: Alan Schmitt <alan.schmitt@polytechnique.org>
> Date: Tue, 23 Jan 2024 11:10:26 +0100
>
> Hello,

Hello Alan,

> On 2023-11-08 07:57, Protesilaos Stavrou <info@protesilaos.com> writes:
>
>> To avoid potential problems, I suggest we do this work after I release
>> Denote version 2.1.0. I hope to do it this week.
>
> Should we resume the discussion here, or do you prefer I submit a patch
> on github?

Yes, let's resume it there.

> (I just noticed the repository on sr.ht is not up to date. Is it
> deprecated?)

Yes. My plan is to move away from SourceHut because I have some issues
with it. I have not made the announcement yet.

Have a nice day,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<m2fryjgpao.fsf@m4x.org>
In-Reply-To
<87fryol5en.fsf@protesilaos.com> (view parent)
DKIM signature
pass
Download raw message
Hello Prot,

On 2024-01-23 12:18, Protesilaos Stavrou <info@protesilaos.com> writes:

>> Should we resume the discussion here, or do you prefer I submit a patch
>> on github?
>
> Yes, let's resume it there.

Here is the proposed code for a function that links to a journal entry,
creating it if necessary. It is a mix of
`denote-journal-extras-new-or-existing-entry' and
`denote-link-or-create'.


(defun denote-journal-extras-link-or-create-entry (&optional date id-only)
  "Use `denote-link' on journal entry, creating it if necessary.
A journal entry is one that has `denote-journal-extras-keyword' as
part of its file name.

If there are multiple journal entries for the current date,
prompt for one using minibuffer completion.  If there is only
one, link to it outright.  If there is no journal entry, create one
by calling `denote-journal-extra-new-entry' and link to it.

With optional DATE as a prefix argument, prompt for a date.  If
`denote-date-prompt-use-org-read-date' is non-nil, use the Org
date selection module.

When called from Lisp, DATE is a string and has the same format
as that covered in the documentation of the `denote' function.
It is internally processed by `denote-journal-extras--get-date'.

With optional ID-ONLY as a prefix argument create a link that
consists of just the identifier.  Else try to also include the
file's title.  This has the same meaning as in `denote-link'."
  (interactive
   (pcase current-prefix-arg
     ('(16) (list (denote-date-prompt) :id-only))
     ('(4) (list (denote-date-prompt)))))
  (let* ((internal-date (denote-journal-extras--get-date date))
         (files (denote-journal-extras--entry-today internal-date))
         (path))
    (cond
     ((length> files 1)
      (setq path (completing-read "Select journal entry: " files nil :require-match)))
     (files
      (setq path (car files)))
     (t
      (save-window-excursion
        (denote-journal-extras-new-entry date)
        (save-buffer)
        (setq path (buffer-file-name)))))
    (denote-link path
                 (denote-filetype-heuristics (buffer-file-name))
                 (denote--link-get-description path)
                 id-only)))

> Yes. My plan is to move away from SourceHut because I have some issues
> with it. I have not made the announcement yet.

Do you plan to stop using the mailing list as well?

Best,

Alan
Details
Message ID
<87plxm6l9l.fsf@protesilaos.com>
In-Reply-To
<m2fryjgpao.fsf@m4x.org> (view parent)
DKIM signature
pass
Download raw message
> From: Alan Schmitt <alan.schmitt@polytechnique.org>
> Date: Sat, 27 Jan 2024 09:21:03 +0100
>
> Hello Prot,

Hello Alan,

> On 2024-01-23 12:18, Protesilaos Stavrou <info@protesilaos.com> writes:
>
>>> Should we resume the discussion here, or do you prefer I submit a patch
>>> on github?
>>
>> Yes, let's resume it there.
>
> Here is the proposed code for a function that links to a journal entry,
> creating it if necessary. It is a mix of
> `denote-journal-extras-new-or-existing-entry' and
> `denote-link-or-create'.

Thank you! Do you want to send this on GitHub so that we can have
everything there? This is in light of my latest announcement:
<https://protesilaos.com/codelog/2024-01-27-sourcehut-no-more/>.

All the best,
Prot

-- 
Protesilaos Stavrou
https://protesilaos.com
Details
Message ID
<m2cytlhh60.fsf@m4x.org>
In-Reply-To
<87plxm6l9l.fsf@protesilaos.com> (view parent)
DKIM signature
pass
Download raw message
On 2024-01-28 08:10, Protesilaos Stavrou <info@protesilaos.com> writes:

> Thank you! Do you want to send this on GitHub so that we can have
> everything there? This is in light of my latest announcement:
> <https://protesilaos.com/codelog/2024-01-27-sourcehut-no-more/>.

Done: https://github.com/protesilaos/denote/issues/234

Best,

Alan
Reply to thread Export thread (mbox)