Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to create a link to another file instead creates a link to a random heading in the current file? #94

Open
Stewmath opened this issue May 14, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Stewmath
Copy link

Stewmath commented May 14, 2024

It's just as the title says... suppose I have a file named "Test1.org":

* Heading A

* Heading B

And a file named "Test2.org":

* Heading C

* Heading D

When I use "org-super-links-link" under "Heading B" in Test1.org and attempt to create a link to "Heading C", this happens instead:

Test1.org:

* Heading A
:PROPERTIES:
:ID:       662f9f39-b22a-4203-8ec1-2b87bcd53342
:END:
:BACKLINKS:
[2024-05-13 Mon 23:41] <- [[id:d798e570-13b4-4d46-906a-22d44c6ecc60][Heading B]]
:END:

* Heading B
:PROPERTIES:
:ID:       d798e570-13b4-4d46-906a-22d44c6ecc60
:END:
[[id:662f9f39-b22a-4203-8ec1-2b87bcd53342][Heading A]]

As you can see it simply linked to Heading A instead. It does seem to work when you link headings within the current file, but for anything outside the current file, this happens instead.

@Stewmath
Copy link
Author

I should also mention that I'm using org-super-links with doom emacs:

(package! org-super-links :recipe
  (:host github
   :repo "toshism/org-super-links"
   :branch "develop"
   :files ("*.el")))

@Stewmath
Copy link
Author

Stewmath commented May 14, 2024

OK, the problem is that my org directory is a symlink. The org-super-links-get-location function contains the following line for getting the buffer to be linked to:

				 (get-file-buffer (car (cdr target)))))))

According to the documentation for get-file-buffer:

The buffer's buffer-file-name must match exactly the expansion of FILENAME.
If there is no such live buffer, return nil.
See also find-buffer-visiting.

It was returning nil because the "canonical" version of the file is somewhere else. By returning nil, it was always operating in the current buffer.

Changing "get-file-buffer" to "find-buffer-visiting" in the implementation of the org-super-links-get-location function fixes the problem. In my case I've simply made my own version of the function:

(defun my-org-super-links-get-location ()
  "My fixed version of org-super-links-get-location. Works with symlinks."
  (let ((target (org-refile-get-location "Super Link")))
    (org-super-links--insert-link (set-marker (make-marker) (car (cdddr target))
                                              (find-buffer-visiting (car (cdr target)))))))
(setq org-super-links-search-function #'my-org-super-links-get-location)

Will leave this open in case the fix can get merged in.

@toshism
Copy link
Owner

toshism commented May 14, 2024

thanks for the investigation. i'll get a fix in for this.

@toshism toshism added the bug Something isn't working label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants