49

I'd like to save, for instance, my find-file and Meta-X history in Emacs' mini-buffer so I can recall commands later in a different session.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Jonathon Watney
  • 20,248
  • 9
  • 38
  • 40

3 Answers3

86

As Trey Jackson said, you want to put this:

(savehist-mode)

in your Emacs start up file, then restart Emacs. (Calling it interactively will stomp on your current mini-buffer history, so you may not want to do that.)

It's also worth pointing out that you can persist other variables across sessions by adding them to savehist-additional-variables, like so:

(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))

You may also want to customize savehist-file, to pick the location where Emacs saves all this stuff:

(setq savehist-file "~/.emacs.d/tmp/savehist")
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
genehack
  • 136,130
  • 1
  • 24
  • 24
  • Thanks for the info on clobbering and the ability to add other history buffers. This looks like what I'm looking for. – Jonathon Watney Aug 23 '09 at 18:11
  • 1
    "... then restart Emacs. (Calling it interactively will stomp on your current mini-buffer history, so you may not want to do that.)" Won't restarting Emacs, when you don't have `savehist-mode` enabled, also clobber your history? Seems the interactive call is less destructive to Emacs state, unless I'm missing something. – Martin C. Martin Sep 05 '18 at 15:02
  • `(savehist-mode 1)` gives `Symbol’s value as variable is void: pell-buffer` error how can I fix it? – alper Jan 14 '21 at 12:07
  • @alper that's gotta be something related to `pell-buffer` in your local config; without seeing it, i don't think folks will be able to offer much advice... – genehack Jan 15 '21 at 14:53
18
M-x savehist-mode

or

(savehist-mode 1)

(available in Emacs as of 22.1)

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
1

If you have an Emacs version older than 22, you can use this instead:

http://www.emacswiki.org/emacs/download/savehist-20%2b.el

Drew
  • 29,895
  • 7
  • 74
  • 104