I use registers (such as C-x r s 0) as a multi-valued clipboard that can save different contents (copy-to-register). Then I can "paste" the value using C-x r i 0. This is really convenient, but all the register values are lost if I close Emacs.

Is it possible to save these register values into a file somewhere and restore them when I open a new Emacs session?


1 Answer 1



Alist of elements (NAME . CONTENTS), one for each Emacs register.

Here is an example:

;; ~/.emacs.d/init.el  -*- lexical-binding: t; -*-

(require 'register)

(let ((my/registers-file "~/.emacs.d/my-registers.el"))
  (add-hook 'kill-emacs-hook
            (lambda ()
              (with-temp-file my/registers-file
                (insert (prin1-to-string register-alist)))))
  (when (file-exists-p my/registers-file)
    (setq register-alist (with-temp-buffer
                           (insert-file my/registers-file)
                           (read (current-buffer))))))
  • 2
    That's probably going to work for strings, numbers and rectangles but it is unlikely to work for window/frame configurations, buffer positions and other such things that are not necessarily preserved across sessions (although desktop-mode might help with some of these too).
    – NickD
    Commented Nov 18, 2023 at 15:44
  • @NickD: Thank you for the additional information, I forgot to remind OP about these precautions. Actually, I believe the ultimate solution to all these problems is to use an Emacs server; I recommend that OP learn about it.
    – shynur
    Commented Nov 18, 2023 at 15:50
  • 2
    Or just add register-alist to savehist-additional-variables (and use savehist.el). Also: search for tags [persistence] and [variables] here.
    – Drew
    Commented Nov 18, 2023 at 16:18

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.