Resolve link generation conflict in bookmarked files

When a file has a bookmark, generating a link in that file (e.g. to the
line at point) results in a query from Org which link generating
function to use.  This is annoying and interferes with the usual flow.
To remedy this, we simply try not to be too smart and just generate
links to bookmarks when in the bookmark menu.
This commit is contained in:
Daniel Borchmann 2025-02-25 17:24:19 +01:00
parent ff30cbdf58
commit fc58eb56f4
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625

View File

@ -2235,37 +2235,10 @@ PARAMS may contain the following values:
(bookmark-jump bookmark))
(defun db/org-bookmark-store-link ()
"Store a link to the bookmark at point.
When in Dired, try to find bookmark that points to the file at
point. When in a buffer associated with a file, try to find a
bookmark that points to this file. Note that in this case, for
performance reasons, equality checks between file names is not
done with `file-equal-p', which seems to be too slow on Windows;
a simple `string=' is used instead, which may not be completely
accurate in certain cases."
(let (file bookmark bmks)
(cond ((eq major-mode 'dired-mode)
(setq file (abbreviate-file-name (dired-get-filename))))
((buffer-file-name (buffer-base-buffer))
(setq file (abbreviate-file-name
(buffer-file-name (buffer-base-buffer))))))
(if (not file)
"Store a link to the bookmark at point."
(let (bookmark)
(when (eq major-mode 'bookmark-bmenu-mode)
(setq bookmark (bookmark-bmenu-bookmark)))
(when (setq bmks
(->> (bookmark-all-names)
(-map (lambda (name)
(if (string= file
(abbreviate-file-name
(bookmark-location name)))
name)))
(delete nil)))
(setq bookmark
(if (eq 1 (length bmks))
(car bmks)
(completing-read "Bookmark: " bmks nil t nil nil (car bmks))))))
(if bookmark
(setq bookmark (bookmark-bmenu-bookmark))
(org-link-store-props :link (concat "bookmark:" bookmark)
:description bookmark))))