Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing automatic change of default-directory

Tags:

emacs

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 that buffer and you (for example) start SLIME, it uses default-directory as the current working directory for SLIME. If you try to open a new file, it opens the file with default-directory as your starting point.

I want to be able to M-x cd or otherwise cd to a directory, and then never have Emacs change my current working directory to anything but that directory until I tell it otherwise. I want this to be global across all buffers, so that any time I'm doing something involving the current working directory, I know what it's set to regardless of where my cursor is at the moment. Is there a way to do this?

like image 440
Brian Carper Avatar asked Dec 09 '08 22:12

Brian Carper


1 Answers

You could try using something like this:

(add-hook 'find-file-hook
          (lambda ()
            (setq default-directory command-line-default-directory)))
like image 99
link0ff Avatar answered Sep 18 '22 20:09

link0ff