如何在启动 emacsclient 后自动评估某些 lisp 代码?

发布于 2024-07-25 13:56:58 字数 215 浏览 4 评论 0原文

启动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

愛放△進行李 2024-08-01 13:56:58

您可以向钩子 '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 call emacsclient).

盗梦空间 2024-08-01 13:56:58

我使用以下代码自动更改服务器缓冲区的行为。 我特别将它与 Firefox 扩展 It's All Text 一起使用。 在该扩展中,缓冲区根据域名命名,因此您可以通过使用 string-match 来匹配文件名来确定要应用的规则。

(defun server-edit-presets ()
  (cond
   ;; When editing mail, set the goal-column to 72.
   ((string-match "mail\\.google\\.com\\.[0-9a-z]+\\.txt" (buffer-name))
    (longlines-mode-off)
    (auto-fill-mode 1)
    (set-fill-column 72)
    (save-excursion
      ;; Don't know if this is necessary, but it seems to help.
      (set-buffer (buffer-name))
      (goto-char (point-min))
      ;; Replace non-breaking strange space characters
      (while (search-forward (char-to-string 160) nil t)
        (replace-match " "))))))

(add-hook 'server-visit-hook 'server-edit-presets)
(add-hook 'server-visit-hook '(lambda () (longlines-mode 1)))

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.

(defun server-edit-presets ()
  (cond
   ;; When editing mail, set the goal-column to 72.
   ((string-match "mail\\.google\\.com\\.[0-9a-z]+\\.txt" (buffer-name))
    (longlines-mode-off)
    (auto-fill-mode 1)
    (set-fill-column 72)
    (save-excursion
      ;; Don't know if this is necessary, but it seems to help.
      (set-buffer (buffer-name))
      (goto-char (point-min))
      ;; Replace non-breaking strange space characters
      (while (search-forward (char-to-string 160) nil t)
        (replace-match " "))))))

(add-hook 'server-visit-hook 'server-edit-presets)
(add-hook 'server-visit-hook '(lambda () (longlines-mode 1)))
闻呓 2024-08-01 13:56:58

如果你真的想要新的框架定制,有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).

倾听心声的旋律 2024-08-01 13:56:58

@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.

小矜持 2024-08-01 13:56:58

看来那些钩子已经不复存在了,所以这是新版本。

(add-hook 'server-after-make-frame-hook 'consult-recent-file)

It seems that those hooks are no more, so here's the new version.

(add-hook 'server-after-make-frame-hook 'consult-recent-file)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文