Emacs version:
I'm using Fira Code font whose ligatures are now supported by Emacs.
To solve this, I used this solution (I think it's not important, just to inform you), say, replacing the ligaturable text with a single large symbol.

However, I use Emacs GUI/Emacs CLI the same often. In CLI, I just have to configure the console's font. Since I use Konsole which supports ligature, I should do nothing with my Emacs. In GUI, I have to do the replacing job.

The solution mentioned above used this code:

;;; Fira code
;; This works when using emacs --daemon + emacsclient
(add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))
;; This works when using emacs without server/client
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")
;; I haven't found one statement that makes both of the above situations work, so I use both for now

But if I'm using emacsclient in CLI, it still replace the symbols, and my console connot display those weired symbols (of course!).
That is to say, the code above will work when I'm using Emacs GUI, and emacsclient in both GUI and CLI.

What I want is, to prevent it from working when using emacsclient+CLI.

What can I do?

Conclusion for impatient answerers

I want to run some elisp code only when using emacsclient with GUI. How can I do it?


It looks like you're not using the frame argument which is passed to after-make-frame-functions.

Try something like this:

;; Per-frame/terminal configuration.
(defun my-frame-behaviours (&optional frame)
  "Make frame- and/or terminal-local changes."
  (with-selected-frame (or frame (selected-frame))
    (when window-system
      ;; Fira code for GUI Emacs frames.
      (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol" frame))))
;; Run now, for non-daemon Emacs...
;; ...and later, for new frames / emacsclient
(add-hook 'after-make-frame-functions 'my-frame-behaviours)

As per glucas's answer, you may want to replace the window-system test with some display-*-p predicate.


You can check display-graphic-p. See Display Feature Testing in the Emacs manual, there are a bunch of other display-*-p predicates for checking what display capabilities are available.

  • Can you check my code with emacsclient? Seems that it doesn't work at all. I've added your code there, but it still doesn't work (in emacsclient + gui, still no ligatures)
    – ice1000
    Dec 10 '17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.