views:

45

answers:

2

Basically I have my Emacs set up so it has a GUI specific elisp, but when starting it in daemon mode this doesn't evaluate. The code is something like:

;; gui.el
(when window-system
  (progn
    ;; do stuff here
    ))

I'd like this file (or at least the code within it—perhaps a funtion) to be re-evaluated when I run emacsclient -c on the command line, as I miss out on all my font-lock and color-theme goodness (as I have that stuff set to runonly when a GUI exists).

A: 

You should evaluate your GUI function when starting emacsclient:

emacsclient -c --eval "(your-gui-init-function)"
Achim Tromm
+2  A: 

You can put your code in a hook to be called before a frame is created

(add-hook 'before-make-frame-hook 'my-gui-initialization-stuff)

In that hook you probably want to have a line that does

(remove-hook 'before-make-frame-hook 'my-gui-initialization-stuff)

so you don't do the initialization over and over.

Trey Jackson
Using frame hooks may not be good idea in this scenario, because they get called for text based frames as well... Some additional checks should be added at least and even then if one uses simultaneously X and text based clients chaos may ensue with stuff like color-theme for example.
Bozhidar Batsov
I'm already verifying whether it's a window system or not, so I think this is alright.
Brad Wright
Thanks Trey, this is great!
Brad Wright