branch: externals/corfu
commit dee10bbddbd3ed572ed87a2b42cd7f0b2a454aca
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    Automatically save corfu-history
---
 CHANGELOG.org               | 3 +++
 extensions/corfu-history.el | 8 +++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 89c4efec67..f05413dd0f 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -7,6 +7,9 @@
 - =corfu-history-duplicate= and =corfu-history-decay=: New customization 
options to
   adjust the rank of duplicate history elements, such that they appear earlier
   in the completion list.
+- =corfu-history-mode=: Ensure that the =corfu-history= is saved if 
=savehist-mode= is
+  enabled. Automatically add =corfu-history= to
+  =savehist-minibuffer-history-variables=.
 
 * Version 2.0 (2025-03-28)
 
diff --git a/extensions/corfu-history.el b/extensions/corfu-history.el
index 4280cbe32a..7120ae8367 100644
--- a/extensions/corfu-history.el
+++ b/extensions/corfu-history.el
@@ -30,12 +30,10 @@
 ;; The recently selected candidates are stored in the `corfu-history' variable.
 ;; If `history-delete-duplicates' is nil, duplicate elements are ranked higher
 ;; with exponential decay.  In order to save the history across Emacs sessions,
-;; enable `savehist-mode' and add `corfu-history' to
-;; `savehist-additional-variables'.
+;; enable `savehist-mode'.
 ;;
 ;; (corfu-history-mode 1)
 ;; (savehist-mode 1)
-;; (add-to-list 'savehist-additional-variables 'corfu-history)
 
 ;;; Code:
 
@@ -102,6 +100,10 @@ See also `corfu-history-duplicate'."
 
 (cl-defmethod corfu--insert :before (_status &context (corfu-history-mode (eql 
t)))
   (when (>= corfu--index 0)
+    (unless (or (not (bound-and-true-p savehist-mode))
+                (memq 'corfu-history (bound-and-true-p 
savehist-ignored-variables)))
+      (defvar savehist-minibuffer-history-variables)
+      (add-to-list 'savehist-minibuffer-history-variables 'corfu-history))
     (add-to-history 'corfu-history
                     (substring-no-properties
                      (nth corfu--index corfu--candidates)))

Reply via email to