tags:

views:

63

answers:

2

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

When I do that with the emacs on my mac, it doesn't work. C-x C-f still shows ~/ not ~/Desktop/mag.

(cd "Users/smcho/Desktop/mag") also gives me this error - Error: No such directory found via CDPATH environment variable

What's wrong with them?

+1  A: 

The straight-forward answer to your question is:

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

Reading the documentation for the variable (C-h v default-directory RET) you'll see:

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

That said, opening a file automatically sets the default-directory to the path of the file...

So, if you always want find-file to start at that directory, you can use this:

(global-set-key (kbd "C-x C-f") '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 of Preventing automatic change of default-directory. Though it's difficult to tell.

Trey Jackson
@Trey : I added the code in .emacs, but C-c C-f shows me the ~/ not ~/Desktop/mag.
prosseek
@prosseek You *always* want `C-c C-f` to start at `~/Desktop/mag`? That's slightly different, and I think already answered. I'll update my answer.
Trey Jackson
@Trey : I'm sorry, I'm confused. C-x C-f was the key what I intended to use to open "~/Desktop/mag", but it's OK that I find a way to open it using C-c C-f.
prosseek
@prosseek - I'd wondered if it was `C-x C-f`, I'll update my answer.
Trey Jackson
@Trey : Thanks! it perfectly works.
prosseek
+1  A: 

The directory that appears in the prompt for C-x C-f ('find-file') comes from the value of default-directory, which is a buffer-local variable. When you first start Emacs, the initial buffer displayed is the GNU Emacs buffer. That buffer's default-directory is set from the variable command-line-default-directory.

So, try this:

(setq command-line-default-directory "~/Desktop/mag")
Jim Blandy
That doesn't work. But Trey's does. Actually I thought there was a simpler version than what he proposed.
Matt H