Emacs 中的 color-theme.el 模块提供了很多好看的配色 方案。可以在网络上搜索并且下在这个文件。
如果你有几个 color theme 都很好,难于取舍,想每隔 一段是自动换一个color theme ,那么试试下面的方法。
创建下面的目录结构:
~/Emacs/myconfig/color-themes/console ~/Emacs/myconfig/color-themes/gui
然后
M-x color-theme-select
选择你喜欢 color theme 然后 press p,打开选择的配 色方案的对应的代码,然后 C-x C-s 保存到对应的目录 中去,取个的名字。
图形界面的放在
~/Emacs/myconfig/color-themes/gui目录下
字符界面的放在
~/Emacs/myconfig/color-themes/console
文件名称一定要以 el 为扩展名称,例如
ocean-deep.el
不要改动文件内容, 尤其是不要改动
(defun my-color-theme ()
的那一行,函数名字一定要是 my-color-theme
然后在你的 .emacs 中添加:
(require 'color-theme) (setq color-themes-directory-name "~/Emacs/myconfig/color-themes") (if (display-graphic-p) (setq color-themes-directory-name (concat color-themes-directory-name "/gui")) (setq color-themes-directory-name (concat color-themes-directory-name "/console"))) (let* ((files (directory-files color-themes-directory-name t "^[^.].*\.el$")) (randnum (% (abs (random t)) (length files ))) (selected-filename (nth randnum files))) (load selected-filename) (my-color-theme))
效果就是,每次启动 emacs 的时候,随机选择一个 color theme.
我现在只有两个 color theme, 一个是 blue mode 一个是crazytool 提供的ocean deep 要 是大家多提供几种漂亮的 theme 就好了 !
下面的函数也很有用
(defun wcy-color-theme-edit () (interactive) (find-file current-color-theme-file-name)) (defun wcy-color-theme-apply () (interactive) (my-color-theme) (wcy-color-theme-adjust-hl-mode-face)) (defun wcy-color-theme-load-theme ( name) (setq current-color-theme-file-name (concat color-themes-directory-name name ".el")) (load current-color-theme-file-name)) (defun wcy-select-color-theme () (interactive) (let* ((files (mapcar (function (lambda (s) (list (replace-regexp-in-string "\\(.*\\)\\.el$" "\\1" s)))) (directory-files color-themes-directory-name nil "^[^.].*\\.el$"))) (theme (completing-read "Input a theme:" files))) (wcy-color-theme-load-theme theme) (wcy-color-theme-apply))) (defun wcy-random-select-color (&optional prefer) (interactive) (let* ((files (mapcar (function (lambda (s) (replace-regexp-in-string "\\(.*\\)\\.el$" "\\1" s))) (directory-files color-themes-directory-name nil "^[^.].*\\.el$"))) (randnum (% (abs (random t)) (length files ))) (theme (nth randnum files))) (wcy-color-theme-load-theme theme) (wcy-color-theme-apply))) ;; 下面的是调整 hight line mode 下的高亮显示行的背景颜色 (require 'hl-line) ;;(hl-line-mode -1) ;;(global-hl-line-mode -1) ;; for hight line mode (or (facep 'my-hl-line-face) (make-face 'my-hl-line-face)) (setq hl-line-face 'my-hl-line-face) (face-spec-set 'my-hl-line-face '((t ( :background "DodgerBlue3" ;;:bold ;;:weight nil :inverse-video nil )))) (defun wcy-color-theme-adjust-hl-mode-face() "interactive" (let* ((color (x-color-values (face-attribute 'default :background)))) (if (null color) (error "not support.") (let ((my-color (mapcar (lambda (x) (let ((y (/ #XFFFF 4)) (delta #X8FF)) (cond ((< x (* y 1)) (+ x delta)) ((< x (* y 2)) (- x delta)) ((< x (* y 3)) (+ x delta)) (t (- x delta))))) color))) (message "%S %S" color my-color) (set-face-attribute 'my-hl-line-face nil :background (concat "#" (mapconcat (lambda (c) (format "%04X" c)) my-color ""))))))) (wcy-color-theme-adjust-hl-mode-face)
M-x wcy-select-color-theme 就可以选择一个 theme , 可以自动补全.