Making highlight-sexp follow modus-themes-toggle

Posted: - Modified: | elisp, emacs
  • : I think I'll stop using highlight-sexp for now. It's a little finicky when I change themes.
  • Prot just added a modus-themes-get-color-value

function. Yay! Also, it turns out that I need to update the overlay in all the buffers.

I'm experimenting with using the highlight-sexp minor mode to highlight my current s-expression, since I sometimes get confused about what I'm modifying with smartparens. The highlight-sexp background colour is hardcoded in the variable hl-sexp-background-color, and will probably look terrible if you use a light background. I wanted it to adapt when I use modus-themes-toggle. Here's how that works:

(defun sacha-hl-sexp-update-overlay ()
  (when (overlayp hl-sexp-overlay)
    (overlay-put
     hl-sexp-overlay
     'face
     `(:background
       ,(modus-themes-get-color-value 'bg-inactive)))))
(defun sacha-hl-sexp-update-all-overlays (&rest args)
  (interactive)
  (dolist (buf (buffer-list))
    (with-current-buffer buf
      (when highlight-sexp-mode
        (sacha-hl-sexp-update-overlay)))))
  (use-package highlight-sexp
    :vc (:url "https://github.com/daimrod/highlight-sexp")
    :after modus-themes
    :hook
    ((emacs-lisp-mode . highlight-sexp-mode)
     (modus-themes-after-load-theme . sacha-hl-sexp-update-all-overlays))
    :config
    (advice-add 'hl-sexp-create-overlay :after 'sacha-hl-sexp-update-overlay))

This is what it looks like:

highlight-sexp.gif
Figure 1: Animation of highlight-sexp toggling along with modus-themes-toggle
This is part of my Emacs configuration.
View Org source for this post
You can view 2 comments or e-mail me at sacha@sachachua.com.

2 comments

Christian Tietze

2023-01-27T07:52:16Z

The way you get the color looked interesting, but modus-themes--current-theme-palette appears to be gone in v4.

So when you migrate to the new version, you'll be looking for a lot of (modus-themes-with-colors ... ,bg-inactive) macro calls :)

Even better, Prot added a function for getting a color. =) Yay!