Emacs can't write to its own init file on Windows 10 - Emacs Stack Exchange most recent 30 from emacs.stackexchange.com 2019-09-21T13:12:01Z https://emacs.stackexchange.com/feeds/question/24160 https://creativecommons.org/licenses/by-sa/4.0/rdf https://emacs.stackexchange.com/q/24160 0 Emacs can't write to its own init file on Windows 10 Frunobulax https://emacs.stackexchange.com/users/12475 2016-06-24T07:17:25Z 2018-02-09T21:05:11Z <p>I have been using Emacs on Windows for decades now and it essentially always worked fine except for minor annoyances. However, I recently had to buy a new machine with Windows 10 (the last Windows I used Emacs on was Win7) and now I'm in the strange situation that Emacs can't write to <code>~/.emacs</code> anymore. Whenever I try to do that, I get a message about wrong file permissions. If I then close and restart Emacs, it can't even <em>read</em> the file anymore, so I have to fix the permissions (which I usually do with Cygwin). To be clear: The file permissions are fine <em>before</em> Emacs tries to write to <code>~/.emacs</code>, but then Emacs itself somehow messes up and as a result it can't read or write the file anymore.</p> <p>I have "fixed" the problem for now by renaming the file to <code>~/_emacs</code>, but I'd like to know what the reason for this behavior is. (And in the long run I'd like to get rid of the warning message that the underline is deprecated...)</p> <p>Emacs version is: GNU Emacs (x86_64-w64-mingw32) of 2016-05-26</p> <p>(I'm also using Emacs via a pretty old version of gnuserv in case that matters.)</p> https://emacs.stackexchange.com/questions/24160/emacs-cant-write-to-its-own-init-file-on-windows-10/24199#24199 2 Answer by Kevin for Emacs can't write to its own init file on Windows 10 Kevin https://emacs.stackexchange.com/users/11645 2016-06-26T18:23:29Z 2016-06-26T18:23:29Z <p>I've been running Emacs 22 and 24.4 on Windows 10 for years, without problems writing the init file. The doc says that Emacs searches for ~/.emacs, ~/.emacs.el, and ~/.emacs.d/init.el, in that order.</p> <p>On Windows, ~ (the HOME environment variable) is not defined by default, so you must define it through Control Panel, System, Environment Variables, if you want to use those locations.</p> <p>Otherwise, by default, Emacs 22 and 24 will search in /Users/name/AppData/Roaming/ for .emacs.</p> <p>I do know that trying to save files to Windows (all versions) from Emacs often requires using double backslashes in the pathnames that you formulate in code. I've found that double backslashes are the only trustworthy way.</p> <p>So to answer your question, I can assert:</p> <ul> <li><p>Windows 10 is capable of .emacs filenames, you don't require _emacs.</p></li> <li><p>Windows 10 is capable of .emacs, in both HOME=/users/name/.emacs form, and in the AppData/Roaming/.emacs form. I don't like the AppData/Roaming location, because /users/name/AppData is a hidden directory on Windows, which makes it awkward to work with.</p></li> <li><p>You might check to see if you have a HOME environment variable defined, and what it points to (maybe a location with bad permissions?). You might check your /users/name/AppData/Roaming/.emacs path for permissions all the way down, too. (The original post doesn't exactly specify the HOME part of the ~/ references.)</p></li> <li><p>This might sound awful (but it has happened to me), but you might check to see that you have exactly 1 startup file, in exactly 1 location, and that your main init file code doesn't reference or reload any other .emacs files from any other places. I use three machines (win10, win10, Mac OSX, and share almost everything through Dropbox), and when installing new versions of Emacs I sometimes end up referencing old files, in old locations.</p></li> </ul> <p>One of the handiest tips I can pass on for this particular problem is to color the background a different color in the init file, as the first line. Then if you see unexpected colors, you will know you're not picking up (or trying to write out--yes, that's happened to me too) the wrong .emacs file.</p> <p>Now my policy is to have .emacs files with only 1 line in them -- and it loads the big shared init file where I look at machine types and do machine-specific setups. That might work for you too, since then your .emacs file won't change much at all, for the life of the machine. Only the big shared (ie, secondary) init file will be regularly modified, and that can be located anywhere you like.</p> <p>Hopefully some of this might help. Good luck!</p> https://emacs.stackexchange.com/questions/24160/emacs-cant-write-to-its-own-init-file-on-windows-10/38729#38729 0 Answer by James P. for Emacs can't write to its own init file on Windows 10 James P. https://emacs.stackexchange.com/users/18454 2018-02-09T21:05:11Z 2018-02-09T21:05:11Z <p>Try setting the HOME environment variable explicitly.</p> <p>Under Windows 10 my emacs wouldn't read the .emacs file in my HOME directory until I set HOME to C:\Users\James</p> <p>Now it works.</p> <p>Right click "This PC" on desktop, select "Properties", click "Advanced system settings", Click "Environment Variable", click "New" under the upper window, Enter "HOME" in the "Variable name" box, and enter "C:\Users\YOUR_NAME" in the "Variable value" box. Click "OK" and you're good to go.</p>