Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't work on macOS #69

Closed
LionyxML opened this issue Sep 27, 2024 · 1 comment
Closed

Won't work on macOS #69

LionyxML opened this issue Sep 27, 2024 · 1 comment

Comments

@LionyxML
Copy link
Owner

LionyxML commented Sep 27, 2024

Annotating here to keep debuging later.

Using emacs-plus formulae on macOS Sonoma, both 29 and 30 versions.
Using emacs-mac formulae, 29.

Auto dark won't eval (M-x auto-dark-mode) || inside the .el file, M-x eval-buffer.

On the same versions (29 and 30). This does not happen on Linux, hence why I only found it now 🤦.

Config:

(use-package auto-dark
  :ensure t
  :custom
  (auto-dark-themes '((doom-gruvbox) (doom-gruvbox-light)))
  :init
  (auto-dark-mode))

Debug on (M-x auto-dark-mode)

Debugger entered--Lisp error: (void-function auto-dark--check-and-set-dark-mode)
  auto-dark--check-and-set-dark-mode()
  #f(compiled-function (symbol value) #<bytecode -0x1b66f97efecd9a2b>)(auto-dark-themes nil)
  custom-initialize-reset(auto-dark-themes (funcall #'#f(compiled-function () #<bytecode 0x18c000ae69414>)))
  custom-declare-variable(auto-dark-themes (funcall #'#f(compiled-function () #<bytecode 0x18c000ae69414>)) "The themes to enable for dark and light modes.\nThe default is to use the themes in `custom-enabled-themes', but that only works\nif the themes are aware of `frame-background-mode', which many aren’t.\n\nIf your themes aren’t aware of `frame-background-mode' (or you just prefer\ndifferent themes for dark and light modes), you can set explicit lists of themes\nfor each mode. Like with `custom-enabled-themes', the earlier themes in the list\nhave higher precedence.\n\nOne other thing to be aware of is that when you first load a theme, you may be\nprompted to acknowledge that the theme can run arbitrary Lisp code.\nAcknowledging this and then allowing Emacs to treat the theme as safe in future\nsessions will silence the prompt (for that particular theme). If you would just\nprefer to ignore this warning for all themes, you can set ‘custom-safe-themes’\nto t." :group auto-dark :type (choice (const :tag "Use custom-enabled-themes" nil) (list :tag "Use distinct dark & light lists" (repeat :tag "Dark" symbol) (repeat :tag "Light" symbol))) :set #f(compiled-function (symbol value) #<bytecode -0x1b66f97efecd9a2b>) :version "0.13")
  byte-code("\300\301\302\303#\210\304\305\302\306\307\310\311\312&\7\210\313\314\315\316\317DD\320\307\305\321\322\323\324\325\326&\13\210\313\327\315\316\330DD\331\307\305\321\332&\7\210\313\333\315\316\334DD\335\307\305\321\336&\7\210\337\327\314\326#\210\337\333\314\326#\207" [require dbus nil t custom-declare-group auto-dark "Automatically changes Emacs theme acording to MacOS/Windows dark-mode status." :group tools :prefix "auto-dark-*" custom-declare-variable auto-dark-themes funcall function #f(compiled-function () #<bytecode 0x18c000ae69414>) "The themes to enable for dark and light modes.\nThe default is to use the themes in `custom-enabled-themes', but that only works\nif the themes are aware of `frame-background-mode', which many aren’t.\n\nIf your themes aren’t aware of `frame-background-mode' (or you just prefer\ndifferent themes for dark and light modes), you can set explicit lists of themes\nfor each mode. Like with `custom-enabled-themes', the earlier themes in the list\nhave higher precedence.\n\nOne other thing to be aware of is that when you first load a theme, you may be\nprompted to acknowledge that the theme can run arbitrary Lisp code.\nAcknowledging this and then allowing Emacs to treat the theme as safe in future\nsessions will silence the prompt (for that particular theme). If you would just\nprefer to ignore this warning for all themes, you can set ‘custom-safe-themes’\nto t." :type (choice (const :tag "Use custom-enabled-themes" nil) (list :tag "Use distinct dark & light lists" (repeat :tag "Dark" symbol) (repeat :tag "Light" symbol))) :set #f(compiled-function (symbol value) #<bytecode -0x1b66f97efecd9a2b>) :version "0.13" auto-dark-dark-theme #f(compiled-function () #<bytecode 0x18c00f677e214>) "The theme to enable when dark-mode is active.\n\nThis variable is obsolete. You should set `auto-dark-themes' instead." (choice symbol (const nil)) auto-dark-light-theme #f(compiled-function () #<bytecode 0x18c00f9ee5b94>) "The theme to enable when dark-mode is inactive.\n\nThis variable is obsolete. You should set `auto-dark-themes' instead." (choice symbol (const nil)) make-obsolete-variable] 12)
  command-execute(auto-dark-mode record)
  execute-extended-command(nil "auto-dark-mode" "auto-dark")
  funcall-interactively(execute-extended-command nil "auto-dark-mode" "auto-dark")
  command-execute(execute-extended-command)

Debug on (M-x eval-buffer):

Debugger entered--Lisp error: (void-function auto-dark--check-and-set-dark-mode)
  (auto-dark--check-and-set-dark-mode)
  #f(lambda (_symbol value) [t] (mapc #'(lambda (mode-themes) (mapc #'(lambda (theme) (if (custom-theme-p theme) nil (load-theme theme nil t))) mode-themes)) value) (auto-dark--check-and-set-dark-mode))(auto-dark-themes nil)
  custom-initialize-reset(auto-dark-themes (funcall #'#f(lambda () [t] "" nil)))
  custom-declare-variable(auto-dark-themes (funcall #'#f(lambda () [t] "" nil)) "The themes to enable for dark and light modes.\nThe default is to use the themes in `custom-enabled-themes', but that only works\nif the themes are aware of `frame-background-mode', which many aren’t.\n\nIf your themes aren’t aware of `frame-background-mode' (or you just prefer\ndifferent themes for dark and light modes), you can set explicit lists of themes\nfor each mode. Like with `custom-enabled-themes', the earlier themes in the list\nhave higher precedence.\n\nOne other thing to be aware of is that when you first load a theme, you may be\nprompted to acknowledge that the theme can run arbitrary Lisp code.\nAcknowledging this and then allowing Emacs to treat the theme as safe in future\nsessions will silence the prompt (for that particular theme). If you would just\nprefer to ignore this warning for all themes, you can set ‘custom-safe-themes’\nto t." :group auto-dark :type (choice (const :tag "Use custom-enabled-themes" nil) (list :tag "Use distinct dark & light lists" (repeat :tag "Dark" symbol) (repeat :tag "Light" symbol))) :set #f(lambda (_symbol value) [t] (mapc #'(lambda (mode-themes) (mapc #'(lambda ... ...) mode-themes)) value) (auto-dark--check-and-set-dark-mode)) :version "0.13")
  eval-buffer()  ; Reading at buffer position 3452
  funcall-interactively(eval-buffer)
  command-execute(eval-buffer record)
  execute-extended-command(nil "eval-buffer" nil)
  funcall-interactively(execute-extended-command nil "eval-buffer" nil)
  command-execute(execute-extended-command)

It works checkouting 478d102, it wont after abcf103.
Diff after both:

diff --git a/auto-dark.el b/auto-dark.el
index 62b2cc8..c1a6535 100644
--- a/auto-dark.el
+++ b/auto-dark.el
@@ -4,16 +4,18 @@
 ;;         Tim Harper <timcharper at gmail dot com>
 ;;         Vincent Zhang <seagle0128@gmail.com>
 ;;         Jonathan Arnett <jonathan.arnett@protonmail.com>
+;;         Greg Pfeil <greg@technomadic.org>
 ;; Created: July 16 2019
-;; Version: 0.13
+;; Version: 0.13.1
 ;; Keywords: macos, windows, linux, themes, tools, faces
 ;; URL: https://github.com/LionyxML/auto-dark-emacs
 ;; Package-Requires: ((emacs "24.4"))
 ;; SPDX-License-Identifier: GPL-2.0-or-later
 
 ;;; Commentary:
-;; Auto-Dark is an auto-changer between 2 themes, dark/light, respecting the
-;; overall settings of MacOS, Linux and Windows.
+
+;; Auto-Dark is an auto-changer between 2 sets of themes, dark/light, respecting
+;; the overall settings of MacOS, Linux and Windows.
 ;; To enable it, install the package and add it to your load path:
 ;;
 ;;     (require 'auto-dark)
@@ -49,13 +51,34 @@ if the themes are aware of `frame-background-mode', which many aren’t.
 If your themes aren’t aware of `frame-background-mode' (or you just prefer
 different themes for dark and light modes), you can set explicit lists of themes
 for each mode. Like with `custom-enabled-themes', the earlier themes in the list
-have higher precedence."
+have higher precedence.
+
+One other thing to be aware of is that when you first load a theme, you may be
+prompted to acknowledge that the theme can run arbitrary Lisp code.
+Acknowledging this and then allowing Emacs to treat the theme as safe in future
+sessions will silence the prompt (for that particular theme). If you would just
+prefer to ignore this warning for all themes, you can set ‘custom-safe-themes’
+to t."
   :group 'auto-dark
   :type '(choice
           (const :tag "Use custom-enabled-themes" nil)
           (list :tag "Use distinct dark & light lists"
                 (repeat :tag "Dark" symbol)
-                (repeat :tag "Light" symbol))))
+                (repeat :tag "Light" symbol)))
+  :set (lambda (_symbol value)
+         ;; Pre-load any themes used by Auto Dark (to force prompts for
+         ;; ‘custom-safe-themes’ while the user is interacting with Auto Dark,
+         ;; rather than at initialization or ‘frame-background-mode’ charge).
+         (mapc (lambda (mode-themes)
+                 (mapc (lambda (theme)
+                         (unless (custom-theme-p theme)
+                           (load-theme theme nil t)))
+                       mode-themes))
+               value)
+         ;; Make sure Auto Dark is showing the updated themes for the current
+         ;; ‘frame-background-mode’.
+         (auto-dark--check-and-set-dark-mode))
+  :version "0.13")
 
 (defcustom auto-dark-dark-theme 'wombat
   "The theme to enable when dark-mode is active.
@@ -89,13 +112,13 @@ can be replaced by “a”."
                                (list auto-dark-light-theme))))
         (when deprecated-theme (list deprecated-theme)))))
 
-(defun auto-dark--dark-themes ()
-  "Return the set of themes to be used in dark mode."
-  (auto-dark--patch-theme-list (car auto-dark-themes) auto-dark-dark-theme))
-
-(defun auto-dark--light-themes ()
-  "Return the set of themes to be used in light mode."
-  (auto-dark--patch-theme-list (cadr auto-dark-themes) auto-dark-light-theme))
+(defun auto-dark--themes-for-mode (mode)
+  "Return the set of themes to be used in MODE."
+  (pcase mode
+    ('dark (auto-dark--patch-theme-list (car auto-dark-themes)
+                                        auto-dark-dark-theme))
+    ('light (auto-dark--patch-theme-list (cadr auto-dark-themes)
+                                         auto-dark-light-theme))))
 
 (defcustom auto-dark-polling-interval-seconds 5
   "The number of seconds between which to poll for dark mode state.
@@ -225,7 +248,9 @@ In order to determine if dark theme is enabled."
 In order to prevent flickering, we only set the theme if we haven't
 already set the theme for the current dark mode state."
   (let ((appearance (if (auto-dark--is-dark-mode) 'dark 'light)))
-    (unless (eq appearance auto-dark--last-dark-mode-state)
+    (unless (and (eq appearance auto-dark--last-dark-mode-state)
+                 (equal custom-enabled-themes
+                        (auto-dark--themes-for-mode appearance)))
       (auto-dark--set-theme appearance))))
 
 (defun auto-dark--update-frame-backgrounds (appearance)
@@ -261,13 +286,10 @@ This will load themes if necessary."
   "Set light/dark theme Argument APPEARANCE should be light or dark."
   (setq auto-dark--last-dark-mode-state appearance)
   (auto-dark--update-frame-backgrounds appearance)
-  (pcase appearance
-    ('dark
-     (auto-dark--enable-themes (auto-dark--dark-themes))
-     (run-hooks 'auto-dark-dark-mode-hook))
-    ('light
-     (auto-dark--enable-themes (auto-dark--light-themes))
-     (run-hooks 'auto-dark-light-mode-hook))))
+  (auto-dark--enable-themes (auto-dark--themes-for-mode appearance))
+  (run-hooks (pcase appearance
+               ('dark 'auto-dark-dark-mode-hook)
+               ('light 'auto-dark-light-mode-hook))))
 
 (defvar auto-dark--timer nil)
 (defun auto-dark-start-timer ()
LionyxML added a commit that referenced this issue Sep 27, 2024
Until we run more tests and find out why #69 and #70 causes.
@LionyxML
Copy link
Owner Author

Same problem as #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant