Homebrew-emacs-plus: System appearance change patch conflict with posframe

Created on 22 Jun 2020  ·  6Comments  ·  Source: d12frosted/homebrew-emacs-plus

I'm using ivy with ivy-posframe. If I add the random choice theme function to ns-system-appearance-change-functions, every time I run M-x the theme is changed.

config to reproduce:

;;; emacs -nw -Q -l ~/.emacs.d/test.el

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org"   . "https://orgmode.org/elpa/")
                         ("gnu"   . "https://elpa.gnu.org/packages/")))

;; initialize packages
(unless (bound-and-true-p package--initialized) ; To avoid warnings in 27
  (setq package-enable-at-startup nil)          ; To prevent initializing twice
  (package-initialize))

;; setup `use-package'
(unless (package-installed-p 'use-package)
  (when (not package-archive-contents)
    (package-refresh-contents))
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(use-package ivy
  :ensure t
  :config (ivy-mode))

(use-package ivy-posframe
  :ensure t
  :config (ivy-posframe-mode 1))

(use-package doom-themes :ensure t)

(defvar light-themes '(doom-acario-light
                       doom-nord-light
                       doom-one-light
                       doom-opera-light
                       doom-solarized-light
                       doom-tomorrow-day)
  "Light themes to switch.")

(defvar dark-themes '(doom-acario-dark
                      doom-nord
                      doom-one
                      doom-opera
                      doom-solarized-dark
                      doom-tomorrow-night
                      doom-dark+
                      doom-ephemeral
                      doom-Iosvkem
                      doom-material
                      doom-moonlight
                      doom-nova
                      doom-oceanic-next
                      doom-palenight
                      doom-peacock
                      doom-rouge
                      doom-sourcerer
                      doom-spacegrey
                      doom-wilmersdorf
                      doom-vibrant)
  "Dark themes to switch.")

(add-hook 'ns-system-appearance-change-functions
          #'(lambda (appearance)
              (print appearance)
              (mapc #'disable-theme custom-enabled-themes)
              (pcase appearance
                ('light (load-theme (seq-random-elt light-themes) t))
                ('dark (load-theme (seq-random-elt dark-themes) t)))))

GNU Emacs 27.0.91 (build 1, x86_64-apple-darwin19.5.0, NS appkit-1894.50 Version 10.15.5 (Build 19F101)) of 2020-06-20

Most helpful comment

Took some more testing than I thought, but the PR sits at #242. I verified the fix using the provided test.el config file.

All 6 comments

If I replace load-theme to just print, this will not run every time I call M-x (only the first time after I startup Emacs)

Hello @tshu-w

Thank you very much for such a detailed issue report. @ngquerol can you please take a look?

Will take a look soon, hopefully tomorrow.

Sorry for the issues in the meantime ! 🙇🏻‍♂️

Alright, it was actually a rather simple bug, and could have been completely avoided had I been a {helm,ivy}-posframe user.

The problem was that the hook was effectively run on every child frame creation, caused by each call to ivy/counsel via M-x with the ivy-posframe package installed. As the fix is really simple, I'll try to make a PR to update the emacs 28 & 27 patches tonight.

Took some more testing than I thought, but the PR sits at #242. I verified the fix using the provided test.el config file.

@tshu-w thanks to @ngquerol , the fix is in the master, please try it and let us know if something is amiss.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulhenrich picture paulhenrich  ·  8Comments

d12frosted picture d12frosted  ·  5Comments

d12frosted picture d12frosted  ·  8Comments

d12frosted picture d12frosted  ·  6Comments

frankjonen picture frankjonen  ·  3Comments