diff --git a/auto-dark.el b/auto-dark.el index 405a683..e6c3037 100644 --- a/auto-dark.el +++ b/auto-dark.el @@ -238,6 +238,19 @@ This will load themes if necessary." (warn "Failed to enable theme(s): %s" (mapconcat #'symbol-name failures ", ")))))) +(defun auto-dark-toggle-appearance () + "Switch between light and dark mode. +If `auto-dark-detection-method' is nil, this will persist until the next time +this is called. Otherwise, it could switch to the system appearance at any +time." + (interactive) + (auto-dark--set-theme (if (eq auto-dark--last-dark-mode-state 'dark) + 'light + ;; NB: This does _something_ even if we don’t know + ;; what the previous state was, since the user + ;; explicitly requested a change. + 'dark))) + (defun auto-dark--set-theme (appearance) "Set light/dark theme Argument APPEARANCE should be light or dark." (setq auto-dark--last-dark-mode-state appearance) @@ -346,7 +359,9 @@ Remove theme change callback registered with D-Bus." ((eq system-type 'windows-nt) 'winreg) (t - (error "Could not determine a viable theme detection mechanism!")))) + (lwarn 'auto-dark :error "Could not determine a viable theme detection \ +mechanism! You can use ‘auto-dark-toggle-appearance’ to manually switch between \ +modes.")))) ;;;###autoload (define-minor-mode auto-dark-mode diff --git a/tests/basic.el b/tests/basic.el index 33e47fa..57df10f 100644 --- a/tests/basic.el +++ b/tests/basic.el @@ -42,6 +42,16 @@ (expect auto-dark-themes :to-equal '((wombat) (leuven))) (expect custom-enabled-themes :to-equal '(leuven)))) +(describe "toggling" + (before-each + (auto-dark-toggle-appearance)) + (it "should invert the current appearance" + (expect custom-enabled-themes :to-equal '(wombat))) + (it "should invert the current appearance again" + (expect custom-enabled-themes :to-equal '(leuven))) + (it "should invert the current appearance and again" + (expect custom-enabled-themes :to-equal '(wombat)))) + ;; Restore the original state (unless auto-dark-tests--original-state (auto-dark-mode -1))