guidoschmidt / circadian.el

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

[Request] Running a theme-change-hook and persisting theme as variable? #10

Closed jojojames closed 6 years ago

jojojames commented 6 years ago

Hi,

Wanted to request getting a theme-change-hook as well as persisting the theme variable on change.

I believe custom-enabled-themes contains a list of enabled themes but it might be more explicit to manage one in this package.

Thanks!

guidoschmidt commented 6 years ago

Hey,

thanks for that suggestion 👍 I'll consider the idea If you like, feel free to contribute some example code that elaborates your thougt 🙂

stardiviner commented 6 years ago

I posted an email in emacs-help mailing list a few days ago, just for circadian. I want the same hook too. http://lists.gnu.org/archive/html/help-gnu-emacs/2017-12/msg00000.html

jojojames commented 6 years ago
  (defvar +current-theme nil "Current theme.")

  (defun theme-changer-switch-theme (_old new)
    ""
    (mapc #'disable-theme custom-enabled-themes)
    (setq +current-theme new)
    (when new
      (load-theme new t)
      (run-hooks 'after-load-theme-hook)))

I have something like this for theme-changer.

stardiviner commented 6 years ago

@jojojames I can't find the after-load-theme-hook. I use [C-h v], but didn't found it.

jojojames commented 6 years ago

It's a hook you run/create yourself.

guidoschmidt commented 6 years ago

@jojojames Thank's for the example above 👍. I'll put the hook onto the top of my todo-stack for circadian. In the meantime, maybe you'll be able to get around using an adviced function (using a hook should be the preferred way ... "Advice should only be used when no hook is provided"... 😓):

(defun foobar (original-function &rest args)
  "Wrap the ORIGINAL-FUNCTION that would be called with its ARGS."
  (message "Circadian will change your theme.") ;; <- custom code, runs before circadian-enable-theme
  (apply original-function args)
  (message "Circadian changed your theme.")) ;; <- custom code, runs after circadian-enable-theme

;; Add your custom foobar function to circadian-enable-theme function
(advice-add #'circadian-enable-theme :around #'foobar)

;; Now when circadian enables a theme, the foobar function is 'wrapped around'
;; circadian-enable-theme
(circadian-enable-theme 'material)

Adding a hook and persisting the currently loaded theme shouldn't be to complicated - I'm on it as soon as possible 🙂

guidoschmidt commented 6 years ago

Just released v0.3.1 providing a hook that runs before loading a theme, as well as one, that runs afterwards.

Let me know, if you want additional features or have further ideas on hooks and what to do with them regarding theme switching 👍

jojojames commented 6 years ago

Thanks @guidoschmidt !