1

I have read the guide found here:

How Emacs Finds Your Init File

I cannot find any .emacs directory in my home directory. I have show hidden files selected. I also cannot find the init.el file in Emacs home directory.

Since I have been unable to find the init.el file, is it reasonable to think there isn't one?

I am using Emacs 27.1 on Windows 10. Except for Emacs home directory I installed with the defaults. I used no command-line options during install.

I seem to remember I have once read a post which explained Emacs has an internal variable which is used to hold the value of the location of where Emacs found the init.el file after it starts, but after searches I have been unable to find what that variable is.

How can I find my init.el file, having failed to locate it in the locations mentioned in the manual?

Does a variable exist which says where the init.el file was found? If so, what is it?

9
  • 1
    You might like to clarify why you think there should be a .emacs directory (AFAIK there can be a .emacs file or a .emacs.d directory, but I've never heard of a .emacs directory). Similarly clarify what you mean by "Emacs home directory". – Stefan Aug 14 '20 at 3:19
  • C-h v and then user-init-file will show you what your current user init file is – minibuffer Aug 14 '20 at 14:08
  • Thanks @minibuffer. I have looked at the variable and it says "Its value is "~/.emacs"". I cannot fine a file of that name. What does this mean? – Georgina Davenport Aug 14 '20 at 16:35
  • That is because windows (usually) sets $HOME as %APPDATA% and puts your .emacs file in there. So in Windows ~ usually meanss %APPDATA%. In a windows cmd prompt do cd %APPDATA%. You will most likely find your .emacs file in there. – minibuffer Aug 14 '20 at 17:29
  • 1
    well you might not have an .emacs file. Create an init.el file inside the .emacs.d directory that you just found. put some sample config on there and see if emacs picks it up. For example (setq initial-scratch-message "Hello from my new init file :)") – minibuffer Aug 14 '20 at 17:44
0

This answer specifically address the question of how/where to find Emacs' user-init-file on Microsoft Windows.

HOME and Startup Directories on MS-Windows

Here is the relavent section from the Emacs manual (available via C-h i) Emacs > Microsoft Windows > Windows Home

The Windows equivalent of HOME is the user-specific application data directory. The actual location depends on the Windows version; ... C:\Users\USERNAME\AppData\Roaming on Windows Vista and later ... If this directory does not exist or cannot be accessed, Emacs falls back to C:\ as the default value of ‘HOME’.

This location is stored in the environment variable that windows refers to as %APPDATA%. See this question and answer on superuser

You can try to find the location of your user-init-file by doing C-h v and then user-init-file [RET]. You will see an output similar to

~/.emacs

On Windows this isn't particularly helpful. We can now find out what Emacs means by ~ doing one of the following:

C-x C-f > ~ > [backspace] The echo area at the bottom of your Emacs screen will expand to show you what Emacs currently consider to be HOME. (Note that this works on Windows and according to @NickD doesn't work on GNU/Linux)

OR more generally (quoting from the Emacs manual)

You can always find out what Emacs thinks is your home directory’s location by typing C-x d ~/ <RET>. This should present the list of files in the home directory, and show its full name on the first line. Likewise, to visit your init file, type C-x C-f ~/.emacs <RET> (assuming the file’s name is .emacs).


Setting up the init.el on Windows

Instead of keeping a .emacs file most emacs users now use an init.el file stored in your emacs-user-directory. This directory defaults to ~/.emacs.d and in your case %APPDATA%/.emacs.d/. Assuming you don't already have a .emacs file stored in %APPDATA%/ You can now go ahead and create an init.el file inside the .emacs.d directory. Put some sample configuration in your init.el file and see if Emacs picks it up when you re-start Emacs. Also see this this anwer on Emacs Stackexchange.

Happy Hacking :)

3
  • Thank you for this comprehensive solution, minibuffer. I had wondered one thing though, like NickD I don't know if I have understood the [backspace] instruction, or if it works differently for the Windows default. When I press backspace, it only deletes the tilde. – Georgina Davenport Aug 18 '20 at 2:01
  • Well on my keyboard when I hit backspace on ~ in the minibuffer it expands to show me the absolute path. In any case, you have an alternate way to achieve the same. – minibuffer Aug 18 '20 at 2:36
  • Yes, once you mentioned %APPDATA%, I merely typed echo %APPDATA% on the command line, and on seeing the variable was defined, I did cd %APPDATA% to visit the directory and found the .emacs.d directory there. In it I put the test init.el file you recommended, which contains only (setq initial-scratch-message "Hello from my new init file :)") and I then launched emacs and found the test message in the scratch buffer, confirming the process works, at least for me. Thank you again for your help! – Georgina Davenport Aug 18 '20 at 14:34
2

The variable is user-init-file. Its doc string says:

File name, including directory, of user’s initialization file. If the file loaded had extension ‘.elc’, and the corresponding source file exists, this variable contains the name of source file, suitable for use by functions like ‘custom-save-all’ which edit the init file. While Emacs loads and evaluates any init file, value is the real name of the file, regardless of whether or not it has the ‘.elc’ extension.

EDIT: If the value of the variable is non-nil, as in your case, it means that it actually found the file ~/.emacs somewhere, somehow. I don't know much about Windows, but if you look in what you think is your home directory and cannot find a file called .emacs, it might be that some translation is going on. ISTR, that in some cases, on Windows, the file name was _emacs, but that was a long time ago, in a universe far, far away, and I may very well be wrong.

See if this link helps: it describes how the HOME directory is determined on Windows.

Also, the method that @minibuffer describes in a comment might well be the best way to find the file: do C-x C-f ~/ RET and look at the pathname at the top of the directory listing (this is slightly different from what the comment describes, but I couldn't get the backspace method to work for me: it just deletes the ~ in the prompt - but this is on Linux, and Windows may behave differently).

3
  • Thank you. It says "Its value is "~/.emacs". I have looked in my home directory and I cannot find a file with that name. What does this mean? – Georgina Davenport Aug 14 '20 at 16:30
  • 1
    In addition to my earlier comment you can also do C-x C-f and then ~ and then hit backspace this will expand to show you the absolute path of what emacs means by ~. – minibuffer Aug 14 '20 at 17:35
  • @minibuffer. Yes, I can do that! This is very helpful. Thank you. I can go directly to the directory within emacs without having to search for it. In that directory structure though I still cannot find the init file. Why is this? – Georgina Davenport Aug 14 '20 at 17:42
0

You can create or open an an existing init file when opening ~/.emacs or ~/.emacs.d/init.el. ~ is a macro character which expand to the correct directory. On a fresh install you have to create an init file.

1
  • Your answer may mean currently there is no init file. I didn't create one. I assumed there would be a default copy. Is it reasonable to believe as I haven't created one that there is no emacs init file on my computer? – Georgina Davenport Aug 14 '20 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.