Compare commits

...

4 Commits

Author SHA1 Message Date
73a8e3be4b
Do not depend on autoloading db-org.el for bookmark links
Let's keep db-org a collection of autoloadable functions and move the
actual configuration of Org bookmark links to init.el.
2025-02-22 20:54:31 +01:00
795fcde3b8
Use default mechanism to store URL bookmarks directly after creation
Nicer :)
2025-02-22 20:54:31 +01:00
35cc0080d5
Set bookmark type for URLs
Just for display, nothing else should change with this (yet).
2025-02-22 20:54:31 +01:00
e32a67d666
Fix performance issue with file comparison on Windows
`file-equal-p` makes creating links too slow with bookmark links
enabled (which is the case by default).
2025-02-22 20:54:26 +01:00
3 changed files with 22 additions and 14 deletions

10
init.el
View File

@ -572,7 +572,9 @@
hydra-org-linking/body
org-dblock-write:db/org-backlinks
db/org-clock-goto-first-open-checkbox
org-password-manager-get-password-by-id))
org-password-manager-get-password-by-id
db/org-bookmark-open
db/org-bookmark-store-link))
;; This is to make the byte-compiler happy about setting some variables later on
;; that are defined in those packages.
@ -759,6 +761,9 @@
(browse-url
(format "https://www.cve.org/CVERecord?id=CVE-%s"
number))))
(org-link-set-parameters "bookmark"
:follow #'db/org-bookmark-open
:store #'db/org-bookmark-store-link)
(when (eq system-type 'windows-nt)
(org-link-set-parameters "onenote" :follow #'db/org-onenote-open)
(org-link-set-parameters "outlook" :follow #'db/org-outlook-open))
@ -2353,7 +2358,8 @@ eventuelly be set to nil, however)."
(use-package bookmark
:init (setq bookmark-default-file (expand-file-name "bookmarks" emacs-d-userdata)
bookmark-menu-confirm-deletion t))
bookmark-menu-confirm-deletion t
bookmark-save-flag 1))
(use-package dumb-jump
:commands (dumb-jump-xref-activate)

View File

@ -2228,20 +2228,20 @@ PARAMS may contain the following values:
;; The code in this section is based version 1.0 of `ol-bookmark.el' by Tokuya Kameshima;
;; see https://github.com/emacsmirror/org-contrib/blob/bd39cca48b1c4a8a1cdfb1cdd6be2ce700acdd97/lisp/ol-bookmark.el.
(org-link-set-parameters "bookmark"
:follow #'org-bookmark-open
:store #'org-bookmark-store-link)
(defun org-bookmark-open (bookmark _)
(defun db/org-bookmark-open (bookmark _)
"Visit the bookmark BOOKMARK."
(bookmark-jump bookmark))
(defun org-bookmark-store-link ()
(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."
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))))
@ -2254,9 +2254,9 @@ bookmark that points to this file."
(when (setq bmks
(->> (bookmark-all-names)
(-map (lambda (name)
(if (file-equal-p file
(abbreviate-file-name
(bookmark-location name)))
(if (string= file
(abbreviate-file-name
(bookmark-location name)))
name)))
(delete nil)))
(setq bookmark

View File

@ -847,13 +847,15 @@ it."
(let ((new-record `((filename . ,location)
(handler . ,handler))))
(bookmark-update-last-modified new-record)
(bookmark-store name new-record nil)
(bookmark-save)))
(bookmark-store name new-record nil)))
(defun db/bookmark-browse-url (bmk)
"Extract filename from bookmark BMK and apply `browse-url' to it."
(browse-url (bookmark-get-filename bmk)))
;; https://takeonrules.com/2024/12/17/extending-built-in-emacs-bookmark-package/
(put 'db/bookmark-browse-url 'bookmark-handler-type "URL")
(defun db/bookmark-system-open (bmk)
"Extract filename from bookmark BMK and apply `db/system-open' to it."
(db/system-open (bookmark-get-filename bmk)))