首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emacs按时间自动加载颜色主题

Emacs按时间自动加载颜色主题
EN

Stack Overflow用户
提问于 2013-02-08 04:40:12
回答 5查看 3.3K关注 0票数 12

我可以让Emacs自动加载主题吗?或者在自定义时间执行某些命令?早上9:00在办公室时告诉M-x load-theme RET solarized-light,回家后告诉M-x laod-theme RET solarized-dark,晚上8:00继续使用emacs

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-02-08 04:56:35

要扩展@Anton Kovalenko的答案,您可以使用current-time-string elisp函数获取当前时间,并以小时为单位提取当前时间。

如果你想写一个完整的实现,你可以这样做(警告,而不是调试的):

代码语言:javascript
复制
;; <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手册的以下部分:

  • Time of day
  • Strings
  • String Conversions
  • Idle Timers
  • Contains
  • Number Sequence
票数 11
EN

Stack Overflow用户

发布于 2014-03-23 03:44:41

另一个(非常优雅的)解决方案是主题转换器。

在给定位置和白天/夜间颜色主题的情况下,此文件提供了更改主题函数,该函数根据主题是白天还是夜晚来选择适当的主题。它将继续在日出和日落时改变主题。要安装:

设置位置:

代码语言:javascript
复制
(setq calendar-location-name "Dallas, TX") 
(setq calendar-latitude 32.85)
(setq calendar-longitude -96.85)

指定白天和晚上的主题:

代码语言:javascript
复制
(require 'theme-changer)
(change-theme 'tango 'tango-dark)

该项目是托管的on Github,可以通过melpa安装。

票数 11
EN

Stack Overflow用户

发布于 2013-02-08 05:07:24

您可以使用这段代码来做您想做的事情。

代码语言:javascript
复制
(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

代码语言:javascript
复制
(setq install-theme-loading-times '(("9:00am" . solarized-light)
                ("8:00pm" . solarized-dark)))
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14760567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档