简体   繁体   English

有没有办法在emacs启动时指定自定义初始化文件?

[英]is there a way to specify custom init file on emacs startup?

I've tried runemacs --user d:\\path\\to\\init\\.emacs but it gives 我已经尝试过runemacs --user d:\\path\\to\\init\\.emacs但它给出了

Error (initialization): Invalid user name d:\\path\\to\\init\\.emacs

I mean custom file in custom location like on my pendrive etc. and not in my default locations in user folder. 我的意思是自定义位置中的自定义文件,例如我的pendrive等,而不是我在用户文件夹中的默认位置。 I try to create a cmd files with corresponding inits for different configuration. 我尝试为不同的配置创建具有相应init的cmd文件。

I am guessing that your end goal is to run Emacs from a USB drive which you can carry around. 我猜你的最终目标是从USB驱动器运行Emacs,你可以随身携带。 There are two ways to have Emacs start with a different init file: 有两种方法可以让Emacs以不同的init文件启动:

(1) the -q --load way (1)-q --load方式

This is simply to run 这只是为了运行

emacs -q --load path-to-your-init.el

which starts Emacs without any initialization, then loads path-to-your-init.el 它在没有任何初始化的情况下启动Emacs,然后加载path-to-your-init.el

Gotchas of this way: in this case, Emacs doesn't really consider the el file to be an init file, in fact, Emacs hasn't gone through initialization at all, which means the following post-initialization steps are skipped: 有这种方式:在这种情况下,Emacs并不真正认为el文件是一个init文件,事实上,Emacs根本没有经过初始化,这意味着跳过了以下的初始化后步骤:

  • enabling packages, that is, evaluating (package-initialize) 启用包,即评估(package-initialize)

  • running hook after-init-hook , that is, evaluating (run-hooks after-init-hook) 运行hook after-init-hook ,即评估(run-hooks after-init-hook)

You may have to add post-initialization stuff in your alternate init file. 您可能必须在备用init文件中添加初始化后的内容。

Also, Customize interface won't let you save settings if Emacs is started with -q option. 此外,如果使用-q选项启动Emacs,则自定义界面将不允许您保存设置。

(2) the HOME way (2)HOME方式

Create my-emacs.bat with contents: 使用内容创建my-emacs.bat:

set HOME=%~dp0
C:\path-to-your\Emacs\bin\runemacs.exe --xrm "emacs.Background: light green"

When you click on that bat file, Emacs creates folder named .emacs.d not in your usual user directory, but in where the bat file is. 当您单击该bat文件时,Emacs会创建名为.emacs.d文件夹, .emacs.d不是在您的常用用户目录中,而是在bat文件所在的位置。 You can put your own init.el in that .emacs.d folder. 您可以将自己的init.el放在.emacs.d文件夹中。 With this Emacs, evaluating (find-file "~/.emacs.d/init.el") opens your own portable init.el and not the init file in your usual user directory. 使用此Emacs,评估(find-file“〜/ .emacs.d / init.el”)将打开您自己的可移植init.el而不是通常用户目录中的init文件。 You may want to delete the --xrm "emacs.Background: light green" part, I include that because I always forget which Emacs is which. 你可能想要删除--xrm "emacs.Background: light green"部分,我包括那个,因为我总是忘记哪个是Emacs。

Gotchas: this Emacs has its own package directory in its own .emacs.d directory. 问题:这个Emacs在自己的.emacs.d目录中有自己的包目录。 That may or may not be what you want. 这可能是也可能不是你想要的。 If you want to share the package directory, you can change package-user-dir or create a symbolic link to the to-be-shared package directory using Link Shell Extension. 如果要共享包目录,可以使用Link Shell Extension更改package-user-dir或创建指向要共享包目录的符号链接。

Somethings to consider for running Emacs on a USB drive: 在USB驱动器上运行Emacs时需要考虑的事项:

Emacs outsources some of its features to external tools. Emacs将其部分功能外包给外部工具。 Grepping and comparison are outsourced to grep and diff, so you probably have installed at least GnuWin32 Grep and GnuWin32 DiffUtils on your system. Grepping和比较外包给grep和diff,所以你可能已经在你的系统上安装了至少GnuWin32 Grep和GnuWin32 DiffUtils。 And part of spell checking is outsourced to aspell, which is also a separate install. 拼写检查的一部分外包给aspell,这也是一个单独的安装。 Encryption is outsourced to GPG, so Gpg4Win another separate install. 加密外包给GPG,所以Gpg4Win另外另外安装。 For your portable Emacs to have all those features, all those external tools should be on your USB drive as well. 为了让您的便携式Emacs具备所有这些功能,所有这些外部工具也应该在您的USB驱动器上。 Fortunately, GnuWin32 and aspell are portable-friendly. 幸运的是,GnuWin32和aspell都是便携式的。 I don't know if GPG is. 我不知道GPG是不是。 The dependency to external grep may be eliminated if you manage to make versions of lgrep and rgrep that only depend on eshell's own grep, but it seems nobody has done it, so making such lgrep/rgrep is to boldly go where no man has gone before. 如果你设法制作只依赖于eshell自己的grep的lgrep和rgrep的版本,那么对外部grep的依赖可能会被消除,但似乎没有人做过它,所以制作这样的lgrep / rgrep是大胆地去到没有人去过的地方。

You can get help on all of the emacs options by typing emacs --help on the command line. 您可以通过在命令行上键入emacs --help来获取有关所有emacs选项的帮助。 That help shows that --user expect the name of a user, not the path to an elisp file. 该帮助显示--user期望用户的名称,而不是elisp文件的路径。

To load a lisp file at startup you can use the --load option: 要在启动时加载lisp文件,可以使用--load选项:

$ emacs --help
...
--load, -l FILE         load Emacs Lisp FILE using the load function
...

If you want to prevent your default init file from loading, you can use this option: 如果要阻止加载默认的init文件,可以使用此选项:

$ emacs --help
...
--no-init-file, -q          load neither ~/.emacs nor default.el
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM