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?

3 Answers 3


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, ... ]

  1. You can persist any global variable, by adding it to the value of option savehist-additional-variables. This includes any minibuffer history variable.

  2. Minibuffer history variables are used (typically) by completing-read. You can use M-p and M-r to retrieve previously used minibuffer inputs when you are prompted by completing-read. See (emacs) Minibuffer History.

  3. 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.

  4. 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.

  5. If you use Icicles then during minibuffer completion (including completing-read):

    • You can use M-h to match your current input against the minibuffer history directly.

    • Use M-<pause> to restrict the current set of completion candidates to those you've used previously. If you use C-u M-pause, then the previously used candidates are ordered chronologically, most recent first.

  6. 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 by completing-read or some other function).


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)

Your Answer

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

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