Change the default emacs directory to "cocoa emacs"

As explained in here , putting (setq default-directory ~ ~ / Desktop / mag) into .emacs is supposed to change the default directory.

When I do this with emacs on my mac, this does not work. Cx Cf still shows ~ / not ~ / Desktop / mag.

(cd "Users / smcho / Desktop / mag") also gives me this error - Error: no such directory was found through the CDPATH environment variable

What is wrong with them?

+4
emacs macos
source share
3 answers

The directory that appears at the prompt for Cx Cf ('find-file') comes from the default-directory value, which is a local buffer variable. When you first start Emacs, the starting buffer is the GNU Emacs buffer. This default-directory buffer is set from the command line directory of the -default variable.

So try the following:

(setq command-line-default-directory "~/Desktop/mag") 
+15
source share

Direct answer to your question:

 (setq-default default-directory "~/Desktop/mag") 

Reading the documentation for the variable ( Ch v default-directory RET ), you will see:

Automatically becomes buffer-local when installed in any way. This variable is safe as a local variable file if its value satisfies the stringp predicate.

Thus, opening the file automatically sets default-directory to the file path ...

So, if you always want find-file run in this directory, you can use this:

 (global-set-key (kbd "Cx Cf") 'my-find-file) (defun my-find-file () "force a starting path" (interactive) (let ((default-directory "~/scratch/")) (call-interactively 'find-file))) 

This question may be a duplicate. Prevent automatic changes to the default directory . Although it’s hard to say.

+6
source share

In addition to the notes above regarding default-directory , I also had to prevent the Emacs splash screen from starting so that subsequent commands, such as dired , actually display their buffer when called from .emacs at startup:

  (setq inhibit-splash-screen t) 
+3
source share

All Articles