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

时间:2009-06-24 18:37:45

标签: emacs emacsclient

启动Emacs时,将评估init.el(或.emacs.el)。但是,在启动emacsclient时,不会评估类似的lisp代码。

每次打开新的emacsclient时,如何获得要评估的lisp文件?

(这对于特定于帧的自定义很方便。)

我假设答案是使用一些钩子,但我似乎无法找到正确使用的钩子。

我期待你的回答。

4 个答案:

答案 0 :(得分:16)

您可以向钩子'server-visit-hook添加一个函数,该函数在每次调用服务器时运行(每次调用emacsclient时)。

答案 1 :(得分:7)

我使用以下代码自动更改服务器缓冲区的行为。我特别使用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)))

答案 2 :(得分:5)

如果你真的想要新的框架自定义,那就是create-frame-hook,它需要一个arg(新框架)......

如果您的意思是gnuclient,您可以使用命令行选项“-eval”来评估某些内容(然后只需创建别名以便始终评估您的自定义设置)。

答案 3 :(得分:1)

@LSW:

试试'window-setup-hook。这解决了因为即使emacsclient未传递文件而被调用的烦恼。

相关问题