Auto-editing of links

I’ve noticed that sometimes when I type:


Sometimes it’ll automagically change it to:


which then gets rendered as just new-page. Edit: if it’s an existing node, the square-bracketed link that gets auto-created uses the existing node id like this: [[id:22b620d9-0480-4e89-a799-5b41324ec51b][my-existing-node]].

Other times, it leaves it unmolested as roam:new-page without the square brackets.

What’s going on there?

Edit: I should say I have org-roam-completion-everywhere set to nil. Also it seems that simply typing roam:somepage already gives me a link, and when I follow the link I get navigated to that page and the conversion to a square brackets link happens then. But sometimes after a period of time, the link has turned into a square-bracketed link without me doing anything obvious to make that happen – I don’t know how to reproduce that.

A couple of things are happening. You can inspect these lines in org-roam-node.el

roam:new-page becomes a link because L680:

org-link-set-parameters "roam" :follow #'org-roam-link-follow-link)

It is an Org mode feature that Org-roam leverages. It explains why roam: new-page is a link.

when I follow the link I get navigated to that page and the conversion to a square brackets link happens the

Look at the function 'org-roam-link-follow-link set and used by org-link-set-parameters above. The function is defined in L681 onward.

You will see the reason for the conversion:

        (when org-roam-link-auto-replace

org-roam-link-auto-replace is a customizing variable, so you can set it as you prefer; the default is t.

Also look at before-save-hook in a buffer visiting an Org-roam file. By default, you should see (org-roam-link-replace-all t) set. The same customizing variable org-roam-link-auto-replace is used here, too.

This is probably because you have some auto save feature turned on – e.g. auto-save-visited-mode, which auto-saves an unsaved buffer after a specific interval. It’s probably you have left a buffer unsaved, moved to some other one, timer kicks in to save the first buffer, and then before-save-hook kicks in to covert the roam: link to a bracket Org-ID one.

That’s most likely because the link target does not exist yet, thus no ID and no Org ID link to convert to.


Re the mysterious auto-edits that seem to happen when I’m not doing anything (specifically not the edits in response to following a link):

I’m 99.9% sure no auto-save is configured in my usual config, but perhaps this cropped up when running with vanilla spacemacs…

  • auto-save-visited-mode is nil in both my out-of-the-box spacemacs config and my usual spacemacs config
  • Nothing seems to be triggering an auto-save in either config if I wait a minute
  • org-roam-link-replace-all replaces square-bracketed links, but these links don’t have square brackets yet

Since I don’t know how to reproduce this and it seems to have stopped happening as mysteriously as it started, I’m going to leave it alone for now.

Thanks again