我可以让Emacs自动加载主题吗?或者在自定义时间执行某些命令?早上9:00在办公室时告诉M-x load-theme RET solarized-light,回家后告诉M-x laod-theme RET solarized-dark,晚上8:00继续使用emacs
发布于 2013-02-08 04:56:35
要扩展@Anton Kovalenko的答案,您可以使用current-time-string elisp函数获取当前时间,并以小时为单位提取当前时间。
如果你想写一个完整的实现,你可以这样做(警告,而不是调试的):
;; <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)))
(if (member hour (number-sequence 6 17))
(setq now '(color-theme-solarized-light))
(setq now '(color-theme-solarized-dark)))
(if (equal now current-theme)
nil
(setq current-theme now)
(eval now) ) ) ;; end of (defun ...
(run-with-timer 0 3600 synchronize-theme)有关使用的函数的更多信息,请参阅emacs手册的以下部分:
发布于 2014-03-23 03:44:41
另一个(非常优雅的)解决方案是主题转换器。
在给定位置和白天/夜间颜色主题的情况下,此文件提供了更改主题函数,该函数根据主题是白天还是夜晚来选择适当的主题。它将继续在日出和日落时改变主题。要安装:
设置位置:
(setq calendar-location-name "Dallas, TX")
(setq calendar-latitude 32.85)
(setq calendar-longitude -96.85)指定白天和晚上的主题:
(require 'theme-changer)
(change-theme 'tango 'tango-dark)该项目是托管的on Github,可以通过melpa安装。
发布于 2013-02-08 05:07:24
您可以使用这段代码来做您想做的事情。
(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)))))只需根据需要自定义变量install-theme-loading-times:
(setq install-theme-loading-times '(("9:00am" . solarized-light)
("8:00pm" . solarized-dark)))https://stackoverflow.com/questions/14760567
复制相似问题