saving history between sessions

I am back from my little holiday, fully re-energized etc.; Before I went, I
asked Emacs-Fu-readers to share their favorite .emacs-tricks; and I was very
pleasantly surprise with so many excellent tricks, many of which I did not
know about. Thanks!!



So, in some future entries I´ll go through the ones I found particularly
interesting – however, look for yourself through all these nice tips. Of
course, I won't simply copy what you could already read, – I'm not that
lazy – but instead, I'll try to give a bit of extra background, and try to
make these tips even more useful.




savehist-mode




The first great new trick mentioned in the dot-emacs trickery-post was
savehist-mode (thanks Valvo).




With savehist-mode, you can save your minibuffer history (ie. the commands
you gave). It's the simple alternative to more complex session-saving
mechanisms like desktop-save-mode and (many!) friends.



save-hist-mode lets you can customize quite a few things, so my setup now
looks like this:

(setq savehist-additional-variables    ;; also save...
'(search-ring regexp-search-ring) ;; ... my search entries
savehist-file "~/.emacs.d/savehist") ;; keep my home clean
(savehist-mode t) ;; do customization before activate


As shown, you should do the customizations before enabling savehist-mode,
or they will be ignored.



The savehist-additional-variables customization particularly interesting;
you can put any (printable) variable in the list, ie. you could put
kill-ring in there, to retrieve your old kill ring (the clipboard) when you
restart emacs again.



Note: if you want emacs to remember your recently-used files between sessions,
you can take a look at recentf.



Also, note that I am setting savehist-file to ~/.emacs.d/savehist. In
general, I'll try to put all my emacs files there, instead of in my
home-directory. This makes it a bit easier to back up things and keep my ~/
clean. For historical reasons, I still have my ~/.emacs, but I could use
~/.emacs.d/init.el instead (great tip by Steve Purcell).


No comments:

Post a Comment

Followers

Popular Posts