I try to set a default path for opening a file via C-x C-f by adding the following to my .emacs:

(setq default-directory "~/some_dir/")

However, after I launch Emacs in some directory, the find-file directory is always reset to the current working directory when I do C-x C-f.

Is there something else I need to configure to enforce this?

2 Answers 2


According to the documentation:

default-directory is a variable defined in ‘C source code’. Its value is "~/" Local in buffer *scratch*; global value is nil

Automatically becomes permanently buffer-local when set. This variable is safe as a file local variable if its value satisfies the predicate 'stringp'.

Documentation: Name of default directory of current buffer. To interactively change the default directory, use command ‘cd’.

So, the default-directory variable, is the "current" directory, for the current buffer. And visiting any file or any directory, changes the default-directory for that buffer.


You can achieve what you want by:

  • adding (cd "/some/dir/") in yout init file.

  • using a hook: (add-hook 'find-file-hook #'(lambda () (setq default-directory (expand-file-name "/some/dir/"))))

  • writing a custom function that will (cd "/some/dir/") before finding file.

  • 1
    So if default-directory does not do what I want, how can I set a fixed directory for C-x C-f?
    – MLister
    Commented Dec 9, 2015 at 19:47
  • @MLister answer edited.
    – Nsukami _
    Commented Dec 9, 2015 at 22:21

If you are running emacs from a shortcut in Windows, you can edit the properties of the shortcut and set the Start in property to be the directory you'd like ctrl+x,ctrl+f to start from.

shortcut properties dialog box

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.