Changing the default folder in Emacs
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
fileSolution 2: Add
(setq default-directory "C:/Documents and Settings/USER_NAME/Desktop/")
to the.emacs
fileSolution 3: Right click the Emacs short cut, hit properties and change the start in field to the desired directory.
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, in Emacs terms, the default-directory
(a variable).
When you start Emacs using an MS Windows shortcut, the default-directory
is initially the folder (directory) specified in the "Start In" field of the shortcut properties. Right click 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, default-directory
starts as the directory where 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 = PWD = present working directory. It makes a lot more sense at the command line than in a GUI.
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.
You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.
I've put
(cd "c:/cvsroot/")
in my .emacs and it did the job