Kinneyzhang / gkroam

A lightweight roam replica on top of emacs org-mode.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gkroam-link-with-headline-re may match incorrectly

Whil- opened this issue · comments

With the following example text:

A {[Link1]} and another {[Link2 » With Heading]} exist on the same line

gkroam-link-with-headline-re doesn't know better than to match the first part with Link1]} and another {[Link2 while the correct match should be Link2

Thanks for figuring out the bug. But I prefer this change:

(defvar gkroam-link-with-headline-re "{\\[\\(.+?\\) » \\(.+?\\)\\].*?}")

instead of doing 'traceback' in consideration of efficiency.

Hi @Kinneyzhang, while I agree that performance should be considered the fix you suggest doesn't actually fix the problem.

When the regexp parser is looking at the third character on the example line above (repeated here):

A {[Link1]} and another {[Link2 » With Heading]} exist on the same line

it will still match all the way to the ending brackets after the second link. Since the regexp doesn't know how to stop the match when encountering the end-brackets at the first link.

So unfortunately this is still a bug and the pull-request I sent will still fix it.

Looking through the source code it seems gkroam-search-all-headline-links suffers from the same issue. Although in that case it likely doesn't matter...

It seems that you have misunderstood the function of gkroam-cache-curr-headline-links. The purpose of the function is to put headline and headline id in caches, so it only need to match headline links.

As to the example:

A {[Link1]} and another {[Link2 » With Heading]} exist on the same line

the first link is a page link and the second one is a headline link.

I might have misunderstood, although I'm not so sure that's the case. What I'm pointing at is that the function never gets to parse the second link correctly, since it manages to find a match that spans both links (which is wrong) and thus will never parse the second link.

Please try to run the regexp search on the example line I added and see what happens. If you mean that it is okay for the function to end up with the first group in the regexp matched with Link1]} and another {[Link2, then I indeed misunderstood something.

And what is the content of the (match-string-no-properties 1) on your end? For me it's not only Link2.

Sorry, I see the problem. 😅