notes from /dev/null

by Charles Choi 최민수


04 Jun 2023

Automatically adjusting Emacs to macOS switches in appearance

Count me among those who likes using the Auto setting when adjusting the appearance in macOS to either light or dark. Native macOS apps that are coded accordingly can automatically adjust as well, and it turns out that the Yamamoto Mitsuharu fork of Emacs (aka emacs-mac-app) can do this too. But with emacs-mac-app, just because it can detect the appearance change doesn’t mean that all the themes or faces will adjust accordingly too. As such it is typically up to the user to write a pair of custom light and dark mode functions to invoke when the appearance change happens.

For quite some time I’ve been calling these appearance mode functions manually like an animal. Then I recently learned that mac-effective-appearance-change-hook is a thing.

This hook gets invoked upon a macOS appearance change, so it becomes straightforward to write a hook function that tests for the :appearance property returned by
(mac-application-state).

1
2
3
4
5
6
7
(defun cc/reconfigure-nsappearance ()
  (let ((appearance (plist-get (mac-application-state) :appearance)))
    (if (string-equal appearance "NSAppearanceNameDarkAqua")
        (cc/dark-mode)
      (cc/light-mode))))

(add-hook 'mac-effective-appearance-change-hook 'cc/reconfigure-nsappearance)

A caveat though: the above code will only work with the Yamamoto fork of Emacs for macOS. As of now there seems to be no consensus on how to handle OS-level appearance changes by Emacs core. That said, if the above works for you, then no more manual appearance change calls!

References

emacs   dev   elisp   software   macos

Past Articles

26
MAY
2023

My Emacs Config Repo

My Emacs config pushed up on GitHub.

read more
22
MAY
2023

Captee 1.1.0 update now available on the App Store

Captee v1.1.0 is a major release. Export of formatted text to Markdown and Org is now supported!

read more
21
MAY
2023

The sad state of the Twitch app on Apple TV

Twitch could do better. They won't.

read more
10
APR
2023

Captee available on the Mac App Store

Captee available on the Mac App Store. Go get it.

read more
10
MAR
2023

Introducing Captee alpha, looking for testers

Introducing Captee, a macOS utility app to share links and content via the macOS Share menu. It's in alpha now, but I'm looking for testers.

read more
5
MAR
2023

What happened to February?

And just like that, it's here and gone.

read more
27
JAN
2023

Beautifying Org Plot with YASnippet and Context Menus

Org Plot in Emacs can be made beautiful and easy to use using YASnippet and Context Menu mode. This post shows you how.

read more
23
JAN
2023

How I Personally Use Mobile Computing in 2023

Some musings on how I use mobile computing in 2023.

read more
3
JAN
2023

Customizing the Emacs Context Menu

Novice Elisp programmer (me) succeeds in customizing Emacs right mouse button menu behavior. Uses this knowledge to copy common actions seen in native (in particular macOS) applications.

read more

Page 1 / 8   >

 

About | Mastodon | Instagram | GitHub

Powered by Pelican