我可以讓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