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?

2 Answers 2

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

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.

5
  • 1
    Is something like this available for helm?
    – vfclists
    Commented Jul 18, 2017 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". Commented Jul 2, 2019 at 3:34
  • (tldr M-x helm-mini) Commented Jul 2, 2019 at 3:35
  • e.g. (defcustom helm-mini-default-sources '(helm-source-buffers-list helm-source-recentf helm-source-buffer-not-found)) source github.com/emacs-helm/helm/blob/v3.2/helm-buffers.el#L92 Commented Jul 2, 2019 at 3:35
  • And for ivy, there's (setq ivy-use-virtual-buffers t) Commented Aug 25, 2019 at 10:58

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.