1 ;;; rainbow-mode.el --- Colorize color names in buffers
3 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc
5 ;; Author: Julien Danjou <julien@danjou.info>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This minor mode sets background color to strings that match color
27 ;; names, e.g. #0000ff is displayed in white with a blue background.
39 (unless (require 'xterm-color nil t)
40 (require 'ansi-color))
43 "Show color strings with a background color."
48 (defvar rainbow-hexadecimal-colors-font-lock-keywords
49 '(("[^&]\\(#\\(?:[0-9a-fA-F]\\{3\\}\\)+\\{1,4\\}\\)"
50 (1 (rainbow-colorize-itself 1)))
51 ("^\\(#\\(?:[0-9a-fA-F]\\{3\\}\\)+\\{1,4\\}\\)"
52 (0 (rainbow-colorize-itself)))
53 ("[Rr][Gg][Bb]:[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}"
54 (0 (rainbow-colorize-itself)))
55 ("[Rr][Gg][Bb][Ii]:[0-9.]+/[0-9.]+/[0-9.]+"
56 (0 (rainbow-colorize-itself)))
57 ("\\(?:[Cc][Ii][Ee]\\(?:[Xx][Yy][Zz]\\|[Uu][Vv][Yy]\\|[Xx][Yy][Yy]\\|[Ll][Aa][Bb]\\|[Ll][Uu][Vv]\\)\\|[Tt][Ee][Kk][Hh][Vv][Cc]\\):[+-]?[0-9.]+\\(?:[Ee][+-]?[0-9]+\\)?/[+-]?[0-9.]+\\(?:[Ee][+-]?[0-9]+\\)?/[+-]?[0-9.]+\\(?:[Ee][+-]?[0-9]+\\)?"
58 (0 (rainbow-colorize-itself))))
59 "Font-lock keywords to add for hexadecimal colors.")
62 (defvar rainbow-html-rgb-colors-font-lock-keywords
63 '(("rgb(\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*)"
64 (0 (rainbow-colorize-rgb)))
65 ("rgba(\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*[0-9]*\.?[0-9]+\s*%?\s*)"
66 (0 (rainbow-colorize-rgb)))
67 ("hsl(\s*\\([0-9]\\{1,3\\}\\)\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*)"
68 (0 (rainbow-colorize-hsl)))
69 ("hsla(\s*\\([0-9]\\{1,3\\}\\)\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*,\s*[0-9]*\.?[0-9]+\s*%?\s*)"
70 (0 (rainbow-colorize-hsl))))
71 "Font-lock keywords to add for RGB colors.")
74 (defvar rainbow-html-colors-font-lock-keywords nil
75 "Font-lock keywords to add for HTML colors.")
76 (make-variable-buffer-local 'rainbow-html-colors-font-lock-keywords)
78 (defcustom rainbow-html-colors-alist
79 '(("AliceBlue" . "#F0F8FF")
80 ("AntiqueWhite" . "#FAEBD7")
82 ("Aquamarine" . "#7FFFD4")
85 ("Bisque" . "#FFE4C4")
87 ("BlanchedAlmond" . "#FFEBCD")
89 ("BlueViolet" . "#8A2BE2")
91 ("BurlyWood" . "#DEB887")
92 ("CadetBlue" . "#5F9EA0")
93 ("Chartreuse" . "#7FFF00")
94 ("Chocolate" . "#D2691E")
96 ("CornflowerBlue" . "#6495ED")
97 ("Cornsilk" . "#FFF8DC")
98 ("Crimson" . "#DC143C")
100 ("DarkBlue" . "#00008B")
101 ("DarkCyan" . "#008B8B")
102 ("DarkGoldenRod" . "#B8860B")
103 ("DarkGray" . "#A9A9A9")
104 ("DarkGrey" . "#A9A9A9")
105 ("DarkGreen" . "#006400")
106 ("DarkKhaki" . "#BDB76B")
107 ("DarkMagenta" . "#8B008B")
108 ("DarkOliveGreen" . "#556B2F")
109 ("Darkorange" . "#FF8C00")
110 ("DarkOrchid" . "#9932CC")
111 ("DarkRed" . "#8B0000")
112 ("DarkSalmon" . "#E9967A")
113 ("DarkSeaGreen" . "#8FBC8F")
114 ("DarkSlateBlue" . "#483D8B")
115 ("DarkSlateGray" . "#2F4F4F")
116 ("DarkSlateGrey" . "#2F4F4F")
117 ("DarkTurquoise" . "#00CED1")
118 ("DarkViolet" . "#9400D3")
119 ("DeepPink" . "#FF1493")
120 ("DeepSkyBlue" . "#00BFFF")
121 ("DimGray" . "#696969")
122 ("DimGrey" . "#696969")
123 ("DodgerBlue" . "#1E90FF")
124 ("FireBrick" . "#B22222")
125 ("FloralWhite" . "#FFFAF0")
126 ("ForestGreen" . "#228B22")
127 ("Fuchsia" . "#FF00FF")
128 ("Gainsboro" . "#DCDCDC")
129 ("GhostWhite" . "#F8F8FF")
131 ("GoldenRod" . "#DAA520")
134 ("Green" . "#008000")
135 ("GreenYellow" . "#ADFF2F")
136 ("HoneyDew" . "#F0FFF0")
137 ("HotPink" . "#FF69B4")
138 ("IndianRed" . "#CD5C5C")
139 ("Indigo" . "#4B0082")
140 ("Ivory" . "#FFFFF0")
141 ("Khaki" . "#F0E68C")
142 ("Lavender" . "#E6E6FA")
143 ("LavenderBlush" . "#FFF0F5")
144 ("LawnGreen" . "#7CFC00")
145 ("LemonChiffon" . "#FFFACD")
146 ("LightBlue" . "#ADD8E6")
147 ("LightCoral" . "#F08080")
148 ("LightCyan" . "#E0FFFF")
149 ("LightGoldenRodYellow" . "#FAFAD2")
150 ("LightGray" . "#D3D3D3")
151 ("LightGrey" . "#D3D3D3")
152 ("LightGreen" . "#90EE90")
153 ("LightPink" . "#FFB6C1")
154 ("LightSalmon" . "#FFA07A")
155 ("LightSeaGreen" . "#20B2AA")
156 ("LightSkyBlue" . "#87CEFA")
157 ("LightSlateGray" . "#778899")
158 ("LightSlateGrey" . "#778899")
159 ("LightSteelBlue" . "#B0C4DE")
160 ("LightYellow" . "#FFFFE0")
162 ("LimeGreen" . "#32CD32")
163 ("Linen" . "#FAF0E6")
164 ("Magenta" . "#FF00FF")
165 ("Maroon" . "#800000")
166 ("MediumAquaMarine" . "#66CDAA")
167 ("MediumBlue" . "#0000CD")
168 ("MediumOrchid" . "#BA55D3")
169 ("MediumPurple" . "#9370D8")
170 ("MediumSeaGreen" . "#3CB371")
171 ("MediumSlateBlue" . "#7B68EE")
172 ("MediumSpringGreen" . "#00FA9A")
173 ("MediumTurquoise" . "#48D1CC")
174 ("MediumVioletRed" . "#C71585")
175 ("MidnightBlue" . "#191970")
176 ("MintCream" . "#F5FFFA")
177 ("MistyRose" . "#FFE4E1")
178 ("Moccasin" . "#FFE4B5")
179 ("NavajoWhite" . "#FFDEAD")
181 ("OldLace" . "#FDF5E6")
182 ("Olive" . "#808000")
183 ("OliveDrab" . "#6B8E23")
184 ("Orange" . "#FFA500")
185 ("OrangeRed" . "#FF4500")
186 ("Orchid" . "#DA70D6")
187 ("PaleGoldenRod" . "#EEE8AA")
188 ("PaleGreen" . "#98FB98")
189 ("PaleTurquoise" . "#AFEEEE")
190 ("PaleVioletRed" . "#D87093")
191 ("PapayaWhip" . "#FFEFD5")
192 ("PeachPuff" . "#FFDAB9")
196 ("PowderBlue" . "#B0E0E6")
197 ("Purple" . "#800080")
199 ("RosyBrown" . "#BC8F8F")
200 ("RoyalBlue" . "#4169E1")
201 ("SaddleBrown" . "#8B4513")
202 ("Salmon" . "#FA8072")
203 ("SandyBrown" . "#F4A460")
204 ("SeaGreen" . "#2E8B57")
205 ("SeaShell" . "#FFF5EE")
206 ("Sienna" . "#A0522D")
207 ("Silver" . "#C0C0C0")
208 ("SkyBlue" . "#87CEEB")
209 ("SlateBlue" . "#6A5ACD")
210 ("SlateGray" . "#708090")
211 ("SlateGrey" . "#708090")
213 ("SpringGreen" . "#00FF7F")
214 ("SteelBlue" . "#4682B4")
217 ("Thistle" . "#D8BFD8")
218 ("Tomato" . "#FF6347")
219 ("Turquoise" . "#40E0D0")
220 ("Violet" . "#EE82EE")
221 ("Wheat" . "#F5DEB3")
222 ("White" . "#FFFFFF")
223 ("WhiteSmoke" . "#F5F5F5")
224 ("Yellow" . "#FFFF00")
225 ("YellowGreen" . "#9ACD32"))
226 "Alist of HTML colors.
227 Each entry should have the form (COLOR-NAME . HEXADECIMAL-COLOR)."
230 (defcustom rainbow-html-colors-major-mode-list
231 '(html-mode css-mode php-mode nxml-mode xml-mode)
232 "List of major mode where HTML colors are enabled when
233 `rainbow-html-colors' is set to auto."
236 (defcustom rainbow-html-colors 'auto
237 "When to enable HTML colors.
238 If set to t, the HTML colors will be enabled. If set to nil, the
239 HTML colors will not be enabled. If set to auto, the HTML colors
240 will be enabled if a major mode has been detected from the
241 `rainbow-html-colors-major-mode-list'."
245 (defvar rainbow-x-colors-font-lock-keywords
246 `((,(regexp-opt (x-defined-colors) 'words)
247 (0 (rainbow-colorize-itself))))
248 "Font-lock keywords to add for X colors.")
250 (defcustom rainbow-x-colors-major-mode-list
251 '(emacs-lisp-mode lisp-interaction-mode c-mode c++-mode java-mode)
252 "List of major mode where X colors are enabled when
253 `rainbow-x-colors' is set to auto."
256 (defcustom rainbow-x-colors 'auto
257 "When to enable X colors.
258 If set to t, the X colors will be enabled. If set to nil, the
259 X colors will not be enabled. If set to auto, the X colors
260 will be enabled if a major mode has been detected from the
261 `rainbow-x-colors-major-mode-list'."
265 (defvar rainbow-latex-rgb-colors-font-lock-keywords
266 '(("{rgb}{\\([0-9.]+\\),\\([0-9.]+\\),\\([0-9.]+\\)}"
267 (0 (rainbow-colorize-rgb-float)))
268 ("{RGB}{\\([0-9]\\{1,3\\}\\),\\([0-9]\\{1,3\\}\\),\\([0-9]\\{1,3\\}\\)}"
269 (0 (rainbow-colorize-rgb)))
270 ("{HTML}{\\([0-9A-Fa-f]\\{6\\}\\)}"
271 (0 (rainbow-colorize-hexadecimal-without-sharp))))
272 "Font-lock keywords to add for LaTeX colors.")
274 (defcustom rainbow-latex-colors-major-mode-list
276 "List of major mode where LaTeX colors are enabled when
277 `rainbow-x-colors' is set to auto."
280 (defcustom rainbow-latex-colors 'auto
281 "When to enable LaTeX colors.
282 If set to t, the LaTeX colors will be enabled. If set to nil, the
283 LaTeX colors will not be enabled. If set to auto, the LaTeX colors
284 will be enabled if a major mode has been detected from the
285 `rainbow-latex-colors-major-mode-list'."
289 (defvar rainbow-ansi-colors-font-lock-keywords
290 '(("\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\|\033\\)\\[\\([0-9;]*m\\)"
291 (0 (rainbow-colorize-ansi))))
292 "Font-lock keywords to add for ANSI colors.")
294 (defcustom rainbow-ansi-colors-major-mode-list
295 '(sh-mode c-mode c++-mode)
296 "List of major mode where ANSI colors are enabled when
297 `rainbow-ansi-colors' is set to auto."
300 (defcustom rainbow-ansi-colors 'auto
301 "When to enable ANSI colors.
302 If set to t, the ANSI colors will be enabled. If set to nil, the
303 ANSI colors will not be enabled. If set to auto, the ANSI colors
304 will be enabled if a major mode has been detected from the
305 `rainbow-ansi-colors-major-mode-list'."
311 (defvar rainbow-r-colors-font-lock-keywords nil
312 "Font-lock keywords to add for R colors.")
313 (make-variable-buffer-local 'rainbow-r-colors-font-lock-keywords)
315 ;; use the following code to generate the list in R
316 ;; output_colors <- function(colors) {for(color in colors) {col <- col2rgb(color); cat(sprintf("(\"%s\" . \"#%02X%02X%02X\")\n",color,col[1],col[2],col[3]));}}
317 ;; output_colors(colors())
318 (defcustom rainbow-r-colors-alist
319 '(("white" . "#FFFFFF")
320 ("aliceblue" . "#F0F8FF")
321 ("antiquewhite" . "#FAEBD7")
322 ("antiquewhite1" . "#FFEFDB")
323 ("antiquewhite2" . "#EEDFCC")
324 ("antiquewhite3" . "#CDC0B0")
325 ("antiquewhite4" . "#8B8378")
326 ("aquamarine" . "#7FFFD4")
327 ("aquamarine1" . "#7FFFD4")
328 ("aquamarine2" . "#76EEC6")
329 ("aquamarine3" . "#66CDAA")
330 ("aquamarine4" . "#458B74")
331 ("azure" . "#F0FFFF")
332 ("azure1" . "#F0FFFF")
333 ("azure2" . "#E0EEEE")
334 ("azure3" . "#C1CDCD")
335 ("azure4" . "#838B8B")
336 ("beige" . "#F5F5DC")
337 ("bisque" . "#FFE4C4")
338 ("bisque1" . "#FFE4C4")
339 ("bisque2" . "#EED5B7")
340 ("bisque3" . "#CDB79E")
341 ("bisque4" . "#8B7D6B")
342 ("black" . "#000000")
343 ("blanchedalmond" . "#FFEBCD")
345 ("blue1" . "#0000FF")
346 ("blue2" . "#0000EE")
347 ("blue3" . "#0000CD")
348 ("blue4" . "#00008B")
349 ("blueviolet" . "#8A2BE2")
350 ("brown" . "#A52A2A")
351 ("brown1" . "#FF4040")
352 ("brown2" . "#EE3B3B")
353 ("brown3" . "#CD3333")
354 ("brown4" . "#8B2323")
355 ("burlywood" . "#DEB887")
356 ("burlywood1" . "#FFD39B")
357 ("burlywood2" . "#EEC591")
358 ("burlywood3" . "#CDAA7D")
359 ("burlywood4" . "#8B7355")
360 ("cadetblue" . "#5F9EA0")
361 ("cadetblue1" . "#98F5FF")
362 ("cadetblue2" . "#8EE5EE")
363 ("cadetblue3" . "#7AC5CD")
364 ("cadetblue4" . "#53868B")
365 ("chartreuse" . "#7FFF00")
366 ("chartreuse1" . "#7FFF00")
367 ("chartreuse2" . "#76EE00")
368 ("chartreuse3" . "#66CD00")
369 ("chartreuse4" . "#458B00")
370 ("chocolate" . "#D2691E")
371 ("chocolate1" . "#FF7F24")
372 ("chocolate2" . "#EE7621")
373 ("chocolate3" . "#CD661D")
374 ("chocolate4" . "#8B4513")
375 ("coral" . "#FF7F50")
376 ("coral1" . "#FF7256")
377 ("coral2" . "#EE6A50")
378 ("coral3" . "#CD5B45")
379 ("coral4" . "#8B3E2F")
380 ("cornflowerblue" . "#6495ED")
381 ("cornsilk" . "#FFF8DC")
382 ("cornsilk1" . "#FFF8DC")
383 ("cornsilk2" . "#EEE8CD")
384 ("cornsilk3" . "#CDC8B1")
385 ("cornsilk4" . "#8B8878")
387 ("cyan1" . "#00FFFF")
388 ("cyan2" . "#00EEEE")
389 ("cyan3" . "#00CDCD")
390 ("cyan4" . "#008B8B")
391 ("darkblue" . "#00008B")
392 ("darkcyan" . "#008B8B")
393 ("darkgoldenrod" . "#B8860B")
394 ("darkgoldenrod1" . "#FFB90F")
395 ("darkgoldenrod2" . "#EEAD0E")
396 ("darkgoldenrod3" . "#CD950C")
397 ("darkgoldenrod4" . "#8B6508")
398 ("darkgray" . "#A9A9A9")
399 ("darkgreen" . "#006400")
400 ("darkgrey" . "#A9A9A9")
401 ("darkkhaki" . "#BDB76B")
402 ("darkmagenta" . "#8B008B")
403 ("darkolivegreen" . "#556B2F")
404 ("darkolivegreen1" . "#CAFF70")
405 ("darkolivegreen2" . "#BCEE68")
406 ("darkolivegreen3" . "#A2CD5A")
407 ("darkolivegreen4" . "#6E8B3D")
408 ("darkorange" . "#FF8C00")
409 ("darkorange1" . "#FF7F00")
410 ("darkorange2" . "#EE7600")
411 ("darkorange3" . "#CD6600")
412 ("darkorange4" . "#8B4500")
413 ("darkorchid" . "#9932CC")
414 ("darkorchid1" . "#BF3EFF")
415 ("darkorchid2" . "#B23AEE")
416 ("darkorchid3" . "#9A32CD")
417 ("darkorchid4" . "#68228B")
418 ("darkred" . "#8B0000")
419 ("darksalmon" . "#E9967A")
420 ("darkseagreen" . "#8FBC8F")
421 ("darkseagreen1" . "#C1FFC1")
422 ("darkseagreen2" . "#B4EEB4")
423 ("darkseagreen3" . "#9BCD9B")
424 ("darkseagreen4" . "#698B69")
425 ("darkslateblue" . "#483D8B")
426 ("darkslategray" . "#2F4F4F")
427 ("darkslategray1" . "#97FFFF")
428 ("darkslategray2" . "#8DEEEE")
429 ("darkslategray3" . "#79CDCD")
430 ("darkslategray4" . "#528B8B")
431 ("darkslategrey" . "#2F4F4F")
432 ("darkturquoise" . "#00CED1")
433 ("darkviolet" . "#9400D3")
434 ("deeppink" . "#FF1493")
435 ("deeppink1" . "#FF1493")
436 ("deeppink2" . "#EE1289")
437 ("deeppink3" . "#CD1076")
438 ("deeppink4" . "#8B0A50")
439 ("deepskyblue" . "#00BFFF")
440 ("deepskyblue1" . "#00BFFF")
441 ("deepskyblue2" . "#00B2EE")
442 ("deepskyblue3" . "#009ACD")
443 ("deepskyblue4" . "#00688B")
444 ("dimgray" . "#696969")
445 ("dimgrey" . "#696969")
446 ("dodgerblue" . "#1E90FF")
447 ("dodgerblue1" . "#1E90FF")
448 ("dodgerblue2" . "#1C86EE")
449 ("dodgerblue3" . "#1874CD")
450 ("dodgerblue4" . "#104E8B")
451 ("firebrick" . "#B22222")
452 ("firebrick1" . "#FF3030")
453 ("firebrick2" . "#EE2C2C")
454 ("firebrick3" . "#CD2626")
455 ("firebrick4" . "#8B1A1A")
456 ("floralwhite" . "#FFFAF0")
457 ("forestgreen" . "#228B22")
458 ("gainsboro" . "#DCDCDC")
459 ("ghostwhite" . "#F8F8FF")
461 ("gold1" . "#FFD700")
462 ("gold2" . "#EEC900")
463 ("gold3" . "#CDAD00")
464 ("gold4" . "#8B7500")
465 ("goldenrod" . "#DAA520")
466 ("goldenrod1" . "#FFC125")
467 ("goldenrod2" . "#EEB422")
468 ("goldenrod3" . "#CD9B1D")
469 ("goldenrod4" . "#8B6914")
471 ("gray0" . "#000000")
472 ("gray1" . "#030303")
473 ("gray2" . "#050505")
474 ("gray3" . "#080808")
475 ("gray4" . "#0A0A0A")
476 ("gray5" . "#0D0D0D")
477 ("gray6" . "#0F0F0F")
478 ("gray7" . "#121212")
479 ("gray8" . "#141414")
480 ("gray9" . "#171717")
481 ("gray10" . "#1A1A1A")
482 ("gray11" . "#1C1C1C")
483 ("gray12" . "#1F1F1F")
484 ("gray13" . "#212121")
485 ("gray14" . "#242424")
486 ("gray15" . "#262626")
487 ("gray16" . "#292929")
488 ("gray17" . "#2B2B2B")
489 ("gray18" . "#2E2E2E")
490 ("gray19" . "#303030")
491 ("gray20" . "#333333")
492 ("gray21" . "#363636")
493 ("gray22" . "#383838")
494 ("gray23" . "#3B3B3B")
495 ("gray24" . "#3D3D3D")
496 ("gray25" . "#404040")
497 ("gray26" . "#424242")
498 ("gray27" . "#454545")
499 ("gray28" . "#474747")
500 ("gray29" . "#4A4A4A")
501 ("gray30" . "#4D4D4D")
502 ("gray31" . "#4F4F4F")
503 ("gray32" . "#525252")
504 ("gray33" . "#545454")
505 ("gray34" . "#575757")
506 ("gray35" . "#595959")
507 ("gray36" . "#5C5C5C")
508 ("gray37" . "#5E5E5E")
509 ("gray38" . "#616161")
510 ("gray39" . "#636363")
511 ("gray40" . "#666666")
512 ("gray41" . "#696969")
513 ("gray42" . "#6B6B6B")
514 ("gray43" . "#6E6E6E")
515 ("gray44" . "#707070")
516 ("gray45" . "#737373")
517 ("gray46" . "#757575")
518 ("gray47" . "#787878")
519 ("gray48" . "#7A7A7A")
520 ("gray49" . "#7D7D7D")
521 ("gray50" . "#7F7F7F")
522 ("gray51" . "#828282")
523 ("gray52" . "#858585")
524 ("gray53" . "#878787")
525 ("gray54" . "#8A8A8A")
526 ("gray55" . "#8C8C8C")
527 ("gray56" . "#8F8F8F")
528 ("gray57" . "#919191")
529 ("gray58" . "#949494")
530 ("gray59" . "#969696")
531 ("gray60" . "#999999")
532 ("gray61" . "#9C9C9C")
533 ("gray62" . "#9E9E9E")
534 ("gray63" . "#A1A1A1")
535 ("gray64" . "#A3A3A3")
536 ("gray65" . "#A6A6A6")
537 ("gray66" . "#A8A8A8")
538 ("gray67" . "#ABABAB")
539 ("gray68" . "#ADADAD")
540 ("gray69" . "#B0B0B0")
541 ("gray70" . "#B3B3B3")
542 ("gray71" . "#B5B5B5")
543 ("gray72" . "#B8B8B8")
544 ("gray73" . "#BABABA")
545 ("gray74" . "#BDBDBD")
546 ("gray75" . "#BFBFBF")
547 ("gray76" . "#C2C2C2")
548 ("gray77" . "#C4C4C4")
549 ("gray78" . "#C7C7C7")
550 ("gray79" . "#C9C9C9")
551 ("gray80" . "#CCCCCC")
552 ("gray81" . "#CFCFCF")
553 ("gray82" . "#D1D1D1")
554 ("gray83" . "#D4D4D4")
555 ("gray84" . "#D6D6D6")
556 ("gray85" . "#D9D9D9")
557 ("gray86" . "#DBDBDB")
558 ("gray87" . "#DEDEDE")
559 ("gray88" . "#E0E0E0")
560 ("gray89" . "#E3E3E3")
561 ("gray90" . "#E5E5E5")
562 ("gray91" . "#E8E8E8")
563 ("gray92" . "#EBEBEB")
564 ("gray93" . "#EDEDED")
565 ("gray94" . "#F0F0F0")
566 ("gray95" . "#F2F2F2")
567 ("gray96" . "#F5F5F5")
568 ("gray97" . "#F7F7F7")
569 ("gray98" . "#FAFAFA")
570 ("gray99" . "#FCFCFC")
571 ("gray100" . "#FFFFFF")
572 ("green" . "#00FF00")
573 ("green1" . "#00FF00")
574 ("green2" . "#00EE00")
575 ("green3" . "#00CD00")
576 ("green4" . "#008B00")
577 ("greenyellow" . "#ADFF2F")
579 ("grey0" . "#000000")
580 ("grey1" . "#030303")
581 ("grey2" . "#050505")
582 ("grey3" . "#080808")
583 ("grey4" . "#0A0A0A")
584 ("grey5" . "#0D0D0D")
585 ("grey6" . "#0F0F0F")
586 ("grey7" . "#121212")
587 ("grey8" . "#141414")
588 ("grey9" . "#171717")
589 ("grey10" . "#1A1A1A")
590 ("grey11" . "#1C1C1C")
591 ("grey12" . "#1F1F1F")
592 ("grey13" . "#212121")
593 ("grey14" . "#242424")
594 ("grey15" . "#262626")
595 ("grey16" . "#292929")
596 ("grey17" . "#2B2B2B")
597 ("grey18" . "#2E2E2E")
598 ("grey19" . "#303030")
599 ("grey20" . "#333333")
600 ("grey21" . "#363636")
601 ("grey22" . "#383838")
602 ("grey23" . "#3B3B3B")
603 ("grey24" . "#3D3D3D")
604 ("grey25" . "#404040")
605 ("grey26" . "#424242")
606 ("grey27" . "#454545")
607 ("grey28" . "#474747")
608 ("grey29" . "#4A4A4A")
609 ("grey30" . "#4D4D4D")
610 ("grey31" . "#4F4F4F")
611 ("grey32" . "#525252")
612 ("grey33" . "#545454")
613 ("grey34" . "#575757")
614 ("grey35" . "#595959")
615 ("grey36" . "#5C5C5C")
616 ("grey37" . "#5E5E5E")
617 ("grey38" . "#616161")
618 ("grey39" . "#636363")
619 ("grey40" . "#666666")
620 ("grey41" . "#696969")
621 ("grey42" . "#6B6B6B")
622 ("grey43" . "#6E6E6E")
623 ("grey44" . "#707070")
624 ("grey45" . "#737373")
625 ("grey46" . "#757575")
626 ("grey47" . "#787878")
627 ("grey48" . "#7A7A7A")
628 ("grey49" . "#7D7D7D")
629 ("grey50" . "#7F7F7F")
630 ("grey51" . "#828282")
631 ("grey52" . "#858585")
632 ("grey53" . "#878787")
633 ("grey54" . "#8A8A8A")
634 ("grey55" . "#8C8C8C")
635 ("grey56" . "#8F8F8F")
636 ("grey57" . "#919191")
637 ("grey58" . "#949494")
638 ("grey59" . "#969696")
639 ("grey60" . "#999999")
640 ("grey61" . "#9C9C9C")
641 ("grey62" . "#9E9E9E")
642 ("grey63" . "#A1A1A1")
643 ("grey64" . "#A3A3A3")
644 ("grey65" . "#A6A6A6")
645 ("grey66" . "#A8A8A8")
646 ("grey67" . "#ABABAB")
647 ("grey68" . "#ADADAD")
648 ("grey69" . "#B0B0B0")
649 ("grey70" . "#B3B3B3")
650 ("grey71" . "#B5B5B5")
651 ("grey72" . "#B8B8B8")
652 ("grey73" . "#BABABA")
653 ("grey74" . "#BDBDBD")
654 ("grey75" . "#BFBFBF")
655 ("grey76" . "#C2C2C2")
656 ("grey77" . "#C4C4C4")
657 ("grey78" . "#C7C7C7")
658 ("grey79" . "#C9C9C9")
659 ("grey80" . "#CCCCCC")
660 ("grey81" . "#CFCFCF")
661 ("grey82" . "#D1D1D1")
662 ("grey83" . "#D4D4D4")
663 ("grey84" . "#D6D6D6")
664 ("grey85" . "#D9D9D9")
665 ("grey86" . "#DBDBDB")
666 ("grey87" . "#DEDEDE")
667 ("grey88" . "#E0E0E0")
668 ("grey89" . "#E3E3E3")
669 ("grey90" . "#E5E5E5")
670 ("grey91" . "#E8E8E8")
671 ("grey92" . "#EBEBEB")
672 ("grey93" . "#EDEDED")
673 ("grey94" . "#F0F0F0")
674 ("grey95" . "#F2F2F2")
675 ("grey96" . "#F5F5F5")
676 ("grey97" . "#F7F7F7")
677 ("grey98" . "#FAFAFA")
678 ("grey99" . "#FCFCFC")
679 ("grey100" . "#FFFFFF")
680 ("honeydew" . "#F0FFF0")
681 ("honeydew1" . "#F0FFF0")
682 ("honeydew2" . "#E0EEE0")
683 ("honeydew3" . "#C1CDC1")
684 ("honeydew4" . "#838B83")
685 ("hotpink" . "#FF69B4")
686 ("hotpink1" . "#FF6EB4")
687 ("hotpink2" . "#EE6AA7")
688 ("hotpink3" . "#CD6090")
689 ("hotpink4" . "#8B3A62")
690 ("indianred" . "#CD5C5C")
691 ("indianred1" . "#FF6A6A")
692 ("indianred2" . "#EE6363")
693 ("indianred3" . "#CD5555")
694 ("indianred4" . "#8B3A3A")
695 ("ivory" . "#FFFFF0")
696 ("ivory1" . "#FFFFF0")
697 ("ivory2" . "#EEEEE0")
698 ("ivory3" . "#CDCDC1")
699 ("ivory4" . "#8B8B83")
700 ("khaki" . "#F0E68C")
701 ("khaki1" . "#FFF68F")
702 ("khaki2" . "#EEE685")
703 ("khaki3" . "#CDC673")
704 ("khaki4" . "#8B864E")
705 ("lavender" . "#E6E6FA")
706 ("lavenderblush" . "#FFF0F5")
707 ("lavenderblush1" . "#FFF0F5")
708 ("lavenderblush2" . "#EEE0E5")
709 ("lavenderblush3" . "#CDC1C5")
710 ("lavenderblush4" . "#8B8386")
711 ("lawngreen" . "#7CFC00")
712 ("lemonchiffon" . "#FFFACD")
713 ("lemonchiffon1" . "#FFFACD")
714 ("lemonchiffon2" . "#EEE9BF")
715 ("lemonchiffon3" . "#CDC9A5")
716 ("lemonchiffon4" . "#8B8970")
717 ("lightblue" . "#ADD8E6")
718 ("lightblue1" . "#BFEFFF")
719 ("lightblue2" . "#B2DFEE")
720 ("lightblue3" . "#9AC0CD")
721 ("lightblue4" . "#68838B")
722 ("lightcoral" . "#F08080")
723 ("lightcyan" . "#E0FFFF")
724 ("lightcyan1" . "#E0FFFF")
725 ("lightcyan2" . "#D1EEEE")
726 ("lightcyan3" . "#B4CDCD")
727 ("lightcyan4" . "#7A8B8B")
728 ("lightgoldenrod" . "#EEDD82")
729 ("lightgoldenrod1" . "#FFEC8B")
730 ("lightgoldenrod2" . "#EEDC82")
731 ("lightgoldenrod3" . "#CDBE70")
732 ("lightgoldenrod4" . "#8B814C")
733 ("lightgoldenrodyellow" . "#FAFAD2")
734 ("lightgray" . "#D3D3D3")
735 ("lightgreen" . "#90EE90")
736 ("lightgrey" . "#D3D3D3")
737 ("lightpink" . "#FFB6C1")
738 ("lightpink1" . "#FFAEB9")
739 ("lightpink2" . "#EEA2AD")
740 ("lightpink3" . "#CD8C95")
741 ("lightpink4" . "#8B5F65")
742 ("lightsalmon" . "#FFA07A")
743 ("lightsalmon1" . "#FFA07A")
744 ("lightsalmon2" . "#EE9572")
745 ("lightsalmon3" . "#CD8162")
746 ("lightsalmon4" . "#8B5742")
747 ("lightseagreen" . "#20B2AA")
748 ("lightskyblue" . "#87CEFA")
749 ("lightskyblue1" . "#B0E2FF")
750 ("lightskyblue2" . "#A4D3EE")
751 ("lightskyblue3" . "#8DB6CD")
752 ("lightskyblue4" . "#607B8B")
753 ("lightslateblue" . "#8470FF")
754 ("lightslategray" . "#778899")
755 ("lightslategrey" . "#778899")
756 ("lightsteelblue" . "#B0C4DE")
757 ("lightsteelblue1" . "#CAE1FF")
758 ("lightsteelblue2" . "#BCD2EE")
759 ("lightsteelblue3" . "#A2B5CD")
760 ("lightsteelblue4" . "#6E7B8B")
761 ("lightyellow" . "#FFFFE0")
762 ("lightyellow1" . "#FFFFE0")
763 ("lightyellow2" . "#EEEED1")
764 ("lightyellow3" . "#CDCDB4")
765 ("lightyellow4" . "#8B8B7A")
766 ("limegreen" . "#32CD32")
767 ("linen" . "#FAF0E6")
768 ("magenta" . "#FF00FF")
769 ("magenta1" . "#FF00FF")
770 ("magenta2" . "#EE00EE")
771 ("magenta3" . "#CD00CD")
772 ("magenta4" . "#8B008B")
773 ("maroon" . "#B03060")
774 ("maroon1" . "#FF34B3")
775 ("maroon2" . "#EE30A7")
776 ("maroon3" . "#CD2990")
777 ("maroon4" . "#8B1C62")
778 ("mediumaquamarine" . "#66CDAA")
779 ("mediumblue" . "#0000CD")
780 ("mediumorchid" . "#BA55D3")
781 ("mediumorchid1" . "#E066FF")
782 ("mediumorchid2" . "#D15FEE")
783 ("mediumorchid3" . "#B452CD")
784 ("mediumorchid4" . "#7A378B")
785 ("mediumpurple" . "#9370DB")
786 ("mediumpurple1" . "#AB82FF")
787 ("mediumpurple2" . "#9F79EE")
788 ("mediumpurple3" . "#8968CD")
789 ("mediumpurple4" . "#5D478B")
790 ("mediumseagreen" . "#3CB371")
791 ("mediumslateblue" . "#7B68EE")
792 ("mediumspringgreen" . "#00FA9A")
793 ("mediumturquoise" . "#48D1CC")
794 ("mediumvioletred" . "#C71585")
795 ("midnightblue" . "#191970")
796 ("mintcream" . "#F5FFFA")
797 ("mistyrose" . "#FFE4E1")
798 ("mistyrose1" . "#FFE4E1")
799 ("mistyrose2" . "#EED5D2")
800 ("mistyrose3" . "#CDB7B5")
801 ("mistyrose4" . "#8B7D7B")
802 ("moccasin" . "#FFE4B5")
803 ("navajowhite" . "#FFDEAD")
804 ("navajowhite1" . "#FFDEAD")
805 ("navajowhite2" . "#EECFA1")
806 ("navajowhite3" . "#CDB38B")
807 ("navajowhite4" . "#8B795E")
809 ("navyblue" . "#000080")
810 ("oldlace" . "#FDF5E6")
811 ("olivedrab" . "#6B8E23")
812 ("olivedrab1" . "#C0FF3E")
813 ("olivedrab2" . "#B3EE3A")
814 ("olivedrab3" . "#9ACD32")
815 ("olivedrab4" . "#698B22")
816 ("orange" . "#FFA500")
817 ("orange1" . "#FFA500")
818 ("orange2" . "#EE9A00")
819 ("orange3" . "#CD8500")
820 ("orange4" . "#8B5A00")
821 ("orangered" . "#FF4500")
822 ("orangered1" . "#FF4500")
823 ("orangered2" . "#EE4000")
824 ("orangered3" . "#CD3700")
825 ("orangered4" . "#8B2500")
826 ("orchid" . "#DA70D6")
827 ("orchid1" . "#FF83FA")
828 ("orchid2" . "#EE7AE9")
829 ("orchid3" . "#CD69C9")
830 ("orchid4" . "#8B4789")
831 ("palegoldenrod" . "#EEE8AA")
832 ("palegreen" . "#98FB98")
833 ("palegreen1" . "#9AFF9A")
834 ("palegreen2" . "#90EE90")
835 ("palegreen3" . "#7CCD7C")
836 ("palegreen4" . "#548B54")
837 ("paleturquoise" . "#AFEEEE")
838 ("paleturquoise1" . "#BBFFFF")
839 ("paleturquoise2" . "#AEEEEE")
840 ("paleturquoise3" . "#96CDCD")
841 ("paleturquoise4" . "#668B8B")
842 ("palevioletred" . "#DB7093")
843 ("palevioletred1" . "#FF82AB")
844 ("palevioletred2" . "#EE799F")
845 ("palevioletred3" . "#CD6889")
846 ("palevioletred4" . "#8B475D")
847 ("papayawhip" . "#FFEFD5")
848 ("peachpuff" . "#FFDAB9")
849 ("peachpuff1" . "#FFDAB9")
850 ("peachpuff2" . "#EECBAD")
851 ("peachpuff3" . "#CDAF95")
852 ("peachpuff4" . "#8B7765")
855 ("pink1" . "#FFB5C5")
856 ("pink2" . "#EEA9B8")
857 ("pink3" . "#CD919E")
858 ("pink4" . "#8B636C")
860 ("plum1" . "#FFBBFF")
861 ("plum2" . "#EEAEEE")
862 ("plum3" . "#CD96CD")
863 ("plum4" . "#8B668B")
864 ("powderblue" . "#B0E0E6")
865 ("purple" . "#A020F0")
866 ("purple1" . "#9B30FF")
867 ("purple2" . "#912CEE")
868 ("purple3" . "#7D26CD")
869 ("purple4" . "#551A8B")
875 ("rosybrown" . "#BC8F8F")
876 ("rosybrown1" . "#FFC1C1")
877 ("rosybrown2" . "#EEB4B4")
878 ("rosybrown3" . "#CD9B9B")
879 ("rosybrown4" . "#8B6969")
880 ("royalblue" . "#4169E1")
881 ("royalblue1" . "#4876FF")
882 ("royalblue2" . "#436EEE")
883 ("royalblue3" . "#3A5FCD")
884 ("royalblue4" . "#27408B")
885 ("saddlebrown" . "#8B4513")
886 ("salmon" . "#FA8072")
887 ("salmon1" . "#FF8C69")
888 ("salmon2" . "#EE8262")
889 ("salmon3" . "#CD7054")
890 ("salmon4" . "#8B4C39")
891 ("sandybrown" . "#F4A460")
892 ("seagreen" . "#2E8B57")
893 ("seagreen1" . "#54FF9F")
894 ("seagreen2" . "#4EEE94")
895 ("seagreen3" . "#43CD80")
896 ("seagreen4" . "#2E8B57")
897 ("seashell" . "#FFF5EE")
898 ("seashell1" . "#FFF5EE")
899 ("seashell2" . "#EEE5DE")
900 ("seashell3" . "#CDC5BF")
901 ("seashell4" . "#8B8682")
902 ("sienna" . "#A0522D")
903 ("sienna1" . "#FF8247")
904 ("sienna2" . "#EE7942")
905 ("sienna3" . "#CD6839")
906 ("sienna4" . "#8B4726")
907 ("skyblue" . "#87CEEB")
908 ("skyblue1" . "#87CEFF")
909 ("skyblue2" . "#7EC0EE")
910 ("skyblue3" . "#6CA6CD")
911 ("skyblue4" . "#4A708B")
912 ("slateblue" . "#6A5ACD")
913 ("slateblue1" . "#836FFF")
914 ("slateblue2" . "#7A67EE")
915 ("slateblue3" . "#6959CD")
916 ("slateblue4" . "#473C8B")
917 ("slategray" . "#708090")
918 ("slategray1" . "#C6E2FF")
919 ("slategray2" . "#B9D3EE")
920 ("slategray3" . "#9FB6CD")
921 ("slategray4" . "#6C7B8B")
922 ("slategrey" . "#708090")
924 ("snow1" . "#FFFAFA")
925 ("snow2" . "#EEE9E9")
926 ("snow3" . "#CDC9C9")
927 ("snow4" . "#8B8989")
928 ("springgreen" . "#00FF7F")
929 ("springgreen1" . "#00FF7F")
930 ("springgreen2" . "#00EE76")
931 ("springgreen3" . "#00CD66")
932 ("springgreen4" . "#008B45")
933 ("steelblue" . "#4682B4")
934 ("steelblue1" . "#63B8FF")
935 ("steelblue2" . "#5CACEE")
936 ("steelblue3" . "#4F94CD")
937 ("steelblue4" . "#36648B")
943 ("thistle" . "#D8BFD8")
944 ("thistle1" . "#FFE1FF")
945 ("thistle2" . "#EED2EE")
946 ("thistle3" . "#CDB5CD")
947 ("thistle4" . "#8B7B8B")
948 ("tomato" . "#FF6347")
949 ("tomato1" . "#FF6347")
950 ("tomato2" . "#EE5C42")
951 ("tomato3" . "#CD4F39")
952 ("tomato4" . "#8B3626")
953 ("turquoise" . "#40E0D0")
954 ("turquoise1" . "#00F5FF")
955 ("turquoise2" . "#00E5EE")
956 ("turquoise3" . "#00C5CD")
957 ("turquoise4" . "#00868B")
958 ("violet" . "#EE82EE")
959 ("violetred" . "#D02090")
960 ("violetred1" . "#FF3E96")
961 ("violetred2" . "#EE3A8C")
962 ("violetred3" . "#CD3278")
963 ("violetred4" . "#8B2252")
964 ("wheat" . "#F5DEB3")
965 ("wheat1" . "#FFE7BA")
966 ("wheat2" . "#EED8AE")
967 ("wheat3" . "#CDBA96")
968 ("wheat4" . "#8B7E66")
969 ("whitesmoke" . "#F5F5F5")
970 ("yellow" . "#FFFF00")
971 ("yellow1" . "#FFFF00")
972 ("yellow2" . "#EEEE00")
973 ("yellow3" . "#CDCD00")
974 ("yellow4" . "#8B8B00")
975 ("yellowgreen" . "#9ACD32"))
977 Each entry should have the form (COLOR-NAME . HEXADECIMAL-COLOR)."
979 (defcustom rainbow-r-colors-major-mode-list
981 "List of major mode where R colors are enabled when
982 `rainbow-r-colors' is set to auto."
985 (defcustom rainbow-r-colors 'auto
986 "When to enable R colors.
987 If set to t, the R colors will be enabled. If set to nil, the
988 R colors will not be enabled. If set to auto, the R colors
989 will be enabled if a major mode has been detected from the
990 `rainbow-r-colors-major-mode-list'."
995 (defun rainbow-colorize-match (color &optional match)
996 "Return a matched string propertized with a face whose
997 background is COLOR. The foreground is computed using
998 `rainbow-color-luminance', and is either white or black."
999 (let ((match (or match 0)))
1001 (match-beginning match) (match-end match)
1002 'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color))
1004 (:background ,color)))))
1006 (defun rainbow-colorize-itself (&optional match)
1007 "Colorize a match with itself."
1008 (rainbow-colorize-match (match-string-no-properties (or match 0)) match))
1010 (defun rainbow-colorize-hexadecimal-without-sharp ()
1011 "Colorize an hexadecimal colors and prepend # to it."
1012 (rainbow-colorize-match (concat "#" (match-string-no-properties 1))))
1014 (defun rainbow-colorize-by-assoc (assoc-list)
1015 "Colorize a match with its association from ASSOC-LIST."
1016 (rainbow-colorize-match (cdr (assoc-string (match-string-no-properties 0)
1019 (defun rainbow-rgb-relative-to-absolute (number)
1020 "Convert a relative NUMBER to absolute. If NUMBER is absolute, return NUMBER.
1021 This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"."
1022 (let ((string-length (- (length number) 1)))
1023 ;; Is this a number with %?
1024 (if (eq (elt number string-length) ?%)
1025 (/ (* (string-to-number (substring number 0 string-length)) 255) 100)
1026 (string-to-number number))))
1028 (defun rainbow-colorize-hsl ()
1029 "Colorize a match with itself."
1030 (let ((h (/ (string-to-number (match-string-no-properties 1)) 360.0))
1031 (s (/ (string-to-number (match-string-no-properties 2)) 100.0))
1032 (l (/ (string-to-number (match-string-no-properties 3)) 100.0)))
1033 (rainbow-colorize-match
1034 (multiple-value-bind (r g b)
1035 (color-hsl-to-rgb h s l)
1036 (format "#%02X%02X%02X" (* r 255) (* g 255) (* b 255))))))
1038 (defun rainbow-colorize-rgb ()
1039 "Colorize a match with itself."
1040 (let ((r (rainbow-rgb-relative-to-absolute (match-string-no-properties 1)))
1041 (g (rainbow-rgb-relative-to-absolute (match-string-no-properties 2)))
1042 (b (rainbow-rgb-relative-to-absolute (match-string-no-properties 3))))
1043 (rainbow-colorize-match (format "#%02X%02X%02X" r g b))))
1045 (defun rainbow-colorize-rgb-float ()
1046 "Colorize a match with itself, with relative value."
1047 (let ((r (* (string-to-number (match-string-no-properties 1)) 255.0))
1048 (g (* (string-to-number (match-string-no-properties 2)) 255.0))
1049 (b (* (string-to-number (match-string-no-properties 3)) 255.0)))
1050 (rainbow-colorize-match (format "#%02X%02X%02X" r g b))))
1052 (defun rainbow-colorize-ansi ()
1053 "Return a matched string propertized with ansi color face."
1054 (let ((xterm-color? (featurep 'xterm-color))
1055 (string (match-string-no-properties 0))
1058 (let* ((replaced (concat
1059 (replace-regexp-in-string
1060 "^\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\)"
1061 "\033" string) "x"))
1064 (applied (funcall (if xterm-color?
1068 (face-property (get-text-property
1070 (if xterm-color? 'face 'font-lock-face)
1072 (unless (listp (car face-property))
1073 (setq face-property (list face-property)))
1074 (setq color (funcall (if xterm-color? 'cadr 'cdr)
1075 (or (assq (if xterm-color?
1079 (assq (if xterm-color?
1084 (rainbow-colorize-match color))))
1086 (defun rainbow-color-luminance (red green blue)
1087 "Calculate the luminance of color composed of RED, BLUE and GREEN.
1088 Return a value between 0 and 1."
1089 (/ (+ (* .2126 red) (* .7152 green) (* .0722 blue)) 256))
1091 (defun rainbow-x-color-luminance (color)
1092 "Calculate the luminance of a color string (e.g. \"#ffaa00\", \"blue\").
1093 Return a value between 0 and 1."
1094 (let* ((values (x-color-values color))
1095 (r (/ (car values) 256.0))
1096 (g (/ (cadr values) 256.0))
1097 (b (/ (caddr values) 256.0)))
1098 (rainbow-color-luminance r g b)))
1100 (defun rainbow-turn-on ()
1101 "Turn on raibow-mode."
1102 (font-lock-add-keywords nil
1103 rainbow-hexadecimal-colors-font-lock-keywords)
1104 ;; Activate X colors?
1105 (when (or (eq rainbow-x-colors t)
1106 (and (eq rainbow-x-colors 'auto)
1107 (memq major-mode rainbow-x-colors-major-mode-list)))
1108 (font-lock-add-keywords nil
1109 rainbow-x-colors-font-lock-keywords))
1110 ;; Activate LaTeX colors?
1111 (when (or (eq rainbow-latex-colors t)
1112 (and (eq rainbow-latex-colors 'auto)
1113 (memq major-mode rainbow-latex-colors-major-mode-list)))
1114 (font-lock-add-keywords nil
1115 rainbow-latex-rgb-colors-font-lock-keywords))
1116 ;; Activate ANSI colors?
1117 (when (or (eq rainbow-ansi-colors t)
1118 (and (eq rainbow-ansi-colors 'auto)
1119 (memq major-mode rainbow-ansi-colors-major-mode-list)))
1120 (font-lock-add-keywords nil
1121 rainbow-ansi-colors-font-lock-keywords))
1122 ;; Activate HTML colors?
1123 (when (or (eq rainbow-html-colors t)
1124 (and (eq rainbow-html-colors 'auto)
1125 (memq major-mode rainbow-html-colors-major-mode-list)))
1126 (setq rainbow-html-colors-font-lock-keywords
1127 `((,(regexp-opt (mapcar 'car rainbow-html-colors-alist) 'words)
1128 (0 (rainbow-colorize-by-assoc rainbow-html-colors-alist)))))
1129 (font-lock-add-keywords nil
1130 `(,@rainbow-html-colors-font-lock-keywords
1131 ,@rainbow-html-rgb-colors-font-lock-keywords)))
1132 ;; Activate R colors?
1133 (when (or (eq rainbow-r-colors t)
1134 (and (eq rainbow-r-colors 'auto)
1135 (memq major-mode rainbow-r-colors-major-mode-list)))
1136 (setq rainbow-r-colors-font-lock-keywords
1137 `((,(regexp-opt (mapcar 'car rainbow-r-colors-alist) 'words)
1138 (0 (rainbow-colorize-by-assoc rainbow-r-colors-alist)))))
1139 (font-lock-add-keywords nil
1140 rainbow-r-colors-font-lock-keywords
1143 (defun rainbow-turn-off ()
1144 "Turn off rainbow-mode."
1145 (font-lock-remove-keywords
1147 `(,@rainbow-hexadecimal-colors-font-lock-keywords
1148 ,@rainbow-x-colors-font-lock-keywords
1149 ,@rainbow-latex-rgb-colors-font-lock-keywords
1150 ,@rainbow-r-colors-font-lock-keywords
1151 ,@rainbow-html-colors-font-lock-keywords
1152 ,@rainbow-html-rgb-colors-font-lock-keywords)))
1155 (define-minor-mode rainbow-mode
1156 "Colorize strings that represent colors.
1157 This will fontify with colors the string like \"#aabbcc\" or \"blue\"."
1162 (rainbow-turn-off))))
1164 (provide 'rainbow-mode)
1166 ;;; rainbow-mode.el ends here