0

I am trying to automatically change my Emacs theme according to time set (Thanks to answer provided by Dan).

My code looks like this:

(setq emacs-curr-theme nil)
(setq emacs-light-theme 'faff)
(setq emacs-dark-theme 'atom-one-dark)

(defun emacs-synchronize-theme ()

  (let ((hour nil) (now nil))
    (progn (setq hour 
        (string-to-number 
            (substring (current-time-string) 11 13)))
    (if (member hour (number-sequence 7 13))
        (setq now emacs-light-theme)
        (setq now emacs-dark-theme))

    (if (equal now emacs-curr-theme now)
        nil
        (progn
          (setq emacs-curr-theme now)
          (load-theme emacs-curr-theme t))))))

(defun emacs-set-theme ()
  ;; Load theme only when using GUI
  (when (display-graphic-p)
      (run-with-timer 0 900 'emacs-synchronize-theme)))

When I am calling the function emacs-set-theme from my init.el, I am getting this error -

Error running timer 'emacs-synchronize-theme': (wrong-number-of-arguments equal 3)

I have no clue what I am doing wrong here. I have checked documentation for run-with-timer, but unable to figure out the problem by myself.

0

Your error is:

(equal now emacs-curr-theme now)

As equal takes two arguments, not three.

I used M-x toggle-debug-on-error before running your code to find that quickly:

Debugger entered--Lisp error: (wrong-number-of-arguments equal 3)
  (equal now emacs-curr-theme now)
  (if (equal now emacs-curr-theme now) nil (progn (setq emacs-curr-theme now) (load-theme emacs-curr-theme t)))
  (progn (setq hour (string-to-number (substring (current-time-string) 11 13))) (if (member hour (number-sequence 7 13)) (setq now emacs-light-theme) (setq now emacs-dark-theme)) (if (equal now emacs-curr-theme now) nil (progn (setq emacs-curr-theme now) (load-theme emacs-curr-theme t))))
  (let ((hour nil) (now nil)) (progn (setq hour (string-to-number (substring (current-time-string) 11 13))) (if (member hour (number-sequence 7 13)) (setq now emacs-light-theme) (setq now emacs-dark-theme)) (if (equal now emacs-curr-theme now) nil (progn (setq emacs-curr-theme now) (load-theme emacs-curr-theme t)))))
  emacs-synchronize-theme()
  apply(emacs-synchronize-theme nil)
  timer-event-handler([t 24378 24806 149715 900 emacs-synchronize-theme nil nil 39000])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.