From 788380cf6a2529ee7477aaadaa430e889c76dacd Mon Sep 17 00:00:00 2001 From: shipmints Date: Fri, 7 Feb 2025 19:39:36 -0500 Subject: [PATCH] Eliminate bookmark-maybe-historicize-string duplicates * lisp/bookmark.el (bookmark-maybe-historicize-string): Use 'add-to-history' to respect history-delete-duplicates and the 'history-length property. (Bug#76137) --- etc/NEWS | 7 +++++++ lisp/bookmark.el | 2 +- test/lisp/bookmark-tests.el | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index f5ec2309090..9fe46d818bd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -472,6 +472,13 @@ default), the 'whitespace-cleanup' function will now add the newline. ** Bookmark +--- +*** Bookmark history now saves each bookmark only once. +Previously, the variable 'bookmark-history' accumulated duplicate +bookmark names when bookmark features were used interactively. This +made their history larger than necessary for frequent bookmark users. +Bookmark names are now saved uniquely. + --- *** New user option 'bookmark-bmenu-type-column-width'. This user option controls the width of the type column on the bookmark diff --git a/lisp/bookmark.el b/lisp/bookmark.el index e8ad0cee31d..8495f33cb5f 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -603,7 +603,7 @@ from other commands that pass in the bookmark name, so `completing-read' never gets a chance to set `bookmark-history'." `(or (called-interactively-p 'interactive) - (setq bookmark-history (cons ,string bookmark-history)))) + (add-to-history 'bookmark-history ,string))) (defvar bookmark-make-record-function 'bookmark-make-record-default "A function that should be called to create a bookmark record. diff --git a/test/lisp/bookmark-tests.el b/test/lisp/bookmark-tests.el index 9099f6cb169..d551d429363 100644 --- a/test/lisp/bookmark-tests.el +++ b/test/lisp/bookmark-tests.el @@ -193,9 +193,12 @@ the lexically-bound variable `buffer'." (should (equal (bookmark-prop-get bmk 'filename) "prop"))))) (ert-deftest bookmark-tests-maybe-historicize-string () - (let ((bookmark-history)) + (let ((bookmark-history) + (history-delete-duplicates t)) (bookmark-maybe-historicize-string "foo") - (should (equal (car bookmark-history) "foo")))) + (bookmark-maybe-historicize-string "foo") + (should (equal (car bookmark-history) "foo")) + (should (= 1 (length bookmark-history))))) (defun bookmark-remove-last-modified (bmk) (assoc-delete-all 'last-modified bmk))