tags:

views:

6211

answers:

12

I am fairly new to emacs and I have been trying to figure out how to change the default folder for c-x c-f on start up. For instance when I first load emacs and hit c-x c-f its default folder is C:\emacs\emacs-21.3\bin, but I would rather it be the desktop. I believe there is some way to customize the .emacs file to do this, but I am still unsure what that is.

Update: There are three solutions to the problem that I found to work, however I believe solution 3 is windows only.

  • Solution 1: Add (cd "C:/Users/Name/Desktop") to the .emacs file
  • Solution 2: Add (setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" ) to the .emacs file
  • Solution 3: Right click the emacs short cut, hit properties and change the start in field to the desired directory.
+1  A: 

Does this serve your purpose?

http://infolab.stanford.edu/~manku/emacs.html

Codeslayer
Could you be more specific?
Sébastien RoccaSerra
A: 

When I add the line (setq load-path (cons "C:\Users\Name\Desktop" load-path)) to my .emacs file, the default folder when I hit c-x c-f is still C:\emacs\emacs-21.3\bin. It does not however cause an error on start up so I may be adding the wrong line or using it incorrectly.

Anton
The load-path is the ordered list of directories emacs will search when resolving function names. It won't affect C-x C-f.You need to follow one of the suggestions below to either tell Windows to start emacs in a different directory or do a cd inside of your .emacs file.
Bart
+10  A: 

I've put

(cd "c:/cvsroot/")

in my .emacs and it did the job

vava
+18  A: 

You didn't say so, but it sounds like you're starting emacs from a Windows shortcut.

The directory that you see with c-x c-f is the cwd, which for a Windows shortcut is specified in the "Start In" field in the properties. Right click on the shortcut, select properties, and type the path to your desktop in the "Start In" field.

If you're using emacs from the command line, c-x c-f would browse to the directory that you were in when you started emacs (the cwd).

This approach is better than editing your .emacs file since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of emacs if you need it.

CWD = current working directory. It makes a lot more sense at the command line than in a GUI. Another common name for this is PWD = print working directory, which refers to the name of a unix command that prints this information. Thanks to @[jf-sebastian] for the clarification.

Bart
I've always thought that PWD stands for `print working directory` (print name of the current working directory) and CWD stands for `current working directory`
J.F. Sebastian
Which of course is what the wikipedia article I linked to explains :-).
Bart
Yes I am using emacs on windows.
Anton
+1  A: 

As you're on Windows you can do it with a shortcut.

Create a shortcut to C:\emacs\emacs-21.3\bin\runemacs.exe. Edit the properties of the shortcut and change the value of Start In: to be whatever you want your default directory to be.

Dave Webb
+3  A: 

The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in C:\dir_a, then the working directory for that buffer will by default be C:\dir_a. You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f).

If you start emacs without opening a file, you will end up with the *scratch* buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with M-x cd, also from the *scratch* buffer.

Finally, you can do as Vadim suggests and put

(cd "c:/dir_a/")

in your .emacs file, to make that directory the default no matter how you start emacs.

ehdr
+5  A: 

I think the line you need to add to your .emacs is is

(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )

Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.

Michael
This works well under linux.
Matt H
+3  A: 

load-path isn't the variable you need to set. That tells emacs where to look when you are loading elisp libraries.

Michael
Yep I realized that thanks to Bart when he told me in a comment
Anton
+3  A: 

I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting "Find file: C:\Program Files\emacs\bin/" like Anton. I have HOME set to "C:\Documents and settings\USER NAME\My Documents". The response to C-x C-f I want in the minibuffer is "Find file: ~/". By adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\Documents and settings\USER NAME\My Documents/" which is functionally the same as "Find file: ~/". However, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.

Alistair
+1  A: 

I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory. Since my emacs defaults to "home" I simply say:

/Desktop/blank_file

and that opens a file called "blank_file"

That also moves the current working directory for that emacs session to the desktop.

If I happen to put stuff in "blank_file" then save it, of course, I've got that stuff saved. Which might be an annoyance or it might be a good thing, depending!

Greg Laden
+1  A: 

You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.

Chris Huang-Leaver
+1  A: 

To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:

;;This works for Windows XP.
(setq default-directory (concat "C:\Documents and Settings\MY_ACCOUNT\DESKTOP\"))

Mr Mulch