command sl-create-new-target insert the original link
jinboowu opened this issue · 13 comments
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)
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.
@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.
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"))
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.
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.
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.
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.
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?
yes, that's very strange, only happened after the I updated to the latest release
no problem now after transferred to the Doom config
interesting, well thanks for the update and glad it's working for you now.