在哪里可以找到在 Windows 上运行的 Emacs 的 .emacs 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/189490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where can I find my .emacs file for Emacs running on Windows?
提问by Ray
I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?
我尝试为 Emacs 的 Windows 安装寻找 .emacs 文件,但我找不到它。Windows 下的文件名是否与 Unix 中的文件名相同?
Do I have to create it myself? If so, under what specific directory does it go?
我必须自己创建吗?如果是这样,它在哪个特定目录下?
采纳答案by Node
Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:
从 Emacs FAQ 中复制并粘贴,http: //www.gnu.org/software/emacs/windows/ :
Where do I put my init file?
我在哪里放置我的 init 文件?
On Windows, the .emacs
file may be called _emacs
for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el
. Many of the other files that are created by Lisp packages are now stored in the .emacs.d
directory too, so this keeps all your Emacs related files in one place.
在 Windows 上,为了与 DOS 和 FAT 文件系统(文件名不能以点开头)向后兼容,.emacs
可能会调用该文件_emacs
。一些用户更喜欢继续使用这样的名称,因为 Windows 资源管理器无法创建名称以点开头的文件,即使文件系统和大多数其他程序可以处理它。在 Emacs 22 及更高版本中,init 文件也可能被称为.emacs.d/init.el
. Lisp 包创建的许多其他文件现在也存储在该.emacs.d
目录中,因此这将所有与 Emacs 相关的文件保存在一个地方。
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
上面提到的所有文件都应该放在您的 HOME 目录中。HOME 目录通过以下步骤确定:
- If the environment variable HOME is set, use the directory it indicates.
- If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
- If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
- If
C:\.emacs
exists, then useC:/
. This is for backward compatibility, as previous versions defaulted toC:/
if HOME was not set. - Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
- 如果设置了环境变量 HOME,请使用它指示的目录。
- 如果设置了注册表项 HKCU\SOFTWARE\GNU\Emacs\HOME,请使用它指示的目录。
- 如果设置了注册表项 HKLM\SOFTWARE\GNU\Emacs\HOME,请使用它指示的目录。不推荐,因为它会导致用户共享相同的 HOME 目录。
- 如果
C:\.emacs
存在,则使用C:/
. 这是为了向后兼容,因为C:/
如果未设置 HOME ,以前的版本默认为。 - 使用用户的AppData目录,通常是用户配置文件目录下的Application Data目录,其位置根据Windows版本和计算机是否属于域而有所不同。
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
.
在 Emacs 中,~
文件名的开头会扩展到您的 HOME 目录,因此您始终可以找到带有 .emacs 文件的 .emacs 文件C-x C-f ~/.emacs
。
There's further information at HOME and Startup Directories on MS-Windows.
在HOME 和 MS-Windows 上的启动目录中有更多信息。
回答by gone
It should be stored in the variable user-init-file. Use C-H v user-init-file RET
to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET
它应该存储在变量 user-init-file 中。使用C-H v user-init-file RET
检查。也可以直接使用打开M-x eval-expression RET (find-file user-init-file) RET
回答by sverrejoh
Open the file like this in Emacs for Windows:
在 Emacs for Windows 中打开这样的文件:
C-x C-f ~/.emacs
More information in the Emacs Wiki
Emacs Wiki中的更多信息
回答by Alexander Kojevnikov
On my Vista box it's in C:\Users\<USER>\AppData\Roaming\
在我的 Vista 盒子上,它在 C:\Users\<USER>\AppData\Roaming\
回答by user3020269
Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs
and create the file.
请注意,仅键入Ctrl-x Ctrl-f ~/.emacs
和创建文件可能还不够。
It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.
可能是您的 Emacs 应用程序使用不同的位置来存储您的 init 文件,如果是这样,那么创建文件 ~/.emacs 只会创建一个您的 Emacs 应用程序忽略的无用文件。
Also, you may want to do more than just accessthe .emacs init file, but you may want to know where it is, i.e., its pathname.
此外,您可能想做的不仅仅是访问.emacs init 文件,而且您可能想知道它在哪里,即它的路径名。
To get at this there are two methods:
要解决这个问题,有两种方法:
Easy way: type Ctrl+ HVuser-init-file Return
简单的方法:输入Ctrl+HV用户初始化文件Return
Slightly trickier way: You can find out where your system is storing its own .emacs file by:
稍微棘手的方法:您可以通过以下方式找出系统存储其自己的 .emacs 文件的位置:
- Click options and scroll down to "Set Default Font..."
- Change the font setting and click okay
- On the options menu, go down to "Save Options"
- When the options are saved, the system saves its .emacs file, and you can read the file pathin the minibuffer at the bottom of the Emacs screen
- 单击选项并向下滚动到“设置默认字体...”
- 更改字体设置并单击确定
- 在选项菜单上,转到“保存选项”
- 选项保存后,系统会保存其.emacs文件,您可以在Emacs屏幕底部的minibuffer中读取文件路径
回答by caisah
In Windows 7 put your init.el
file in C:\Users\user-name\AppData\Roaming\.emacs.d\
, where user-nameis your user/login folder.
在 Windows 7 中,将您的init.el
文件放在 中 C:\Users\user-name\AppData\Roaming\.emacs.d\
,其中用户名是您的用户/登录文件夹。
Take care so your init.el
file won't be named init.el.txt
. This is something Windows does if you create your file with some editor like Notepad.
请注意init.el
不要将您的文件命名为init.el.txt
. 如果您使用记事本等编辑器创建文件,Windows 就会这样做。
回答by Gauthier
On versions of Emacs on Windows above 22, it seems to have moved to
在 22 以上的 Windows 上的 Emacs 版本上,它似乎已经转移到
~/.emacs.d/init.el
, ~
being the value of your environment variable HOME (see Control Panel → System→ Advanced→ Environment variables).
,~
作为您的环境变量 HOME 的值(请参阅控制面板 →系统→高级→环境变量)。
The file itself might not exist. In that case just create it.
文件本身可能不存在。在这种情况下,只需创建它。
回答by PatS
You must create an emacs initialization file. One is not automatically created. I had a similar issue and this answer tracks down what I did.
您必须创建一个 emacs 初始化文件。一个不是自动创建的。我有一个类似的问题,这个答案追踪了我所做的。
My issue was my ~/.emacs.el
file was not loading. Strange because this has always worked for me.
我的问题是我的~/.emacs.el
文件没有加载。奇怪,因为这一直对我有用。
This question/answer helped me but I had to put my init file in the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
because this is apparently the default behavior on Windows.
这个问题/答案对我有帮助,但我不得不将我的 init 文件放在 中,%USERPROFILE%\AppData\Roaming\.emacs.d\init.el
因为这显然是 Windows 上的默认行为。
To troubleshoot this, I ran the following in the emacs *scratch*buffer.
为了解决这个问题,我在 emacs *scratch*缓冲区中运行了以下命令。
user-emacs-directory
"~/.emacs.d/"
When I saw user-emacs-directory
was ~/.emacs.d
, I simply moved my .emacs.el file to %USERPROFILE%\.emacs.d\init.el
. But this still didn't work.
I continued with expand-file-name
as shown below:
当我看到isuser-emacs-directory
时~/.emacs.d
,我只是将我的 .emacs.el 文件移动到%USERPROFILE%\.emacs.d\init.el
. 但这仍然没有奏效。我继续expand-file-name
如下所示:
(expand-file-name user-emacs-directory)
"c:/Users/pats/AppData/Roaming/.emacs.d/"
Got to love how Windows works. (not) So I moved my emacs.el
file to the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
and this worked. The file was now being read. But I got other errors because my initialization file loaded other (personal emacs) files (in ~/myenv/emacs/*.el
.
必须喜欢 Windows 的工作方式。(不是)所以我将我的emacs.el
文件移到了%USERPROFILE%\AppData\Roaming\.emacs.d\init.el
并且这有效。现在正在读取文件。但是我遇到了其他错误,因为我的初始化文件加载了其他(个人 emacs)文件(在~/myenv/emacs/*.el
.
Warning (initialization): An error occurred while loading ‘c:/Users/pats/AppData/Roaming/.emacs.d/init.el':
Hum... Seems like all my files ~/myenv/emacs/*.el
would need to be moved in order for this to work but I didn't want to do that. Then I realized that because the HOME environment variable was not set, emacs was performing its default behavior.
嗯...似乎我的所有文件~/myenv/emacs/*.el
都需要移动才能使其正常工作,但我不想这样做。然后我意识到因为 HOME 环境变量没有设置,emacs 正在执行它的默认行为。
SOLUTION
解决方案
Once I set my windows HOME
environment variable to %USERPROFILE%
everything began to work like it has for the past 25 years. :-)
一旦我将 WindowsHOME
环境变量设置为%USERPROFILE%
一切,就开始像过去 25 年一样工作。:-)
To set the HOME environment variable, I typed WindowsKey+"edit environment variables for your account" to open the Environment Variablesdialog box, and entered HOME=%USERPROFILE%
.
要设置 HOME 环境变量,我键入 WindowsKey+“为您的帐户编辑环境变量”打开环境变量对话框,然后输入HOME=%USERPROFILE%
.
Now my emacs initialization file .emacs.el is is back to its rightful place $HOME/.emacs.el
and not in %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
现在我的 emacs 初始化文件 .emacs.el 回到了它应有的位置,$HOME/.emacs.el
而不是在%USERPROFILE%\AppData\Roaming\.emacs.d\init.el
To be fair, if Windows had just one place to put files for user installed packages the solution of making HOME=%USERPROFILE\AppData\Roaming
might be acceptable, but because some applications use %USERPROFILE%
, some use %USERPROFILE\AppData\Roaming
and others use %USERPROFILE\AppData\Local
it just makes it difficult to know where to find your configuration files.
公平地说,如果 Windows 只有一个地方为用户安装的软件包放置文件,那么制作 HOME= 的解决方案%USERPROFILE\AppData\Roaming
可能是可以接受的,但是因为某些应用程序使用%USERPROFILE%
,有些应用程序%USERPROFILE\AppData\Roaming
和其他应用程序使用%USERPROFILE\AppData\Local
它只会让您很难知道在哪里可以找到您的配置文件。
I prefer having everything in my %USERPROFILE% or $HOME directory.
我更喜欢将所有内容都放在我的 %USERPROFILE% 或 $HOME 目录中。
Another similar question was here:
另一个类似的问题在这里:
回答by ex_
On Emacs 23 and Windows 7 it only works if you set:
在 Emacs 23 和 Windows 7 上,它仅在您设置时才有效:
HKCU\SOFTWARE\GNU\Emacs\HOME
回答by phils
As kanja answered, the path to this file is stored in the user-init-file
variable (or if no init file exists, the variable contains the default value for where to create it).
正如 kanja 回答的那样,该文件的路径存储在user-init-file
变量中(或者,如果不存在 init 文件,则该变量包含创建它的位置的默认值)。
So regardlessof which of the possible init file names you are using, and which directory it is in, you should be able to visit your init file with:
因此,无论您使用的是哪个可能的 init 文件名,以及它在哪个目录中,您都应该能够使用以下命令访问您的 init 文件:
M-:(find-file user-init-file)
RET
M-:(find-file user-init-file)
RET
Or display its full path in the echo area with:
或在回声区域显示其完整路径:
M-:(expand-file-name user-init-file)
RET
M-:(expand-file-name user-init-file)
RET