rainbow-mode.el 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. ;;; rainbow-mode.el --- Colorize color names in buffers
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc
  3. ;; Author: Julien Danjou <julien@danjou.info>
  4. ;; Keywords: faces
  5. ;; Version: 0.6
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; This minor mode sets background color to strings that match color
  20. ;; names, e.g. #0000ff is displayed in white with a blue background.
  21. ;;
  22. ;;; Code:
  23. (eval-when-compile
  24. (require 'cl))
  25. (require 'regexp-opt)
  26. (require 'faces)
  27. (require 'color)
  28. (unless (require 'xterm-color nil t)
  29. (require 'ansi-color))
  30. (defgroup rainbow nil
  31. "Show color strings with a background color."
  32. :tag "Rainbow"
  33. :group 'help)
  34. ;; Hexadecimal colors
  35. (defvar rainbow-hexadecimal-colors-font-lock-keywords
  36. '(("[^&]\\(#\\(?:[0-9a-fA-F]\\{3\\}\\)+\\{1,4\\}\\)"
  37. (1 (rainbow-colorize-itself 1)))
  38. ("^\\(#\\(?:[0-9a-fA-F]\\{3\\}\\)+\\{1,4\\}\\)"
  39. (0 (rainbow-colorize-itself)))
  40. ("[Rr][Gg][Bb]:[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}"
  41. (0 (rainbow-colorize-itself)))
  42. ("[Rr][Gg][Bb][Ii]:[0-9.]+/[0-9.]+/[0-9.]+"
  43. (0 (rainbow-colorize-itself)))
  44. ("\\(?:[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]+\\)?"
  45. (0 (rainbow-colorize-itself))))
  46. "Font-lock keywords to add for hexadecimal colors.")
  47. ;; rgb() colors
  48. (defvar rainbow-html-rgb-colors-font-lock-keywords
  49. '(("rgb(\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*)"
  50. (0 (rainbow-colorize-rgb)))
  51. ("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*)"
  52. (0 (rainbow-colorize-rgb)))
  53. ("hsl(\s*\\([0-9]\\{1,3\\}\\)\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*)"
  54. (0 (rainbow-colorize-hsl)))
  55. ("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*)"
  56. (0 (rainbow-colorize-hsl))))
  57. "Font-lock keywords to add for RGB colors.")
  58. ;; HTML colors name
  59. (defvar rainbow-html-colors-font-lock-keywords nil
  60. "Font-lock keywords to add for HTML colors.")
  61. (make-variable-buffer-local 'rainbow-html-colors-font-lock-keywords)
  62. (defcustom rainbow-html-colors-alist
  63. '(("AliceBlue" . "#F0F8FF")
  64. ("AntiqueWhite" . "#FAEBD7")
  65. ("Aqua" . "#00FFFF")
  66. ("Aquamarine" . "#7FFFD4")
  67. ("Azure" . "#F0FFFF")
  68. ("Beige" . "#F5F5DC")
  69. ("Bisque" . "#FFE4C4")
  70. ("Black" . "#000000")
  71. ("BlanchedAlmond" . "#FFEBCD")
  72. ("Blue" . "#0000FF")
  73. ("BlueViolet" . "#8A2BE2")
  74. ("Brown" . "#A52A2A")
  75. ("BurlyWood" . "#DEB887")
  76. ("CadetBlue" . "#5F9EA0")
  77. ("Chartreuse" . "#7FFF00")
  78. ("Chocolate" . "#D2691E")
  79. ("Coral" . "#FF7F50")
  80. ("CornflowerBlue" . "#6495ED")
  81. ("Cornsilk" . "#FFF8DC")
  82. ("Crimson" . "#DC143C")
  83. ("Cyan" . "#00FFFF")
  84. ("DarkBlue" . "#00008B")
  85. ("DarkCyan" . "#008B8B")
  86. ("DarkGoldenRod" . "#B8860B")
  87. ("DarkGray" . "#A9A9A9")
  88. ("DarkGrey" . "#A9A9A9")
  89. ("DarkGreen" . "#006400")
  90. ("DarkKhaki" . "#BDB76B")
  91. ("DarkMagenta" . "#8B008B")
  92. ("DarkOliveGreen" . "#556B2F")
  93. ("Darkorange" . "#FF8C00")
  94. ("DarkOrchid" . "#9932CC")
  95. ("DarkRed" . "#8B0000")
  96. ("DarkSalmon" . "#E9967A")
  97. ("DarkSeaGreen" . "#8FBC8F")
  98. ("DarkSlateBlue" . "#483D8B")
  99. ("DarkSlateGray" . "#2F4F4F")
  100. ("DarkSlateGrey" . "#2F4F4F")
  101. ("DarkTurquoise" . "#00CED1")
  102. ("DarkViolet" . "#9400D3")
  103. ("DeepPink" . "#FF1493")
  104. ("DeepSkyBlue" . "#00BFFF")
  105. ("DimGray" . "#696969")
  106. ("DimGrey" . "#696969")
  107. ("DodgerBlue" . "#1E90FF")
  108. ("FireBrick" . "#B22222")
  109. ("FloralWhite" . "#FFFAF0")
  110. ("ForestGreen" . "#228B22")
  111. ("Fuchsia" . "#FF00FF")
  112. ("Gainsboro" . "#DCDCDC")
  113. ("GhostWhite" . "#F8F8FF")
  114. ("Gold" . "#FFD700")
  115. ("GoldenRod" . "#DAA520")
  116. ("Gray" . "#808080")
  117. ("Grey" . "#808080")
  118. ("Green" . "#008000")
  119. ("GreenYellow" . "#ADFF2F")
  120. ("HoneyDew" . "#F0FFF0")
  121. ("HotPink" . "#FF69B4")
  122. ("IndianRed" . "#CD5C5C")
  123. ("Indigo" . "#4B0082")
  124. ("Ivory" . "#FFFFF0")
  125. ("Khaki" . "#F0E68C")
  126. ("Lavender" . "#E6E6FA")
  127. ("LavenderBlush" . "#FFF0F5")
  128. ("LawnGreen" . "#7CFC00")
  129. ("LemonChiffon" . "#FFFACD")
  130. ("LightBlue" . "#ADD8E6")
  131. ("LightCoral" . "#F08080")
  132. ("LightCyan" . "#E0FFFF")
  133. ("LightGoldenRodYellow" . "#FAFAD2")
  134. ("LightGray" . "#D3D3D3")
  135. ("LightGrey" . "#D3D3D3")
  136. ("LightGreen" . "#90EE90")
  137. ("LightPink" . "#FFB6C1")
  138. ("LightSalmon" . "#FFA07A")
  139. ("LightSeaGreen" . "#20B2AA")
  140. ("LightSkyBlue" . "#87CEFA")
  141. ("LightSlateGray" . "#778899")
  142. ("LightSlateGrey" . "#778899")
  143. ("LightSteelBlue" . "#B0C4DE")
  144. ("LightYellow" . "#FFFFE0")
  145. ("Lime" . "#00FF00")
  146. ("LimeGreen" . "#32CD32")
  147. ("Linen" . "#FAF0E6")
  148. ("Magenta" . "#FF00FF")
  149. ("Maroon" . "#800000")
  150. ("MediumAquaMarine" . "#66CDAA")
  151. ("MediumBlue" . "#0000CD")
  152. ("MediumOrchid" . "#BA55D3")
  153. ("MediumPurple" . "#9370D8")
  154. ("MediumSeaGreen" . "#3CB371")
  155. ("MediumSlateBlue" . "#7B68EE")
  156. ("MediumSpringGreen" . "#00FA9A")
  157. ("MediumTurquoise" . "#48D1CC")
  158. ("MediumVioletRed" . "#C71585")
  159. ("MidnightBlue" . "#191970")
  160. ("MintCream" . "#F5FFFA")
  161. ("MistyRose" . "#FFE4E1")
  162. ("Moccasin" . "#FFE4B5")
  163. ("NavajoWhite" . "#FFDEAD")
  164. ("Navy" . "#000080")
  165. ("OldLace" . "#FDF5E6")
  166. ("Olive" . "#808000")
  167. ("OliveDrab" . "#6B8E23")
  168. ("Orange" . "#FFA500")
  169. ("OrangeRed" . "#FF4500")
  170. ("Orchid" . "#DA70D6")
  171. ("PaleGoldenRod" . "#EEE8AA")
  172. ("PaleGreen" . "#98FB98")
  173. ("PaleTurquoise" . "#AFEEEE")
  174. ("PaleVioletRed" . "#D87093")
  175. ("PapayaWhip" . "#FFEFD5")
  176. ("PeachPuff" . "#FFDAB9")
  177. ("Peru" . "#CD853F")
  178. ("Pink" . "#FFC0CB")
  179. ("Plum" . "#DDA0DD")
  180. ("PowderBlue" . "#B0E0E6")
  181. ("Purple" . "#800080")
  182. ("Red" . "#FF0000")
  183. ("RosyBrown" . "#BC8F8F")
  184. ("RoyalBlue" . "#4169E1")
  185. ("SaddleBrown" . "#8B4513")
  186. ("Salmon" . "#FA8072")
  187. ("SandyBrown" . "#F4A460")
  188. ("SeaGreen" . "#2E8B57")
  189. ("SeaShell" . "#FFF5EE")
  190. ("Sienna" . "#A0522D")
  191. ("Silver" . "#C0C0C0")
  192. ("SkyBlue" . "#87CEEB")
  193. ("SlateBlue" . "#6A5ACD")
  194. ("SlateGray" . "#708090")
  195. ("SlateGrey" . "#708090")
  196. ("Snow" . "#FFFAFA")
  197. ("SpringGreen" . "#00FF7F")
  198. ("SteelBlue" . "#4682B4")
  199. ("Tan" . "#D2B48C")
  200. ("Teal" . "#008080")
  201. ("Thistle" . "#D8BFD8")
  202. ("Tomato" . "#FF6347")
  203. ("Turquoise" . "#40E0D0")
  204. ("Violet" . "#EE82EE")
  205. ("Wheat" . "#F5DEB3")
  206. ("White" . "#FFFFFF")
  207. ("WhiteSmoke" . "#F5F5F5")
  208. ("Yellow" . "#FFFF00")
  209. ("YellowGreen" . "#9ACD32"))
  210. "Alist of HTML colors.
  211. Each entry should have the form (COLOR-NAME . HEXADECIMAL-COLOR)."
  212. :group 'rainbow)
  213. (defcustom rainbow-html-colors-major-mode-list
  214. '(html-mode css-mode php-mode nxml-mode xml-mode)
  215. "List of major mode where HTML colors are enabled when
  216. `rainbow-html-colors' is set to auto."
  217. :group 'rainbow)
  218. (defcustom rainbow-html-colors 'auto
  219. "When to enable HTML colors.
  220. If set to t, the HTML colors will be enabled. If set to nil, the
  221. HTML colors will not be enabled. If set to auto, the HTML colors
  222. will be enabled if a major mode has been detected from the
  223. `rainbow-html-colors-major-mode-list'."
  224. :group 'rainbow)
  225. ;; X colors
  226. (defvar rainbow-x-colors-font-lock-keywords
  227. `((,(regexp-opt (x-defined-colors) 'words)
  228. (0 (rainbow-colorize-itself))))
  229. "Font-lock keywords to add for X colors.")
  230. (defcustom rainbow-x-colors-major-mode-list
  231. '(emacs-lisp-mode lisp-interaction-mode c-mode c++-mode java-mode)
  232. "List of major mode where X colors are enabled when
  233. `rainbow-x-colors' is set to auto."
  234. :group 'rainbow)
  235. (defcustom rainbow-x-colors 'auto
  236. "When to enable X colors.
  237. If set to t, the X colors will be enabled. If set to nil, the
  238. X colors will not be enabled. If set to auto, the X colors
  239. will be enabled if a major mode has been detected from the
  240. `rainbow-x-colors-major-mode-list'."
  241. :group 'rainbow)
  242. ;; LaTeX colors
  243. (defvar rainbow-latex-rgb-colors-font-lock-keywords
  244. '(("{rgb}{\\([0-9.]+\\),\\([0-9.]+\\),\\([0-9.]+\\)}"
  245. (0 (rainbow-colorize-rgb-float)))
  246. ("{RGB}{\\([0-9]\\{1,3\\}\\),\\([0-9]\\{1,3\\}\\),\\([0-9]\\{1,3\\}\\)}"
  247. (0 (rainbow-colorize-rgb)))
  248. ("{HTML}{\\([0-9A-Fa-f]\\{6\\}\\)}"
  249. (0 (rainbow-colorize-hexadecimal-without-sharp))))
  250. "Font-lock keywords to add for LaTeX colors.")
  251. (defcustom rainbow-latex-colors-major-mode-list
  252. '(latex-mode)
  253. "List of major mode where LaTeX colors are enabled when
  254. `rainbow-x-colors' is set to auto."
  255. :group 'rainbow)
  256. (defcustom rainbow-latex-colors 'auto
  257. "When to enable LaTeX colors.
  258. If set to t, the LaTeX colors will be enabled. If set to nil, the
  259. LaTeX colors will not be enabled. If set to auto, the LaTeX colors
  260. will be enabled if a major mode has been detected from the
  261. `rainbow-latex-colors-major-mode-list'."
  262. :group 'rainbow)
  263. ;; Shell colors
  264. (defvar rainbow-ansi-colors-font-lock-keywords
  265. '(("\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\|\033\\)\\[\\([0-9;]*m\\)"
  266. (0 (rainbow-colorize-ansi))))
  267. "Font-lock keywords to add for ANSI colors.")
  268. (defcustom rainbow-ansi-colors-major-mode-list
  269. '(sh-mode c-mode c++-mode)
  270. "List of major mode where ANSI colors are enabled when
  271. `rainbow-ansi-colors' is set to auto."
  272. :group 'rainbow)
  273. (defcustom rainbow-ansi-colors 'auto
  274. "When to enable ANSI colors.
  275. If set to t, the ANSI colors will be enabled. If set to nil, the
  276. ANSI colors will not be enabled. If set to auto, the ANSI colors
  277. will be enabled if a major mode has been detected from the
  278. `rainbow-ansi-colors-major-mode-list'."
  279. :group 'rainbow)
  280. ;; Functions
  281. (defun rainbow-colorize-match (color &optional match)
  282. "Return a matched string propertized with a face whose
  283. background is COLOR. The foreground is computed using
  284. `rainbow-color-luminance', and is either white or black."
  285. (let ((match (or match 0)))
  286. (put-text-property
  287. (match-beginning match) (match-end match)
  288. 'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color))
  289. "white" "black"))
  290. (:background ,color)))))
  291. (defun rainbow-colorize-itself (&optional match)
  292. "Colorize a match with itself."
  293. (rainbow-colorize-match (match-string-no-properties (or match 0)) match))
  294. (defun rainbow-colorize-hexadecimal-without-sharp ()
  295. "Colorize an hexadecimal colors and prepend # to it."
  296. (rainbow-colorize-match (concat "#" (match-string-no-properties 1))))
  297. (defun rainbow-colorize-by-assoc (assoc-list)
  298. "Colorize a match with its association from ASSOC-LIST."
  299. (rainbow-colorize-match (cdr (assoc-string (match-string-no-properties 0)
  300. assoc-list t))))
  301. (defun rainbow-rgb-relative-to-absolute (number)
  302. "Convert a relative NUMBER to absolute. If NUMBER is absolute, return NUMBER.
  303. This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"."
  304. (let ((string-length (- (length number) 1)))
  305. ;; Is this a number with %?
  306. (if (eq (elt number string-length) ?%)
  307. (/ (* (string-to-number (substring number 0 string-length)) 255) 100)
  308. (string-to-number number))))
  309. (defun rainbow-colorize-hsl ()
  310. "Colorize a match with itself."
  311. (let ((h (/ (string-to-number (match-string-no-properties 1)) 360.0))
  312. (s (/ (string-to-number (match-string-no-properties 2)) 100.0))
  313. (l (/ (string-to-number (match-string-no-properties 3)) 100.0)))
  314. (rainbow-colorize-match
  315. (multiple-value-bind (r g b)
  316. (color-hsl-to-rgb h s l)
  317. (format "#%02X%02X%02X" (* r 255) (* g 255) (* b 255))))))
  318. (defun rainbow-colorize-rgb ()
  319. "Colorize a match with itself."
  320. (let ((r (rainbow-rgb-relative-to-absolute (match-string-no-properties 1)))
  321. (g (rainbow-rgb-relative-to-absolute (match-string-no-properties 2)))
  322. (b (rainbow-rgb-relative-to-absolute (match-string-no-properties 3))))
  323. (rainbow-colorize-match (format "#%02X%02X%02X" r g b))))
  324. (defun rainbow-colorize-rgb-float ()
  325. "Colorize a match with itself, with relative value."
  326. (let ((r (* (string-to-number (match-string-no-properties 1)) 255.0))
  327. (g (* (string-to-number (match-string-no-properties 2)) 255.0))
  328. (b (* (string-to-number (match-string-no-properties 3)) 255.0)))
  329. (rainbow-colorize-match (format "#%02X%02X%02X" r g b))))
  330. (defun rainbow-colorize-ansi ()
  331. "Return a matched string propertized with ansi color face."
  332. (let ((xterm-color? (featurep 'xterm-color))
  333. (string (match-string-no-properties 0))
  334. color)
  335. (save-match-data
  336. (let* ((replaced (concat
  337. (replace-regexp-in-string
  338. "^\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\)"
  339. "\033" string) "x"))
  340. xterm-color-current
  341. ansi-color-context
  342. (applied (funcall (if xterm-color?
  343. 'xterm-color-filter
  344. 'ansi-color-apply)
  345. replaced))
  346. (face-property (get-text-property
  347. 0
  348. (if xterm-color? 'face 'font-lock-face)
  349. applied)))
  350. (unless (listp (car face-property))
  351. (setq face-property (list face-property)))
  352. (setq color (funcall (if xterm-color? 'cadr 'cdr)
  353. (or (assq (if xterm-color?
  354. :foreground
  355. 'foreground-color)
  356. face-property)
  357. (assq (if xterm-color?
  358. :background
  359. 'background-color)
  360. face-property))))))
  361. (when color
  362. (rainbow-colorize-match color))))
  363. (defun rainbow-color-luminance (red green blue)
  364. "Calculate the luminance of color composed of RED, BLUE and GREEN.
  365. Return a value between 0 and 1."
  366. (/ (+ (* .2126 red) (* .7152 green) (* .0722 blue)) 256))
  367. (defun rainbow-x-color-luminance (color)
  368. "Calculate the luminance of a color string (e.g. \"#ffaa00\", \"blue\").
  369. Return a value between 0 and 1."
  370. (let* ((values (x-color-values color))
  371. (r (/ (car values) 256.0))
  372. (g (/ (cadr values) 256.0))
  373. (b (/ (caddr values) 256.0)))
  374. (rainbow-color-luminance r g b)))
  375. (defun rainbow-turn-on ()
  376. "Turn on raibow-mode."
  377. (font-lock-add-keywords nil
  378. rainbow-hexadecimal-colors-font-lock-keywords)
  379. ;; Activate X colors?
  380. (when (or (eq rainbow-x-colors t)
  381. (and (eq rainbow-x-colors 'auto)
  382. (memq major-mode rainbow-x-colors-major-mode-list)))
  383. (font-lock-add-keywords nil
  384. rainbow-x-colors-font-lock-keywords))
  385. ;; Activate LaTeX colors?
  386. (when (or (eq rainbow-latex-colors t)
  387. (and (eq rainbow-latex-colors 'auto)
  388. (memq major-mode rainbow-latex-colors-major-mode-list)))
  389. (font-lock-add-keywords nil
  390. rainbow-latex-rgb-colors-font-lock-keywords))
  391. ;; Activate ANSI colors?
  392. (when (or (eq rainbow-ansi-colors t)
  393. (and (eq rainbow-ansi-colors 'auto)
  394. (memq major-mode rainbow-ansi-colors-major-mode-list)))
  395. (font-lock-add-keywords nil
  396. rainbow-ansi-colors-font-lock-keywords))
  397. ;; Activate HTML colors?
  398. (when (or (eq rainbow-html-colors t)
  399. (and (eq rainbow-html-colors 'auto)
  400. (memq major-mode rainbow-html-colors-major-mode-list)))
  401. (setq rainbow-html-colors-font-lock-keywords
  402. `((,(regexp-opt (mapcar 'car rainbow-html-colors-alist) 'words)
  403. (0 (rainbow-colorize-by-assoc rainbow-html-colors-alist)))))
  404. (font-lock-add-keywords nil
  405. `(,@rainbow-html-colors-font-lock-keywords
  406. ,@rainbow-html-rgb-colors-font-lock-keywords))))
  407. (defun rainbow-turn-off ()
  408. "Turn off rainbow-mode."
  409. (font-lock-remove-keywords
  410. nil
  411. `(,@rainbow-hexadecimal-colors-font-lock-keywords
  412. ,@rainbow-x-colors-font-lock-keywords
  413. ,@rainbow-latex-rgb-colors-font-lock-keywords
  414. ,@rainbow-html-colors-font-lock-keywords
  415. ,@rainbow-html-rgb-colors-font-lock-keywords)))
  416. ;;;###autoload
  417. (define-minor-mode rainbow-mode
  418. "Colorize strings that represent colors.
  419. This will fontify with colors the string like \"#aabbcc\" or \"blue\"."
  420. :lighter " Rbow"
  421. (progn
  422. (if rainbow-mode
  423. (rainbow-turn-on)
  424. (rainbow-turn-off))
  425. ;; Turn on font lock
  426. (font-lock-mode 1)))
  427. (provide 'rainbow-mode)
  428. ;;; rainbow-mode.el ends here