How do I get emacs to tell me the location of the .emacs file it has loaded?
My situation is simply when I do sudo emacs
, it loads up a very different .emacs file than the one in my home directory. I can get around with by doing M-x eval-buffer
on my own .emacs file, but that's a lot of extra steps, plus it doesnt seem to clear out the goofy binds in whatever .emacs file is being loaded. If anything, I'd simply like to find the .emacs file and remove some of the stranger binds (c-n, c-p, c-a all rebound to strange stuff)
My main question is still, how do I get emacs to tell me the location of the .emacs file it has loaded?
Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your . emacs file with C-x C-f ~/. emacs . There's further information at HOME and Startup Directories on MS-Windows.
emacs config file usually resides in your home directory. See also The Emacs Initialization File. If you need to start with a blank . emacs , try touch ~/.
You can use the command load-file ( M-x load-file , then press return twice to accept the default filename, which is the current file being edited). You can also just move the point to the end of any sexp and press C-x C-e to execute just that sexp.
The init file used is stored in the variable 'user-init-file'. To see this use 'describe-variable' (C-h v), type in 'user-init-file' and it will display the file used.
You could try to see what file is found by:
C-x C-f ~/.emacs RET
~
gets translated to the value of the HOME
environment variable. Emacs looks for .emacs
, then .emacs.elc
(the byte compiled version), then .emacs.el
, then ~/.emacs.d/init.elc
and ~/.emacs.d/init.el
. This documentation shows the alternatives. It also depends on the environment variabls LOGNAME
and USER
.
You can also check out the contents of the *Messages*
buffer - though you should set (setq message-log-max t)
(if you can) to ensure that all the Messages are kept. Inside that buffer there are lines that look like:
Loading /home/tjackson/.emacs.tjackson.el (source)...
which will show what files were loaded.
You should also check out the Find-Init documentation that shows even more files that can be loaded like the site-start.el
, and terminal specific initialization (new to me).
If you are on Linux, you could try this to see what files are opened by emacs when it launches.
sudo strace -o /tmp/emacs.txt -e open emacs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With