toshism / org-super-links

Package to create links with auto backlinks
GNU General Public License v3.0
285 stars 20 forks source link

command sl-create-new-target insert the original link #50

Closed jinboowu closed 3 years ago

jinboowu commented 3 years ago

The command meant to create a new heading and link to the original headline.

But it always insert the original headline itself link

but sometimes it works, do not know how to solve the issue, it seems the function " sl-related-to-last-capture" has some problems My working environment: windows 10 operation system, spacemacs

MY config:

(use-package org-super-links :bind (("C-c s s" . sl-link) ("C-c s l" . sl-store-link) ("C-c s C-l" . sl-insert-link)))

(require 'org-id) (setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)

(defun sl-create-new-target () (interactive) (add-hook 'org-capture-after-finalize-hook 'sl-related-to-last-capture) (org-capture))

(defun sl-related-to-last-capture () (interactive) (sl--insert-link org-capture-last-stored-marker) (remove-hook 'org-capture-after-finalize-hook 'sl-related-to-last-capture))

(spacemacs/set-leader-keys-for-major-mode 'org-mode "gi" 'sl-create-new-target)

toshism commented 3 years ago

@jinboowu did you manage to get this fixed?

jinboowu commented 3 years ago

yes, it was some config issue on my side.

获取 Outlook for Androidhttps://aka.ms/ghei36


From: Tosh Lyons notifications@github.com Sent: Wednesday, December 23, 2020 6:25:59 PM To: toshism/org-super-links org-super-links@noreply.github.com Cc: jinboowu wgz.grant@outlook.com; Mention mention@noreply.github.com Subject: Re: [toshism/org-super-links] command sl-create-new-target insert the original link (#50)

@jinboowuhttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjinboowu&data=04%7C01%7C%7C4aa5e077ae70405fbde408d8a72d24c4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637443159625892712%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5gXCTGWIcRtUMQjpV%2BwHZTU%2F4oaflUKSCjbAFgwUjxE%3D&reserved=0 did you manage to get this fixed?

― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftoshism%2Forg-super-links%2Fissues%2F50%23issuecomment-750099724&data=04%7C01%7C%7C4aa5e077ae70405fbde408d8a72d24c4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637443159625902708%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=coJJkOaZpSvvPYDdDFkq%2BZhduKIlBLXhWrW05MMfGaE%3D&reserved=0, or unsubscribehttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAIBXRHNG4FUAMSAFW7RLJ6LSWHATPANCNFSM4VARUZXA&data=04%7C01%7C%7C4aa5e077ae70405fbde408d8a72d24c4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637443159625902708%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=NBitfQvD8Xp%2FIHmS%2FtWBETNdWqitBH7eY3fZg1Q9BrQ%3D&reserved=0.

jinboowu commented 3 years ago

I found the function "sl-related-to-last-capture" may have some lag issue,

For example, I just captured headline a, Then i capture headline b, during the capturing process, I want to use this command to link the "headline a" and "headline b", Sometimes I will found that the link I inserted was pointed to "headline c" which I created before the "headline a".

It happens randomly, and I do not know the cause and how to resolve it.

toshism commented 3 years ago

@jinboowu could you test this now with the latest release? I did some refactoring around this that I think may have made this more stable.

jinboowu commented 3 years ago

Thanks for the update, I just reinstalled the package, and as you noted to change or the =sl-= to =org-super-links-=, but it seems the old prefix is still effective and the new definition is not recognized by the system. The installation is as followed: (org-super-links :location (recipe :fetcher github :repo "toshism/org-super-links" :commit "0.3"))

jinboowu commented 3 years ago

change the installation config to (org-super-links :location (recipe :fetcher github :repo "toshism/org-super-links" :commit "0.4")),solved the prefix issue. but found the lag issue still exists.

jinboowu commented 3 years ago

The new issue is: it will insert the headline backlink, even when I call the org-capture command without the "sl-create-new-target"

the likely cause is this:

capture template

Whenever org-capture is called a link to the current point is automatically stored. To insert this link simply call org-super-links-insert-link. The backlink will be created automatically as usual.

toshism commented 3 years ago

Ah, so I think I misunderstood the issue you were seeing. So if you use the sl-create-new-target function then you don't need to insert a link at all. It will be auto added, but not until after you finalize the capture. The way this works is kind of hacky and is probably leading to the issue you are seeing. When you call org capture a marker pointing to the heading you were on when you called it is stored in a register, after you finalize the capture it pulls that mark to handle the linking. The issue is probably arising because the same register is used for storing all stored links.

For instance, if you call sl-create-new-target then before you finalize the capture you call org-super-links-store-link (or some other command that ends up calling it) you will overwrite the original marker. So after finalizing you will get some other link.

Hopefully that makes sense.

jinboowu commented 3 years ago

Thanks for the explanation, which helped me to better understand the cause of the issue.

I delete the "sl-creat-new-target" and just try the "sl-related-to-last-capture" command, and I found that it would work fine under this condition: I should finish the capture process, then call the command, it will have the right link.

Maybe I have misunderstand the command, previously I always call the command during the capture process. I would create a capture item a, then I created a new capture item b, I would write something then call the command and finish the capture process, it would link to the capture item c which created before the capture item a. But I think it would be much convenient to enable the command during the capture process.

Then I add the "sl-creat-new-target" function again to my spacemacs config, I found that if I just use the org-capture command it will be fine, once I call the "sl-creat-new-target" command once, after that, the calling of org-capture command will have the same result as the "sl-creat-new-target", it will automatically add the link, which is very annoying.

toshism commented 3 years ago

Sorry but I don't think I fully understand your last paragraph? Are you saying that using sl-create-new-target a single time means it happens everytime you use capture after that?

jinboowu commented 3 years ago

yes, that's very strange, only happened after the I updated to the latest release

jinboowu commented 3 years ago

no problem now after transferred to the Doom config

toshism commented 3 years ago

interesting, well thanks for the update and glad it's working for you now.