Make sure org-roam-node-from-title-or-alias won't mess up with the match-data #1766
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It lies in between org-in-regexp and replace-match. In some situations, like
when the link looks like roam:a s'b, it changes the match-data.
Motivation for this change
Get file file test.txt
It is an elisp file, but github won't allow the extension .el...
It
[[roam:a s'b]]
org-roam-link-replace-all
This simulates the behavior when you create a note and use the completion mecanism to add a link to another note.
Run this with emacs -Q --load test.txt, you will get the following error
org-roam-link-replace-at-point: Args out of range: 0, 0
Try removing the "'" character, so that the first file has the title "a sb" and the roam link is now
[[roam:a sb]]
. Now the test works.Digging a little bit, I found out that, when the title is "a s'b"
org-roam-link-replace-at-point
callsorg-roam-node-from-title-or-alias
org-roam-node-from-title-or-alias
callsorg-roam-db-query
org-roam-db-query
callsemacsql
andorg-roam-db
emacsql
andorg-roam-db
change the match-dataI did not look further. May be some other place of the code changes the match-data.
But I can tell that nesting
org-roam-link-replace-at-point
insidesave-match-data
fixes the issue.Moreover, I guess it is a good practice to ensure that the code between anything that sets the match data (
org-in-regexp
in this example) and anything that relies on this match-data (replace-match
in this example) does not change the match-data.