Is there a simple framework for making previous inputs of completing-read
persistent across emacs restarts?
For instance if I start with:
(completing-read "test:" '("a" "b") nil nil)
and enter "c" the next time I start emacs and execute I want the collection to be (completing-read "test:" '("a" "b" "c") nil nil)
instead. Is there a simple way to achieve this?

- 245
- 1
- 8
3 Answers
Yes: just put (savehist-mode 1)
in your ~/.emacs
and that should do the trick.
[ Tho not quite in the way you describe: c
will still not be among the completion candidates. But it will be in your history and hence accessible via M-p
, M-s
, ... ]

- 26,154
- 3
- 46
- 84
You can persist any global variable, by adding it to the value of option
savehist-additional-variables
. This includes any minibuffer history variable.Minibuffer history variables are used (typically) by
completing-read
. You can useM-p
andM-r
to retrieve previously used minibuffer inputs when you are prompted bycompleting-read
. See (emacs) Minibuffer History.However, there are many different minibuffer history variables. The most common, catch-all variable is
minibuffer-history
. You can try persisting all of the minibuffer history variables you can find ;-), but be aware that any code can add a new such variable.None of what I've said puts minibuffer history entries into the default set of completion candidates for any
completing-read
call. Input history and completion candidates are two different things.If you use Icicles then during minibuffer completion (including
completing-read
):If you use Icicles then you can use
M-o
to complete against the history list during any minibuffer inputting, even without completion (i.e., whether the minibuffer is being used bycompleting-read
or some other function).

- 75,699
- 9
- 109
- 225
It seems there is no history for single minibuffer instances so I'm using this approach where magit-gerrit-reviewers
is the '("a" "b" "c")
list:
Saving history
(defun magit-gerrit-write-review (file)
(with-temp-file file
(insert "(setq magit-gerrit-reviewers '")
(prin1 magit-gerrit-reviewers (current-buffer))
(insert ")" )))
Loading history:
(if (file-exists-p "~/.gerrit.reviewers")
(load "~/.gerrit.reviewers"))
And using it:
(completing-read "Reviewer Name/Email:" magit-gerrit-reviewers nil nil)

- 245
- 1
- 8