1

I have my emacs configuration file under ~/.emacs with just one declaration:

(setq default-directory "/var/www/")

What I want to do is to C-x C-f and go directly to my apache directory. But I tried using C-x C-f and my current directory is HOME.

The file gets loaded, because I used this: (shell) and the shell gets opened. Anyone knows where my error is? I just want to set the start-up directory in htdocs.

3 Answers 3

3

default-directory does not do what you seem to think. C-h v default-directory

default-directory is a variable defined in `buffer.c'.
Its value is "/"
Local in buffer stackoverflow.com/questions/14914353; global value is nil

  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'.

Documentation:
Name of default directory of current buffer.  Should end with slash.
To interactively change the default directory, use command `cd'.

It's a buffer-local (i.e. buffer specific) variable, meaning its value is different depending on which buffer is currently active. So when you think you've set it to "/var/www", you are simply visiting a file already in that directory.

If you want to open a file from "/var/www", you need to make your own command that binds "/var/www" to default-directory.

Sign up to request clarification or add additional context in comments.

2 Comments

Unrelated question: Do you browse stackoverflow from Emacs? Is there a mode for that? Which one please?
No, I edit my answers in Emacs using a chrome "Edit With Emacs" plugin.
1

Just in case someone is wondering how to do this:

As @Pacha was saying, when emacs starts, the welcome screen shows up and it will change your working directory to the command-line-default-directory

So, for example, If you want your default directory to be "~/", add this to your .emacs and you should be on track.

(setq command-line-default-directory "~/")
(setq default-directory "~/")

Comments

0

Solved it, it was a really weird problem.

Every time I try to open a file from the default buffer (*GNU Emacs*) it changes the default directory to ~/, but when I try to open a file from another buffer, it opens to the one I specified in my variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.