protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme

Home Page:https://protesilaos.com/emacs/denote

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

update the link description if the target title is changed

jarofromel opened this issue · comments

Hello,

Usecase:

  • I created the meta note which contains links to other denote files. The links are in the format [[denote:20230330T150916][Target original titlel]]
  • then I rename the title to Target more precise title and I would like to automatize the renaming of the link in the meta note, e.g. to have [[denote:20230330T150916][Target more precise titlel]] by running some renaming command.

I have went though the doc for 2.3 and didn't find such a command.
I think I can do it by combining functionalities of denote--link-get-description and org-dblock-update.
Is that true or is there is better way, please? (sorry for such a question, the speed of the denote development is quite impressive and I am not definitely up-to-date with it current state). Thanks a lot for the package.

Postmortem I see the Discussions are enabled now. This is the question and fits better there.

I am fine with using the issue tracker for this. Better have everything in one place. I do not know what is a "discussion" that couldn't also be an issue, so better keep it simple.

To the point, we do not provide such a facility because the change would have to be applied across all files. Then you have practical problems:

  • What if the text of the link was not the file title to be begin with?
  • If the renaming does not affect the TITLE, but works with the KEYWORDS or SIGNATURE, then we must account for this to not update the links. But links with a SIGNATURE can be different (e.g. denote-link-with-signature). What to do in this case?
  • Does the user auto-fill their paragraphs and is the new title breaking this?
  • Do we want to prompt for a change per file, for all files at once, or no prompts at all?
  • Should the affected buffers be saved or left there for further inspection?
  • Is this feature subject to a user option?

I personally like my links to be the way they were originally written, because this preserves the history of the file and shows that the text was true at that time. Though I can see the value of what you are suggesting.

Protesilaos is right. We cannot know what the link descriptions are.

Another example that illustrates your point is denote-region where the link description is the content of the region. I expect this kind of links to be quite common. It would not be desirable to update link descriptions across all files. I would lose valuable data and my notes would look weird if a link in the middle of a sentence such as this one is changed to another string automatically.

I think we could eventually provide a command to rewrite links automatically, but we must be careful. I am also not sure that we currently have what it takes in denote-file-types to find those links reliably accross all files according to each supported file extensions. The regexps are not immediately usable for this task.

Maybe it is better to keep this idea in mind for now.

Thanks for answers. Based on your input I can be more specific in my original needs.

  1. Having the cursor in the link I'd like to update its description with the command (which returns the title of the target). If I am happy with the result I can save the file.
  2. Being in the buffer I'd like to update all its link descriptions with the command. If I am happy with the result I can save the file.

I can solve the 1) with the following code. It is very simple and does not cover all the corners mentioned by @protesilaos .

(defun my-update-denote-link ()
  (interactive)
  (my-org-update-link-description
   (denote-retrieve-filename-title
    (denote-link--ol-resolve-link-to-target
     (org-element-property :path (org-element-context))))))

I reused my-org-update-link-description from here Sacha Chua's Emacs configuration

(defun my-org-update-link-description (description)
  "Update the current link's DESCRIPTION."
  (interactive "MDescription: ")
  (let (link)
    (save-excursion
      (cond
       ((org-in-regexp org-link-bracket-re 1)
        (setq link (org-link-unescape (match-string-no-properties 1)))
        (delete-region (match-beginning 0) (match-end 0))
        (insert (org-link-make-string link description))
        (sit-for 0))
       ((or (org-in-regexp org-link-angle-re)
            (org-in-regexp org-link-plain-re))
        (setq link (org-unbracket-string "<" ">" (match-string 0)))
        (delete-region (match-beginning 0) (match-end 0))
        (insert (org-link-make-string link description))
        (sit-for 0))))))

@jarofromel Good to know! If there is a way to cover all cases, I am happy to consider it. But we cannot do this only for some cases because it will create other problems for us.

I say we do not work on this. There will be sharp edges to it. Also, we do not have a precedent for this in, say, Org, meaning that we would be moving outside the scope of what we ordinarily do. Thank you!