As per the Emacs docs, every time you open a file, Emacs changes default-directory
to the directory containing that file.
Then, if the cursor is in th
This is the best I've come up with so far, sadly:
(defun find-file-save-directory ()
(interactive)
(setq saved-default-directory default-directory)
(ido-find-file)
(setq default-directory saved-default-directory))
(global-set-key "\C-x\C-f" 'find-file-save-directory)
This works as long as default-directory
is properly set before I C-x C-f
. I'm going to Accept jurta's answer for pointing me in a useful direction.
You could try using something like this:
(add-hook 'find-file-hook
(lambda ()
(setq default-directory command-line-default-directory)))
Another variant is to bind default-directory to the necessary directory in directory-local variables, e.g. in the .dir-locals.el file in one of your parent directories to something like:
((nil . ((default-directory . "~/.emacs.d/"))))