Emacs color theme download by time

Can I let Emacs download a theme automatically? or execute a specific command in a custom time? Say that I want Mx load-theme RET solarized-light when I am in the office at 9:00 and Mx laod-theme RET solarized-dark when I get home and continued to work in emacs at 20:00.

+8
emacs elisp
source share
4 answers

To deploy the answer to @Anton Kovalenko, you can get the current time using the current elisp line-string and extracting the current time of day in hours.

If you want to write a complete implementation, you can do something like ( Warning, not debug ):

 ;; <Color theme initialization code> (setq current-theme '(color-theme-solarized-light)) (defun synchronize-theme (setq hour (string-to-number (substring (current-time-string) 11 13))) ;;closes (setq hour... (if (member hour (number-sequence 6 17)) (setq now '(color-theme-solarized-light)) (setq now '(color-theme-solarized-dark))) ;; end of (if ... (if (eq now current-theme) nil (setq current-theme now) (eval now) ) ) ;; end of (defun ... (run-with-timer 0 3600 synchronize-theme) 

For more information about the features used, see the following sections of the emacs manual:

+6
source share

Another (very elegant) solution is the theme changer.

Given the location and color themes of day and night, this file provides a theme change function that selects a suitable theme depending on whether it is day or night. He will continue to change themes at sunrise and sunset. To install:

Set location:

 (setq calendar-location-name "Dallas, TX") (setq calendar-latitude 32.85) (setq calendar-longitude -96.85) 

Indicate the day and night topics:

 (require 'theme-changer) (change-theme 'tango 'tango-dark) 

The project is hosted on Github and can be installed via melpa.

+7
source share

You can use this piece of code to do what you want.

 (defvar install-theme-loading-times nil "An association list of time strings and theme names. The themes will be loaded at the specified time every day.") (defvar install-theme-timers nil) (defun install-theme-loading-at-times () "Set up theme loading according to `install-theme-loading-at-times`" (interactive) (dolist (timer install-theme-timers) (cancel-timer timer)) (setq install-theme-timers nil) (dolist (time-theme install-theme-loading-times) (add-to-list 'install-theme-timers (run-at-time (car time-theme) (* 60 60 24) 'load-theme (cdr time-theme))))) 

Just configure the install-theme-loading-times variable as desired:

 (setq install-theme-loading-times '(("9:00am" . solarized-light) ("8:00pm" . solarized-dark))) 
+5
source share

You can start with the run-with-timer function:

 (run-with-timer SECS REPEAT FUNCTION &rest ARGS) Perform an action after a delay of SECS seconds. Repeat the action every REPEAT seconds, if REPEAT is non-nil. SECS and REPEAT may be integers or floating point numbers. The action is to call FUNCTION with arguments ARGS. This function returns a timer object which you can use in `cancel-timer'. 

Schedule a function to run every minute or so that will check the current time and call load-theme if necessary (do not switch the theme every minute, even if it reloads the current theme).

+2
source share

All Articles