我可以让Emacs自动加载主题吗?或在定制时间执行某些命令?说我想要的是M-x load-theme RET solarized-light
,当我在上午9:00在办公室,M-x laod-theme RET solarized-dark
当我回家,并在晚上8:00继续emacs。Emacs自动加载时间颜色主题
回答
要扩展@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))) ;;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)
有关功能使用的更多信息,请参阅Emacs手册的以下部分:
您可以run-with-timer
功能开始:
(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'.
计划运行每分钟左右的功能,这将检查 当前时间和通话load-theme
在适当的时候(不转每分钟 主题,甚至如果它重新加载当前主题)。
感谢您的指导。继@Dan代码之后,我想我已经明白了。谢谢。 – liuminzhao
您可以使用此代码段将做你想做的。
(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)))
跟着@Dan的代码我会通过你的代码学习elisp。谢谢。 – liuminzhao
另一个(非常优雅)的解决方案是主题变换器。
给定一个位置和日/夜的颜色主题,这个文件提供了一个变化主题功能,根据它是白天还是晚上选择适当的主题。它将继续在日出和日落时改变主题。要安装:
设置的位置:
(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安装。
非常好的解决方案。谢谢你的提示。 – liuminzhao
- 1. OCaml的emacs颜色主题
- 2. Emacs颜色主题设置
- 3. Emacs使用颜色主题时出错
- 4. Emacs - 每小时随机颜色主题?
- 5. “无法打开加载文件,颜色主题”错误emacs-24.1
- 6. Emacs 24客户端不能正确加载颜色主题
- 7. 颜色主题画廊某处为emacs?
- 8. 更改emacs终端颜色主题
- 9. Aptana像emacs的颜色主题
- 10. 获取Windows 8自动颜色主题的活动颜色
- 11. 动态主题颜色
- 12. emacs自定义面颜色
- 13. emacs自动加载模式
- 14. 自动加载Emacs ESS
- 15. 更改颜色主题Emacs 24 - 订单问题
- 16. ActionBarSherlock主题颜色
- 17. VSPackage主题颜色
- 18. 如何制作不设置背景颜色的Emacs颜色主题?
- 19. Eclipse改变颜色主题的颜色?
- 20. Emacs颜色主题为无法识别的文件类型
- 21. Emacs:禁用终端中的主题背景颜色
- 22. 颜色的主题没有正确设置在.emacs文件
- 23. emacs 24 ansi-term似乎忽略了主题颜色
- 24. 如何更改Emacs中[]和()的颜色主题?
- 25. 无法设置默认的emacs的颜色主题文件
- 26. 在Emacs中选择不同的颜色主题进行打印
- 27. Emacs颜色主题会导致迷你缓冲区消失?
- 28. 有没有办法将颜色主题从R GUI导入Emacs?
- 29. 设置主题颜色动态
- 30. 如何在控制台模式下应用Emacs自定义颜色主题?
很好的例子。我每天使用emacs,但从未尝试学习elisp。刚开始学习并遵循你的例子。有用。谢谢。小提醒:应该是'substring(当前时间字符串)11 13)'?没有括号?也可以在'run-with-timer'中的'synchronize-theme'之前添加'''。 – liuminzhao
@ liuminzhao:你能否澄清需要解决的问题(或者直接修复)。 – Dan
它修复了一些错误后可以使用:(if(eq now current-theme)to(if(now now current-theme) – tangxinfa