denote icon indicating copy to clipboard operation
denote copied to clipboard

Denote link with direct jump to an Org heading (plus `denote-org-extras.el`)

Open protesilaos opened this issue 1 year ago • 9 comments

I have some working code in the link-to-org-headings branch and I am interested in further comments on whether this is useful, how it can be expanded, etc.

Excerpt from the manual on what is on offer right now:

[ Part of {{{development-version}}}. ]

The user option ~denote-org-store-link-to-heading~ determines whether
~org-store-link~ links to the current Org heading.

When its value is non-nil, ~org-store-link~ stores a link to the
current Org heading inside the Denote file. If the heading does not
have a =CUSTOM_ID=, it creates it and includes it in the heading's
=PROPERTIES= drawer. If a =CUSTOM_ID= exists, ~org-store-link~ use it
as-is.

This make the resulting link a combination of the =denote:= link type,
pointing to the identifier of the current file, plus the value of the
heading's =CUSTOM_ID=, such as:

- =[[denote:20240118T060608][Some test]]=
- =[[denote:20240118T060608::#h:eed0fb8e-4cc7-478f-acb6-f0aa1a8bffcd][Some test]]=

Both lead to the same Denote file, but the latter jumps to the heading
with the given =CUSTOM_ID=.

The value of the =CUSTOM_ID= is determined by the Org user option
~org-id-method~. The sample shown above uses the default UUID
infrastructure.

If ~denote-org-store-link-to-heading~ is set to a nil value, the
command ~org-store-link~ only stores links to the Denote file (using
its identifier), but not to the given heading. This is what Denote was
doing in versions prior to =3.0.0=.

[ This feature only works in Org mode files, as other file types do
  not have a linking mechanism that handles unique identifiers for
  headings or other patterns to jump to. If ~org-store-link~ is
  invoked in one such file, it captures only the Denote identifier of
  the file, even if this user option is set to a non-nil value. ]"

protesilaos avatar Jan 18 '24 13:01 protesilaos

I have tested this and it works great! As I was not using this feature before, I don't know how it can be expanded. I think this is useful!

jeanphilippegg avatar Jan 20 '24 05:01 jeanphilippegg

Thank you @jeanphilippegg! I just merged it into main. Check the command denote-org-link-to-heading for an idea (part of denote-org.el for which I have several ideas).

The org-store-link now also captures the text of the heading when generating the description of the link.

protesilaos avatar Jan 20 '24 05:01 protesilaos

Ok, I will check this tomorrow!

jeanphilippegg avatar Jan 20 '24 05:01 jeanphilippegg

I have checked your code in denote-org-extras.el. These are good functionalities! Good job.

Here are some comments:

  • The command denote-org-extras-link-to-heading and denote-link-ol-store should retrieve the description part of the link description using denote--link-get-description instead of denote--retrieve-title-or-filename. This way, the description can be anything + the heading. This was developed in #222.

  • denote-org-extras-link-to-heading can be called in a yaml note and the link format is still with brackets. I don't know if it is desirable to have these links work in other file types. If not, maybe add a condition to prevent it from being called outside org files.

  • There are many functionalities related to org spread in denote.el, denote-org-dblock.el and denote-org-extras.el. Maybe we could move all of them into denote-org.el. This could include the sections "Register denote: custom Org hyperlink" and "Glue code for org-capture".

  • I get this warning everytime I restart Emacs: "Warning (defvaralias): Overwriting value of ‘denote--file-history’ by aliasing to ‘denote-file-history’".

I will not do pull requests related to this part of the code because it is in development, but if you want me to work on it, let me know!

jeanphilippegg avatar Jan 20 '24 15:01 jeanphilippegg

Hello @jeanphilippegg!

This way, the description can be anything + the heading. This was developed [...]

Okay, I missed that. I will check it now.

here are many functionalities related to org spread in [...]

I just made the change that absorbs the dynamic blocks into denote-org-extras.el. See commit edbc0e4. I was not sure how best to deprecate the feature denote-org-dblocks. I think what I did is backward-compatible.

About the Org functionality in denote.el, I think that should stay there. The idea is that all the "extras" files are optional for those who need the additional functionality. What is in denote.el is the basic infrastructure.

[...] maybe add a condition to prevent it from being called outside org files.

Error checking is done since commit e4fcef9.

I get this warning everytime I restart Emacs:

This is because those variables are now public (unrelated to denote-org-extras.el). The reason I made them public is because a user may want to change their value (e.g. M-x remove-hook). Do you keep getting these warnings? Maybe because of savehist-mode?

protesilaos avatar Jan 23 '24 05:01 protesilaos

Hello again @jeanphilippegg!

In the denote-org-extras.el we now have the code for the Org dynamic blocks. Note these warnings from some recent changes you made:

  288  18 warning  e-f-b-c  ‘denote-format-link’ called with 3 arguments, but requires 4
  295  25 warning  e-f-b-c  the function ‘denote--link-get-description-with-signature’ is not known to be defined.
  296  23 warning  e-f-b-c  ‘denote--link-get-description’ called with 2 arguments, but accepts only 1

Do you want to take a look or shall I edit it from here?

protesilaos avatar Jan 23 '24 08:01 protesilaos

same warning problem here.

Warning (defvaralias): Overwriting value of ‘denote-sort--component-hist’ by aliasing to ‘denote-sort-component-history’

It exists after I restart Emacs even I delete the save history file.

Jousimies avatar Jan 23 '24 12:01 Jousimies

I just made a change for the history variables. Hopefully we don't get any warnings now.

protesilaos avatar Jan 25 '24 04:01 protesilaos

Do you want to take a look or shall I edit it from here?

Sorry about that. I originally fixed it, but it got lost in the commits. This is fixed in pull request #231.

I just made a change for the history variables. Hopefully we don't get any warnings now.

I fixed denote--keyword-history as well in #231.

Have a good day!

jeanphilippegg avatar Jan 27 '24 03:01 jeanphilippegg

I think we are good with denote-org-extras.el for now. Other topics can be discussed in separate threads. Thank you!

protesilaos avatar Feb 05 '24 09:02 protesilaos