How to automatically evaluate certain lisp code after starting an emacsclient?

白昼怎懂夜的黑 提交于 2019-11-28 23:27:03

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

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)))

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:

Try 'window-setup-hook. This addresses the annoyance since it is called even if emacsclient is not passed a file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!