Change default directory in Emacs startup in Linux(CentOS 7)

639 views Asked by At

I am learning emacs nowadays. So, it's pretty much frustrating to find that even the basic settings are not directly accessible in the menu bars.

I searched for changing the default directory which pops up when I use C-x C-f to create/search a file.

Find file: ~/cursor_blinking

Emacs version = GNU Emacs 24.3

Everywhere they have suggested to change the default directory in your ~/.emacs, or ~/.emacs.el, or ~/.emacs.d/init.el; whichever exists. In my case, none of them exists. Only ~/.emacs.d directory exists,but there doesn't exist any such file.

I even tried changing the working directory using Emacs command `cd', but, of no avail.

Also, even the similar questions have been asked here for Windows OS, which is not my case.

How should I get back to work, given that I want to set my default-directory as "My Directory"?

2

There are 2 answers

1
Jeffrey DeLeo On

In your home directory, create a file ".emacs.el". In that file, put the line:

(setq default-directory "~/My Directory")

or whatever. As Rörd says, if you subsequently change this via the interactive cd command, than that will be the new default directory.

4
Rörd On

Those three names are the possible names for the Emacs configuration file. If none of those exists, create any one of them to put your configuration in it.

The Emacs command cd is meant to change the default directory. You can use it interactively with M-x cd, or call it from the configuration file with (cd "My Directory"). Only in the second case the change will be permanent. Also note that the default directory is a buffer-local setting, so you can have a different one for each buffer, and changing it on one buffer won't affect another buffer that's already open.

By the way, activating one of the Emacs extensions like ido-mode that let you navigate directories quicker might make changing the default directory unnecessary.