I am trying to have specific settings when I start a new emacs frame in X as opposed to in the terminal while using emacs-server. My initial attempt was using this solution, but it appears it isn't working for me (using Emacs 24.4.1).
Basically, my minimimal non-working example is this:
(defun new-frame-setup (&optional frame)
(if (display-graphic-p)
(message "window system")
(message "not a window system")
))
;; run when regular emacs is started
(new-frame-setup)
;; run when a new frame is created using server
(add-hook 'after-make-frame-functions 'new-frame-setup)
When I start regular emacs and go to my Messages buffer it says:
window system
So this works just as I expected. However, if I run the command emacsclient -c
, the Messages buffer says
not a window system
Starting Emacs daemon
not a window system
The first "not a window system" makes sense, as it's starting the emacs server in the terminal. However, the second one doesn't make sense, as that frame is already a graphical window. Furthermore, after the fact, if I evaluate (display-graphic-p)
in my scratch buffer, it evaluates as t
. Any ideas as to what I'm doing wrong?
EDIT
So the big problem here is not that (display-graphic-p)
doesn't work, it's that it doesn't know what frame to check. This was a problem for me since the daemon didn't have a window-system, but it's an even bigger problem if I have a terminal version and an X version of emacsclient running at the same time. For example, if I create a frame with emacsclient -c
and have it change some settings, and then I create a frame with emacsclient -nw
and have it change some other settings - all of those settings are getting changed at the global level.
So I guess the real question is: how can I get emacs to check the display of the most recently created frame, and then run some elisp code only on that frame? I have absolutely no idea if this is possible.
focus-in-hook
instead. – Kaushal Modi Jul 14 '16 at 19:54focus-in-hook
, it will make it unable to move my window after the fact. – rottweiler Jul 14 '16 at 20:09window-system
instead? – theldoria Jul 14 '16 at 20:11window-system
gives the exact same problem. I useddisplay-graphic-p
because according to the docs "Use of this variable as a boolean is deprecated" – rottweiler Jul 14 '16 at 20:18emacsclient -c myfile
, but without running it with the file argument, it doesn't immediately focus on the new client (so it moves after i click it). Second, this doesn't let me run separate code when i run it in the terminal. Thedisplay-graphic-p
lets me use an if-else to run separate code for the different instances. – rottweiler Jul 14 '16 at 21:07(raise-frame)
in the function. I think the second problem might not be a problem either, since all the "terminal" code will get called whenever i start emacs-server. – rottweiler Jul 14 '16 at 21:15focus-in-hook
is to be used in place ofafter-make-frame-functions
. You still need to usedisplay-graphic-p
to know if you are running in terminal. But thenfocus-in-hook
is not run when you run emacs[client] with -nw. So to cover that case, you need to add your fn toafter-init-hook
. You might also use(daemonp)
to do something like this. <- In this example,after-make-frame-functions
does what I need. – Kaushal Modi Jul 14 '16 at 21:17after-init-hook
so that it gets run every time, and then selectively disable things in myfocus-in-hook
? – rottweiler Jul 15 '16 at 15:35