“色向胆边生” - 记Emacs配色的超级武器:Icicles,Color Palette和DoReMi

Emacs的定制性非常强大, 其颜色定制性当然也非常强大了, 不过我相信Emacser们在定制颜色的时候, 非常的不方便, 使用set-face-foreground, set-face-background, set-background-color, set-foreground-color等系列命令的时候只能根据颜色名字来选择颜色, 非常的不直观, 不像windows下那样能根据调色板来选择颜色, 那么Emacs下有没有windows下这样的调色板呢? 当然有! Emacs永远比windows下的工具强大!(:), windows粉丝不要扔鸡蛋啊, windows只适合做桌面, 开发方面它只是个原始社会的工具, 桌面方面它也不咋的, 只不过大家做的都不好,它就成老大了,
), 哈哈, 跑题了, 我们继续来说Emacs。
Emacs下定制颜色比较好的工具有Icicles, Color Palette, 以及DoReMi(这三个工具都是同一个作者DrewAdams写的, 这个作者还写了好多工具, 大家可以去他的EmacsWiki的主页上去看看)。我先说一下安装它们要注意的问题, 然后再来一个个的介绍它们.
安装Icicles, Color Palette, DoReMi应该注意的问题
Icicles中有一个frame-cmds.el, 它必须放在MultiTerm前面, 否则ediff退出时会报”Lisp nesting exceeds ‘max-lisp-eval-depth’”, 而icicles soft-require frame-cmds.el, 所以icicles也必须放在MultiTerm前面加载. 还有, Emacs22下面Icicles也必须放在kde-emacs前面加载, 否则会报shell-command是void-function.
说完了安装时应该注意的问题, 我们来分别介绍它们.
Icicles
要是用Icicles, 先要激活icy-mode(M-x icy-mode), 不过激活后会与ido有冲突, 所以我一般只有在配置颜色的时候才会激活icy-mode, 平时是关着的, 关于与ido冲突这个问题, 据作者说是ido操作minibuffer的方法和其按键的绑定不是兼容的方法, 而Icicles操作minibuffer的方法才是与正常的操作minibuffer的方法是接近的, 关于这个, 大家可以看这里. 激活了icy-mode后, 再使用set-face-foreground, set-face-background, set-background-color, set-foreground-color等系列命令的时候, 就不只是光看到颜色名字了, 还能看到颜色的直观显示, 截图如下:
这样,挑选好看的颜色就方便多了。而且在按tab进行补全的时候,还可以按C-up,C-down,C-prior,C-next来使当前选中的候选颜色生效,当然,按C-g退出命令的时候,刚才生效的颜色会取消。Icicles还有好多其他的强大功能,大家可以试试。
DoReMi
DoReMi可以直接操纵RGB,HSV分量来选择颜色,主要是这些命令: doremi-(bg|fg)+,doremi-face-(bg|fg)+,还可以根据颜色名称来循环的看颜色效果,比如:问先选择一个”yellow2″这个颜色,看看效果,不好看的话,不用退出命令,继续循环下一个颜色,非常方便,主要是doremi-(bg|fg)-color-name+,doremi-face-(bg|fg)-color-name+,以上在选择颜色的时候,都可以按C-g来恢复之前的颜色设置。
对颜色不太敏感的或者懒的自己来配色的同志可以使用Color Theme, 使用Color theme选择颜色主题的时候,要一个一个的去试,有点麻烦,doremi-color-themes+可以让你更方便的选颜色主题。Color theme还有一个更好用的命令color-theme-print, 它可以把你当前的颜色设置制作成Color theme,我就做了一个Color theme,请看这里。
DoReMi配置文件在这里,配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ;; -*- Emacs-Lisp -*- ;; Time-stamp: <2009-11-18 00:46:57 Wednesday by ahei> (require 'doremi) (require 'doremi-cmd) (require 'doremi-mac) (require 'thumb-frm) (require 'menu-bar+) (require 'zoom-frm) ;; (require 'setup-keys) (require 'facemenu+) (setq doremi-up-keys '(?\M-p ?p)) (setq doremi-down-keys '(?\M-n ?n)) (setq doremi-RGB-increment-factor 256) |
Color Palette
Color Palette是一个非常强大的配色工具,直接使用M-x facemenup-palette-face-at-point打开Color Palette, 这个命令会选择当前光标下的face的前景色作为待编辑的颜色,也可以使用M-x facemenup-palette-face,这个命令会提示你输入一个face,然后使用它的前景色作为待编辑的颜色。打开后就是一个调色板, 就像下面这样:
然后我们可以使用方向键或者h,j,k,l来上下移动光标,或者按J,H,K,L来快速移动光标(这些按键以及上面的命令都是我配置后的),选到一个满意的颜色后,按m或者回车键使这个颜色生效,不过这个调色板打开的时候有点慢,更新颜色的时候也有点慢。按f选择正在编辑的face的前景色进行编辑,b选择face的背景色进行编辑,F恢复face的前景色,B恢复face的背景色,r则一起恢复前景色和背景色,d会显示当前编辑的颜色,C拷贝当前的颜色,使用C-x k关闭调色板的时候,刚才所做的颜色修改都会恢复,其他譬如q或者系统关闭按钮退出,则不恢复。
Color Palette配置文件在这里,配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | ;; -*- Emacs-Lisp -*- ;; Time-stamp: <2009-11-19 15:14:32 Thursday by ahei> (require 'palette) (defun blink-cursor-mode-disable () "Disable `blink-cursor-mode'." (interactive) (blink-cursor-mode -1)) (add-hook 'palette-mode-hook 'blink-cursor-mode-disable) (defmacro def-palette-move-command (move-command speed) "Make definition of command which palette move quickly." `(defun ,(concat-name move-command "-quickly") () ,(concat move-command " quickly.") (interactive) (,(symbol-function (intern move-command)) ,speed))) (apply-args-list-to-fun 'def-palette-move-command `(("palette-down" 7) ("palette-up" 7) ("palette-left" 7) ("palette-right" 7))) (apply-define-key palette-mode-map `(("j" palette-down) ("k" palette-up) ("h" palette-left) ("l" palette-right) ("J" palette-down-quickly) ("K" palette-up-quickly) ("H" palette-left-quickly) ("L" palette-right-quickly) ("r" palette-face-restore-bg-fg) ("f" palette-set-face-changed-to-foreground) ("b" palette-set-face-changed-to-background) ("B" facemenup-face-bg-restore) ("F" facemenup-face-fg-restore) ("d" palette-disply-which-in-changine) ("m" palette-pick-background-at-point) ("C" palette-copy-current-color) ("C-x k" palette-quit-restore-bg-fg))) (defun kill-palette-buffers (frame) (when (get-buffer "Palette (Hue x Saturation)") (kill-buffer "Palette (Hue x Saturation)")) (when (get-buffer "Brightness") (kill-buffer "Brightness")) (when (get-buffer "Current/Original") (kill-buffer "Current/Original"))) (add-to-list 'delete-frame-functions 'kill-palette-buffers) (if window-system (let ((font (car (x-list-fonts "-outline-Courier New-normal-normal-normal-mono-6-*-*-*-c-*-iso8859-1" nil nil 1)))) (if font (setq palette-font font)))) (apply-define-key global-map `(("C-x M-F" facemenup-palette-face) ("C-x M-P" facemenup-palette-face-at-point))) (defvar facemenup-palette-change-face-bg nil "Face background be changed or not.") (defvar facemenup-last-face-color nil "Last face color used.") (defun palette-quit-restore () "Quite palette and restore face changed." (interactive) (palette-quit) (palette-face-restore)) (defun palette-quit-restore-bg-fg () "Quite palette and restore face changed." (interactive) (palette-quit) (palette-face-restore-bg-fg)) (defun palette-face-restore () "Restore face have changed." (interactive) (unless (or (string= facemenup-last-face-color palette-current-color) (string= (hexrgb-color-name-to-hex facemenup-last-face-color) palette-current-color)) (if facemenup-palette-change-face-bg (facemenup-face-bg-restore) (facemenup-face-fg-restore)))) (defun palette-face-restore-bg-fg () "Restore face background and foreground have changed." (interactive) (facemenup-face-bg-restore) (facemenup-face-fg-restore)) (defun facemenup-palette-face-at-point (&optional is-bg) "Open palette and set face at point to face which to be changed." (interactive "P") (let (face (hl-line hl-line-mode)) (if hl-line (hl-line-mode -1)) (setq face (eyedrop-face-at-point)) (if hl-line (hl-line-mode 1)) (if face (facemenup-palette-face face is-bg) (call-interactively 'facemenup-palette-face)))) (defun facemenup-palette-face (face &optional is-bg) "Open palette and set face FACE to face which to be changed." (interactive (list (read-face-name (concat "Face whose " (if current-prefix-arg "background" "foreground") " to change")) current-prefix-arg)) (setq facemenup-palette-change-face-bg is-bg) (let ((color (if is-bg (facemenup-face-bg face) (facemenup-face-fg face)))) (setq facemenup-last-face-bg (facemenup-face-bg face)) (setq facemenup-last-face-fg (facemenup-face-fg face)) (setq facemenup-last-face-color color) (setq facemenup-last-face-changed face) (when facemenup-palette-update-while-editing-flag (palette-set-face-changed-to-foreground is-bg)) (condition-case nil (palette color) (quit (set-face-foreground face color))))) (defun palette-set-face-changed-to-foreground (&optional is-bg) "Set face change color to foreground." (interactive "P") (setq facemenup-palette-change-face-bg is-bg) (setq palette-action `(lambda () ,(if is-bg `(set-face-background facemenup-last-face-changed palette-current-color) `(set-face-foreground facemenup-last-face-changed palette-current-color)))) (message (concat "Change to " (if is-bg "back" "fore") "ground"))) (defun palette-set-face-changed-to-background (&optional is-fg) "Set face change color to background." (interactive "P") (palette-set-face-changed-to-foreground (not is-fg))) (defun palette-disply-which-in-changine () "Display which face in changing on palette." (interactive) (message (concat "Color changing is: %s's " (if facemenup-palette-change-face-bg "back" "fore") "ground") facemenup-last-face-changed)) (defun palette-copy-current-color () "Copy current color." (interactive) (kill-new palette-current-color) (message "Color %s copied." palette-current-color)) |

loading...
自己对颜色还真是不大敏感,也不知道如何搭配会比较舒服,自己目前用的主题还是在emacs-wiki上找到的tango主题,博主的颜色搭配似乎是自己设置的,看过截图,还不错。博主介绍的这两个elisp插件自己倒是还没用过,蛮实用的功能的。
[回复]
ahei 回复:
十一月 20th, 2009 at 1:32 下午
那些主题我都试过,但是总是感觉不满意,因为再好的主题,总有几个你不满意的地方,所以总需要自己去定制,我的配色完全自己定制的,没有用任何主题,不过我准备有空的时候把我的配色也做成主题,传到wiki上面去,你要是用Color Theme的话,可以使用doremi-color-themes+,这个选主题非常方便 ,我文中提到了
[回复]
ahei 回复:
十一月 20th, 2009 at 4:34 下午
我的主题做好了,请看这里。
[回复]
如果配色嫌麻烦的话可以去这个网站 http://alexpogosyan.com/color-theme-creator/ 直接生成theme。
[回复]
ahei 回复:
四月 27th, 2010 at 8:19 上午
@ylhufo, 那个可以配置的颜色太少了。
[回复]
你的dea中上面的命令怎么运行不了
[回复]
ahei 回复:
五月 20th, 2010 at 3:10 上午
@, 哪个命令预先不了呢?./install.sh? 这个现在的DEA里面是./install
[回复]
匿名 回复:
五月 20th, 2010 at 5:02 上午
@ahei, 那些配色工具的命令,好像没加载
[回复]
ahei 回复:
五月 20th, 2010 at 5:15 上午
@, 比如?
[回复]
匿名 回复:
五月 20th, 2010 at 6:13 上午
@ahei, M-x icy-mode
[回复]
ahei 回复:
五月 20th, 2010 at 6:15 上午
@, 。。。你没有(require ‘icicles)?
[回复]
请教一个问题:
hl-line-mode颜色很性感, 但我感觉太亮了,会干扰我输入文字。我如何才能把颜色调淡一些呢?
[回复]
ahei 回复:
六月 15th, 2010 at 3:50 上午
@凌狐, 你看我DEA里面的配置
[回复]