Different themes for terminal and graphical frames when using Emacs daemon

2018-05-23 00:04:25

I'm trying to achieve the following behavior in Emacs24:

I like to use a different theme (solarized-dark vs. solarized-light) depending on whether I connect to the running

server with a terminal frame

% emacsclient -t

or with a gtk frame

% emacsclient -c

This seems to have worked in older Emacs, but the current Emacs I couldn't find a way. I alreday checked SO (e.g., https://stackoverflow.com/q/18904529/152439 and answers) and the mailing lists (e.g., https://lists.gnu.org/archive/html/help-gnu-emacs/2012-02/msg00227.html and https://lists.gnu.org/archive/html/help-gnu-emacs/2012-02/msg00237.html).

My current setup looks like this:

(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/solarized")

(if (daemonp)

(add-hook 'after-make-frame-functions

(lambda (frame)

(select-frame frame)

(if (display-graphic-p frame)

(load-theme 'solarized-light t)

(load-theme 'solarized-dark t)

)

)

)

(load-theme 'solarized-light t)

  • You cannot do this using different themes. The solution is to create a theme that has different face definitions depending on the terminal. If you look at an example like font-lock-comment-face, you'll see how it works. Instead of specifying ((class color) (min-colors 88) (background dark)) you could also specifcy (type tty) or (type graphic) etc. The manual has more info.

    (defface font-lock-comment-face

    '((((class grayscale) (background light))

    :foreground "DimGray" :weight bold :slant italic)

    (((class grayscale) (background dark))

    :foreground "LightGray" :weight bold :slant italic)

    (((class color) (min-colors 88) (background light))

    :foreground "Firebrick")

    (((class color) (min-colors 88) (background dark))

    :foreground "chocolate1")

    (((class color) (min-colors 16) (background light))

    :foreground "red")

    (((class color) (min-colors 16) (background dark))

    :foreground "red1")

    (((class color) (min-colors 8) (background light))

    :foreground "red")

    (((class color) (min-colors 8)

    2018-05-23 00:18:53
  • color-theme-buffer-local provides buffer-local theme support for both color-theme and the Emacs 24 theme systems. My version of the solarized theme also supports both systems, if you decide to go this route.

    2018-05-23 00:49:41
  • You can define conditions for face customizations, like "terminal mode" or "minimal colors" in the customization editor:

    When customizing a face, click the [State] button and select "Show all display specs". Then you can set up the conditions for further specialization of the face.

    2018-05-23 01:36:05