3

Overriding part of an Emacs theme

 3 years ago
source link: https://www.eigenbahn.com/2020/04/06/emacs-theme-override
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Overriding part of an Emacs theme

April 6, 2020

Introduction

Like most sane people, I don’t use Emacs’ default theme but instead rely on custom themes.

Through a thoughtful choice of colors, the venerable editor can feel like a modern beast (or a retro oddity if that’s what you’re into).

I cycle through several themes but my current favorite is chocolate. I def’ recommend it: very easy on the eyes and yummy 🍫.

Other favorites are white-sand, dracula and for a more retro vibe comidia.

A matter of taste

I really love the themes I use. At least 95% of them.

But there are several discrepancies between them that annoy me:

  • whether variable pitch is on for outlines
  • whether different outline levels have different colors
  • mode-line look: either “box” or “flat”
  • active buffer mode-line not standing out sufficiently
  • face form-feed-line (for ^L character) not of the same color as comments
  • show-paren-* faces colors not standing out
  • region color too close to hl-line and / or cursor

Yeah, I’m a picky dude.

The way I used to deal with this was by forking the themes and maintaining my own versions.

But this was cumbersome and I had the feeling there was a better way.

Enters Spacemacs

I stumbled on this blog post about beautifying org-mode on Abhinav Tushar’s blog and realized that Spacemacs has “native” theme override capabilities.

Once I discovered this I decided to switch to Spacemacs delve into Spacemacs source code to find out how it’s done.

It appears that the outer part of Spacemacs’ code is divided into special kinds of packages called layers (as opposed to the core part).

The theme override code is provided by the theming layer (code) and the trick seems to be to call custom-set-faces.

Porting to vanilla Emacs 🍦

I could have called custom-set-faces directly from my init.el but got a better idea.

Why not reuse the same format as Spacemacs for defining theme overrides?

And why not just simply port the whole layer to vanilla Emacs as regular package?

As it turns out, it was pretty trivial to do.

Introducing new package: space-theming.

Also please note for Emacs 27 users, you might have to set the following:

(setq custom--inhibit-theme-enable nil)

Bonus example

As a bonus here is my setup for chocolate-theme:

(setq space-theming-modifications
      '((chocolate
         ;; strawberry active region
         (region :background "#C77497" :foreground "black")

         (show-paren-match :background "white" :foreground "black")
         (show-paren-mismatch :background "red" :foreground "white")

         ;; active / inactivate buffer mode-line
         (mode-line :background "#594A3B") ; chocolate-dark-yellow
         (mode-line-inactive :background "#2b241d") ; darker derivative of chocolate-dark-yellow

         (fringe :background "#2b241d") ; same as mode-line-inactive

         ;; ^L are comments
         (form-feed-line :strike-through "#705B5F") ;; :foreground of `font-lock-comment-delimiter-face'

         ;; babel
         (org-block :inherit default)
         (org-block-begin-line :foreground "#594A3B")
         (org-block-end-line :foreground "#594A3B")

         ;; dired
         (dired-directory :foreground "#EAEAFE") ; chocolate-hue-2

         ;; bookmarks
         (bmkp-local-directory :foreground "#45AFBD")
         (bmkp-remote-file :foreground "#C55D67")))
chocolate theme overrides

You can see my customization on the left VS the default faces on the right.

Please note:

  • it’s way clearer that the bottom buffer is the active one
  • the region went from “I’m a ninja and want to look the same as a mode-line” to “Hey look at me!”.
  • the unobtrusive form feed in the top buffer

Tagged #emacs.



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK