Take the 2-minute tour ×

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
    ;; do stuff here

I'd like this file (or at least the code within it—perhaps a function) 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).

share|improve this question
It begs the question, why have that stuff wrapped in the (when window-system ...) the daemon mode should handle that just fine. So I'd try removing the check. Also, the (progn ...) is unnecessary inside the when. –  Trey Jackson Mar 30 '10 at 21:23
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
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 Mar 31 '10 at 8:05
I'm already verifying whether it's a window system or not, so I think this is alright. –  Brad Wright Apr 1 '10 at 20:10
Thanks Trey, this is great! –  Brad Wright Apr 1 '10 at 20:10
add comment

You should evaluate your GUI function when starting emacsclient:

emacsclient -c --eval "(your-gui-init-function)"
share|improve this answer
add comment

Your Answer


