Compare commits

...

4 Commits

Author SHA1 Message Date
1ef654788a
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:52:30 +01:00
54bcd4d6a0
Use default mechanism to store URL bookmarks directly after creation
Nicer :)
2025-02-22 18:23:34 +01:00
4457921ca9
Set bookmark type for URLs
Just for display, nothing else should change with this (yet).
2025-02-22 18:19:29 +01:00
db00b4f3c7
Fix performance issue with file comparions on Windows
`file-equal-p` makes creating links too slow with bookmark links
enabled (which is the case by default).
2025-02-22 18:07:41 +01:00
3 changed files with 22 additions and 14 deletions

10
init.el
View File

@ -572,7 +572,9 @@
hydra-org-linking/body hydra-org-linking/body
org-dblock-write:db/org-backlinks org-dblock-write:db/org-backlinks
db/org-clock-goto-first-open-checkbox 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 ;; This is to make the byte-compiler happy about setting some variables later on
;; that are defined in those packages. ;; that are defined in those packages.
@ -759,6 +761,9 @@
(browse-url (browse-url
(format "https://www.cve.org/CVERecord?id=CVE-%s" (format "https://www.cve.org/CVERecord?id=CVE-%s"
number)))) number))))
(org-link-set-parameters "bookmark"
:follow #'db/org-bookmark-open
:store #'db/org-bookmark-store-link)
(when (eq system-type 'windows-nt) (when (eq system-type 'windows-nt)
(org-link-set-parameters "onenote" :follow #'db/org-onenote-open) (org-link-set-parameters "onenote" :follow #'db/org-onenote-open)
(org-link-set-parameters "outlook" :follow #'db/org-outlook-open)) (org-link-set-parameters "outlook" :follow #'db/org-outlook-open))
@ -2353,7 +2358,8 @@ eventuelly be set to nil, however)."
(use-package bookmark (use-package bookmark
:init (setq bookmark-default-file (expand-file-name "bookmarks" emacs-d-userdata) :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 (use-package dumb-jump
:commands (dumb-jump-xref-activate) :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; ;; 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. ;; see https://github.com/emacsmirror/org-contrib/blob/bd39cca48b1c4a8a1cdfb1cdd6be2ce700acdd97/lisp/ol-bookmark.el.
(org-link-set-parameters "bookmark" (defun db/org-bookmark-open (bookmark _)
:follow #'org-bookmark-open
:store #'org-bookmark-store-link)
(defun org-bookmark-open (bookmark _)
"Visit the bookmark BOOKMARK." "Visit the bookmark BOOKMARK."
(bookmark-jump bookmark)) (bookmark-jump bookmark))
(defun org-bookmark-store-link () (defun db/org-bookmark-store-link ()
"Store a link to the bookmark at point. "Store a link to the bookmark at point.
When in Dired, try to find bookmark that points to the file at 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 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) (let (file bookmark bmks)
(cond ((eq major-mode 'dired-mode) (cond ((eq major-mode 'dired-mode)
(setq file (abbreviate-file-name (dired-get-filename)))) (setq file (abbreviate-file-name (dired-get-filename))))
@ -2254,7 +2254,7 @@ bookmark that points to this file."
(when (setq bmks (when (setq bmks
(->> (bookmark-all-names) (->> (bookmark-all-names)
(-map (lambda (name) (-map (lambda (name)
(if (file-equal-p file (if (string= file
(abbreviate-file-name (abbreviate-file-name
(bookmark-location name))) (bookmark-location name)))
name))) name)))

View File

@ -847,13 +847,15 @@ it."
(let ((new-record `((filename . ,location) (let ((new-record `((filename . ,location)
(handler . ,handler)))) (handler . ,handler))))
(bookmark-update-last-modified new-record) (bookmark-update-last-modified new-record)
(bookmark-store name new-record nil) (bookmark-store name new-record nil)))
(bookmark-save)))
(defun db/bookmark-browse-url (bmk) (defun db/bookmark-browse-url (bmk)
"Extract filename from bookmark BMK and apply `browse-url' to it." "Extract filename from bookmark BMK and apply `browse-url' to it."
(browse-url (bookmark-get-filename bmk))) (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) (defun db/bookmark-system-open (bmk)
"Extract filename from bookmark BMK and apply `db/system-open' to it." "Extract filename from bookmark BMK and apply `db/system-open' to it."
(db/system-open (bookmark-get-filename bmk))) (db/system-open (bookmark-get-filename bmk)))