How do I make new bookmarks (bookmark-set
) be added to the end of the bookmark file, not the beginning?
1 Answer
I found a way to do this via monkey patching, and looking at the original code, it doesn't seem like there is any other way to accomplish this. (The changed section is marked by @monkeyPatched
.)
(defun bookmark-store (name alist no-overwrite)
"Store the bookmark NAME with data ALIST.
If NO-OVERWRITE is non-nil and another bookmark of the same name already
exists in `bookmark-alist', record the new bookmark without throwing away the
old one."
(bookmark-maybe-load-default-file)
(let ((stripped-name (copy-sequence name)))
(set-text-properties 0 (length stripped-name) nil stripped-name)
(if (and (not no-overwrite)
(bookmark-get-bookmark stripped-name 'noerror))
;; Already existing bookmark under that name and
;; no prefix arg means just overwrite old bookmark.
(let ((bm (bookmark-get-bookmark stripped-name)))
;; First clean up if previously location was fontified.
(when bookmark-set-fringe-mark
(bookmark--remove-fringe-mark bm))
;; Modify using the new (NAME . ALIST) format.
(setcdr bm alist))
;; otherwise just cons it onto the front (either the bookmark
;; doesn't exist already, or there is no prefix arg. In either
;; case, we want the new bookmark consed onto the alist...)
;;; @monkeyPatched
;; (push (cons stripped-name alist) bookmark-alist))
(setf (cdr (last bookmark-alist))
(list (cons stripped-name alist))))
;;;
;; Added by db
(setq bookmark-current-bookmark stripped-name)
(setq bookmark-alist-modification-count
(1+ bookmark-alist-modification-count))
(if (bookmark-time-to-save-p)
(progn (bookmark-save)))
(setq bookmark-current-bookmark stripped-name)
(bookmark-bmenu-surreptitiously-rebuild-list)))
bookmark-store
puts a new bookmark first. And you can instead put it at the end as you did, or you can move it there with a separate operation (outside ofbookmark-store
) that does the same thing.