#+TITLE: Sacha Chua's Emacs configuration
#+ELEVENTY_COLLECTIONS: _posts
#+ELEVENTY_BASE_DIR: ~/proj/static-blog/
#+ELEVENTY_CATEGORIES+: emacs
#+ELEVENTY_LAYOUT: layouts/post
#+ELEVENTY_BASE_URL: https://sachachua.com
* Making highlight-sexp follow modus-themes-toggle              :elisp:emacs:
:PROPERTIES:
:EXPORT_DATE: 2023-01-26T10:25:38-0500
:EXPORT_ELEVENTY_PERMALINK: /blog/2023/01/making-highlight-sexp-follow-modus-themes-toggle/
:EXPORT_ELEVENTY_FILE_NAME: blog/2023/01/making-highlight-sexp-follow-modus-themes-toggle/
:CUSTOM_ID: making-highlight-sexp-follow-modus-themes-toggle
:EXPORT_MODIFIED: 2026-06-18T09:59:49-0400
:END:

#+begin_update
- [2026-06-18]: I think I'll stop using highlight-sexp for now. It's a little finicky when I change themes.
- [2023-01-27 Fri] Prot just added a [[https://github.com/protesilaos/modus-themes/commit/0ca79257ef941ff5f9ec34f5d76eed2ff35d7752][modus-themes-get-color-value]]
function. Yay! Also, it turns out that I need to update the overlay in
all the buffers.
#+end_update

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:

#+begin_src emacs-lisp :tangle lisp/sacha-appearance.el
(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)))))
#+end_src

#+begin_src emacs-lisp
  (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))
#+end_src

This is what it looks like:

#+CAPTION: Animation of highlight-sexp toggling along with modus-themes-toggle
[[file:images/highlight-sexp.gif]]

