guidoschmidt / circadian.el

Theme-switching for Emacs based on daytime
https://guidoschmidt.github.io/circadian.el
MIT License
169 stars 8 forks source link

saving desktop: theme wouldn't switch #21

Closed Krisselack closed 2 years ago

Krisselack commented 4 years ago

I use circadian happily and also desktop-save-mode. When I shut down emacs in the evening and open it up in the morning, the dark theme is saved (and vice versa with the light theme). Is there a way to reload the correct theme with desktop-save-mode? Thanks.

config:

(desktop-save-mode` 1)
(setq desktop-restore-frame nil)

;; ALSO: saving the window configuration; maybe that's the issue here 

(defvar pre-ediff-window-configuration nil
  "window configuration to use")
(defvar new-ediff-frame-to-use nil
  "new frame for ediff to use")
(defun save-my-window-configuration ()
  (interactive)
  (setq pre-ediff-window-configuration (current-window-configuration))
  (select-frame-set-input-focus (setq new-ediff-frame-to-use (new-frame))))
(add-hook 'ediff-before-setup-hook 'save-my-window-configuration)
(defun restore-my-window-configuration ()
  (interactive)
  (when (framep new-ediff-frame-to-use)
    (delete-frame new-ediff-frame-to-use)
    (setq new-ediff-frame-to-use nil))
  (when (window-configuration-p pre-ediff-window-configuration)
    (set-window-configuration pre-ediff-window-configuration)))
(add-hook 'ediff-after-quit-hook-internal 'restore-my-window-configuration)

(use-package circadian
  :config
  (setq calendar-latitude 48.2)
  (setq calendar-longitude 16.37)
  (setq circadian-themes '((:sunrise . leuven)
                           (:sunset  . wombat)))
  (circadian-setup))
guidoschmidt commented 3 years ago

@Krisselack thanks for the request and sorry for beeing that late, I haven't worked on circadian.el for quite a while. I'm trying to dig in again more often.

Note for myself, check: Emacs Desktop-Save-Mode

utoku commented 2 years ago

This is not circadian's fault. This usually is caused by stale locks (or two emacs open using the same desktop file.) You have two workarounds:

  1. use the :hook keyword of use-package to make sure that circadian setup also runs after desktop-load i.e. here is mine:
    
    (use-package circadian
    :config
    (setq calendar-latitude  YF/latitude)
    (setq calendar-longitude YF/longitude)
    (setq circadian-themes '((:sunrise . hydandata-light)
                           (:sunset . sanityinc-tomorrow-eighties)))
    (circadian-setup)
    :hook (desktop-after-read . circadian-setup )
    )

2. Make sure your emacs don't use stale desktop locks, or similar as mentioned in https://www.emacswiki.org/emacs/Desktop
Krisselack commented 2 years ago

thank you, @utoku, I included both your hook and disabled stale lock by including sylvains code snipped from your shared url into my emacs-config. issue seems solved so far :-).