0

How do I make new bookmarks (bookmark-set) be added to the end of the bookmark file, not the beginning?

5
  • Does it matter where it goes? I mean functionally. Or is this just an aesthetic choice on your part?
    – NickD
    Sep 24, 2021 at 13:52
  • You can do what you like, of course. The reasons for the way it's designed are (1) this puts the latest bookmark first for completion and other operations, if no sorting is done, (2) this allows newer bookmarks with the same name to shadow older ones, without deleting the older ones (you can remove newer ones to re-expose older ones.
    – Drew
    Sep 24, 2021 at 19:09
  • What @NickD asked: What's your use case? Maybe this is an X-Y problem?
    – Drew
    Sep 24, 2021 at 19:11
  • Anyway, the answer is yes, you're right: 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 of bookmark-store) that does the same thing.
    – Drew
    Sep 24, 2021 at 19:12
  • @NickD Generally speaking, my older bookmarks are the more high-value targets, and I would manually move new bookmarks if they were high-value. Newer bookmarks are either temporary or not that high value. (After all, most new files I open are low-value, while the files that I use the most remain almost constant.)
    – HappyFace
    Sep 25, 2021 at 5:34

1 Answer 1

0

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)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.