Emacs 在 Windows 下使用总结

文章目录

  1. 1. HOME
  2. 2. 服务
  3. 3. 右键使用 emacs

Emacs 在 Windows 上使用会遇到各种问题,下面就是对实践中遇到的问题进行的总结,内容将来会有更新。

HOME

这个在 emacs 的说明中有具体章节HOME and Startup Directories on MS-Windows.

The Windows equivalent of HOME is the user-specific application data directory. The actual location depends on the Windows version; typical values are C:\Documents and Settings\username\Application Data on Windows 2000/XP/2K3, C:\Users\username\AppData\Roaming on Windows Vista/7/2008, and either C:\WINDOWS\Application Data or C:\WINDOWS\Profiles\username\Application Data on Windows 9X/ME. If this directory does not exist or cannot be accessed, Emacs falls back to C:\ as the default value of HOME.

HOME 在 windows 上等价于特定用户的应用程序数据路径。这个路径依赖于 windows 版本。

  • Windows 2000/XP/2K3 下是 C:\Documents and Settings\username\Application Data
  • Windows Vista/7/2008/8/10 下是 C:\Users\username\AppData\Roaming
  • Windows 9X/ME 下是 C:\WINDOWS\Application Data 或者 C:\WINDOWS\Profiles\username\Application Data

如果没有这个路径,emacs 会使用 C:\作为缺省 HOME 路径。

HOME 可以通过添加环境变量来进行修改,如果此时系统中如果安装了 cygwin、git 等软件,会影响到它们的使用。

因为 HOME 是存放 init 文件的地方。如果 init 文件在别的目录下,可以在 HOME 中通过创建一个.emacs 文件,指向真正的初始化文件。例如:

(load-file "d:/emacs-24.5/.emacs.d/init.el")

服务

emacs 会在 HOME 中创建一个.emacs.d 目录,如果 emacs 程序在别的路径中有一个.emacs.d,这个.emacs.d 并不起作用。如果 emacs 作为一个服务启动,需要在 init 文件中添加:

(server-start)

会在 HOME/.emacs.d/server 下生成一个 server 文件,这个文件记录了 ip、端口和其它信息。关掉这个服务,这个文件会自动消失。

右键使用 emacs

在注册表中添加以下键值

HKEY_CLASSES_ROOT\*\shell\Edit With Emacs\command

修改 Default 值为:

"d:\emacs-24.5\bin\emacsclientw.exe" --no-wait --alternate-editor="d:\emacs-24.5\bin\runemacs.exe" "%1"
  • –no-wait 告诉 client 不用等到 server 的返回,而是直接退出
  • –alternate-editor 当 server 不存在时,变为使用 runemacs 这个程序去打开文件,即相当于启动了一个 server,当然此时的 init 文件中有`(server-start)`这个语句。

设置成功之后,在需要打开的文件上右键菜单,就会出现 Edit With Emacs 这个菜单项。

参考windows 平台 Emacs 单实例原理、设置及右键菜单的添加.


Render by hexo-renderer-org with Emacs 25.0.50.1 (Org mode 8.2.10)

版权声明

本博客 采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可