views:

205

answers:

3

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.

+3  A: 

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

mike
+6  A: 

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

Trey Jackson
+1  A: 

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