Shishir Pandey
Shishir Pandey

Reputation: 832

emacs "Find File:" default path

I am using emacs on windows. I would like to know how to change the default "Find File:" path in emacs i.e. When we press "C-x C-f" I want the default file path to point to my Documents directory and not to "c:\emacs-**\bin/".

Upvotes: 14

Views: 13146

Answers (4)

Thomas
Thomas

Reputation: 17422

In a buffer that is visiting a file, the default path you see when you visit a new file (C-x C-f) is the directory that contains the current buffer's file.

In order to override the value "c:\emacs-**\bin/" with something more sensible, set the default-directory variable in your .emacs file:

(setq default-directory "/path/to/documents/directory/")

Note that the path value should end with a slash (or backslash on Windows).

However, you might also want to consider changing the value of your HOME environment variable, as by default, this is what the variable default-directory points at at startup (unless set to some other value like shown above).

Upvotes: 18

Drew
Drew

Reputation: 30699

Variable 'default-directory' is the "current" directory (for the current buffer). Command 'cd' changes directories, and visiting any file or directory (e.g. with Dired) changed the 'default-directory' for that buffer.

You can start Emacs in a given directory, by passing that directory on the command line. You can use a Windows shortcut to do this too. And you can have the shortcut visit that directory in Dired.

Example shortcut info:

Target: C:\Emacs\bin\runemacs.exe "C:\my\favorite\folder"

Start in: C:\my\favorite\folder

Upvotes: 5

loudandclear
loudandclear

Reputation: 2386

This shall do it:

(global-set-key (kbd "C-x C-f")  (lambda () (interactive)
                                     (cd "somePathHere")
                                     (call-interactively 'find-file)))

(replace somePathHere with the path to your documents directory)

Upvotes: 6

Giann
Giann

Reputation: 3192

You have to redefine the environment variable HOME to your new default directory.

Upvotes: 0

Related Questions