I'm new to Emacs. I saw that you could have registers with special files. I really like that feature, and I was wondering if I could get the same functionality with a Dired buffer. For example, the following works:

    (set-register ?e (cons 'file "~/.emacs.d/init.el"))

And I would like to something along the lines of:

    (set-register ?o '(buffer '(dired "path/somewhere")))

However, I get the following error:

switch-to-buffer: Wrong type argument: stringp, ('(dired "path/somewhere")).

How could I get that functionality to work?

1 Answer 1


It turns out you have to use the "file" command and simply specify a directory. It will open dired outomatically.

As in:

(set-register ?o (cons 'file "path/to/directory"))

C-h v register-alist tells you all the possibilities for register values:

Alist of elements (NAME . CONTENTS), one for each Emacs register.
NAME is a character (a number).  CONTENTS is a string, number, marker, list
or a struct returned by ‘registerv-make’.
A list of strings represents a rectangle.
A list of the form (file . FILE-NAME) represents the file named FILE-NAME.
A list of the form (file-query FILE-NAME POSITION) represents
 position POSITION in the file named FILE-NAME, but query before
 visiting it.
A list of the form (buffer . BUFFER-NAME) represents the buffer BUFFER-NAME.
 represents a saved window configuration plus a saved value of point.
 represents a saved frame configuration (a.k.a. "frameset") plus
 a saved value of point.
  • Posting the answer you discovered yourself -- very nice! You should mark it accepted too, as a little reward for yourself. Commented Oct 10, 2023 at 20:46
  • Hi @PhilHudson! Thanks for the reminder. Stackexchange only told me to wait 2 days before marking my own answer as correct. Have a good day ^_^. Commented Oct 11, 2023 at 1:40

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.