8

I've discovered desktop-save-mode which allows Emacs to be closed and when it reopens, it appears with the same files that were open before.

I want to take this a bit further and I was wondering if I could also:

  1. Save the history of files I've open with C-x C-f. I often end up opening the same files, so it'd be great to easily find those. If not possible to save this, maybe some bookmarks would help?
  2. Save the history of buffer commands executed via M-x or M-:, is this possible? If not possible, maybe I could keep some snippets around to do this?
Drew
  • 75,699
  • 9
  • 109
  • 225
Galder Zamarreño
  • 1,527
  • 2
  • 12
  • 21

2 Answers2

9

The savehist library is the general option for persisting variable values across sessions.

Simply enabling savehist-mode ensures that most minibuffer histories will persist, but you can also tell it to do likewise for any other variable, by adding it to savehist-additional-variables:

(eval-after-load "savehist"
 '(add-to-list 'savehist-additional-variables 'foo))

(savehist-mode 1)

See also: M-x customize-group RET savehist RET

phils
  • 48,657
  • 3
  • 76
  • 115
2

For file history, if you enable ido-mode and customize ido-use-virtual-buffers to t, even closed buffers remain in the ido history. This persists across desktop.el sessions.

C-k during an ido-switch-buffer removes the selected buffer from the history, if you need to get it out of your way.

Croad Langshan
  • 3,192
  • 14
  • 42
  • 1
    Is something like this available for helm? – vfclists Jul 18 '17 at 20:35
  • @vfclists yeah, there's a builtin "*Helm Source*" for `ido` virtual buffers and another for `recentf` files. (1) use `M-x helm-mini` instead of `M-x helm-buffer` , which merges that *Helm Source* with the source for open buffers and with a "dummy source". (2) iirc, enable the option which says to "use recentf buffers instead of ido virtual buffers". – sam boosalis Jul 02 '19 at 03:34
  • (tldr `M-x helm-mini`) – sam boosalis Jul 02 '19 at 03:35
  • e.g. `(defcustom helm-mini-default-sources '(helm-source-buffers-list helm-source-recentf helm-source-buffer-not-found))` source https://github.com/emacs-helm/helm/blob/v3.2/helm-buffers.el#L92 – sam boosalis Jul 02 '19 at 03:35
  • And for ivy, there's `(setq ivy-use-virtual-buffers t)` – Croad Langshan Aug 25 '19 at 10:58