如何在启动 emacsclient 后自动评估某些 lisp 代码?
启动 Emacs 时,会评估 init.el(或 .emacs.el)。 然而,当启动 emacsclient 时,不会评估类似的 lisp 代码。
如何在每次打开新的 emacsclient 时评估 lisp 文件?
(这对于特定于框架的自定义非常方便。)
我认为答案是使用一些钩子,但我似乎找不到要使用的正确钩子。
我期待您的答复。
When starting Emacs, init.el (or .emacs.el) is evaluated. However, when starting emacsclient, no similar lisp code is evaluated.
How can I get a lisp file to be evaluated every time I open a new emacsclient?
(This would be handy for frame specific customizations.)
I assume the answer is to use some hook, but I can't seem to find the correct hook to use.
I look forward to your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以向钩子
'server-visit-hook
添加一个函数,该函数在每次调用服务器时(每次调用emacsclient
时)运行。You can add a function to the hook
'server-visit-hook
, which is run every time the server is called (every time you callemacsclient
).我使用以下代码自动更改服务器缓冲区的行为。 我特别将它与 Firefox 扩展 It's All Text 一起使用。 在该扩展中,缓冲区根据域名命名,因此您可以通过使用
string-match
来匹配文件名来确定要应用的规则。I use the following code to automatically change the behavior of server buffers. I use it especially with the Firefox extension It's All Text. In that extension, buffers are named according to the domain name, so you can figure out which rule to apply by using
string-match
to match the name of the file.如果你真的想要新的框架定制,有create-frame-hook,它需要一个arg(新框架)...
如果你的意思是gnuclient,你可以使用命令行选项“-eval”来评估某些东西(然后只是创建别名以始终评估您的自定义)。
If you really want new frame customizations, there's create-frame-hook which takes one arg (the new frame)...
If you mean gnuclient, you can use the command-line option "-eval" to evaluate something (and then just make an alias to always eval your customizations).
@LSW:
尝试
'window-setup-hook
。 这解决了烦恼,因为即使 emacsclient 没有传递文件,它也会被调用。@LSW:
Try
'window-setup-hook
. This addresses the annoyance since it is called even if emacsclient is not passed a file.看来那些钩子已经不复存在了,所以这是新版本。
It seems that those hooks are no more, so here's the new version.