From 4f34ba1501849a3df19bcfab58715a8e1d9db336 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 23 Sep 2011 19:00:24 +0200 Subject: [PATCH] Update rainbow-mode to version 0.2 --- ChangeLog | 2 + packages/rainbow-mode/rainbow-mode.el | 232 ++++++++++++++++++++++---- 2 files changed, 205 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89e1e6ec8..59a173945 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2011-09-23 Julien Danjou + * packages/rainbow-mode/rainbow-mode.el: Update to version 0.2. + * packages/oauth2/oauth2.el: New package. 2011-08-28 PJ Weisberg diff --git a/packages/rainbow-mode/rainbow-mode.el b/packages/rainbow-mode/rainbow-mode.el index 7d71002cc..d3b759ce6 100644 --- a/packages/rainbow-mode/rainbow-mode.el +++ b/packages/rainbow-mode/rainbow-mode.el @@ -1,10 +1,10 @@ ;;; rainbow-mode.el --- Colorize color names in buffers -;; Copyright (C) 2010 Free Software Foundation, Inc +;; Copyright (C) 2010-2011 Free Software Foundation, Inc ;; Author: Julien Danjou ;; Keywords: faces -;; Version: 0.1 +;; Version: 0.2 ;; This file is part of GNU Emacs. @@ -42,7 +42,13 @@ ;; Hexadecimal colors (defvar rainbow-hexadecimal-colors-font-lock-keywords - '(("#[0-9a-fA-F]\\{3\\}[0-9a-fA-F]\\{3\\}?" + '(("#\\(?:[0-9a-fA-F]\\{3\\}\\)+\\{1,4\\}" + (0 (rainbow-colorize-itself))) + ("[Rr][Gg][Bb]:[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}/[0-9a-fA-F]\\{1,4\\}" + (0 (rainbow-colorize-itself))) + ("[Rr][Gg][Bb][Ii]:[0-9.]+/[0-9.]+/[0-9.]+" + (0 (rainbow-colorize-itself))) + ("\\(?:[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]+\\)?" (0 (rainbow-colorize-itself)))) "Font-lock keywords to add for hexadecimal colors.") @@ -50,8 +56,12 @@ (defvar rainbow-html-rgb-colors-font-lock-keywords '(("rgb(\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*,\s*\\([0-9]\\{1,3\\}\\(?:\s*%\\)?\\)\s*)" (0 (rainbow-colorize-rgb))) - ("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]\\{1,3\\}\s*%?\s*)" - (0 (rainbow-colorize-rgb)))) + ("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*)" + (0 (rainbow-colorize-rgb))) + ("hsl(\s*\\([0-9]\\{1,3\\}\\)\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*,\s*\\([0-9]\\{1,3\\}\\)\s*%\s*)" + (0 (rainbow-colorize-hsl))) + ("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*)" + (0 (rainbow-colorize-hsl)))) "Font-lock keywords to add for RGB colors.") ;; HTML colors name @@ -60,22 +70,153 @@ (make-variable-buffer-local 'rainbow-html-colors-font-lock-keywords) (defcustom rainbow-html-colors-alist - '(("black" . "#000000") - ("silver" . "#C0C0C0") - ("gray" . "#808080") - ("white" . "#FFFFFF") - ("maroon" . "#800000") - ("red" . "#FF0000") - ("purple" . "#800080") - ("fuchsia" . "#FF00FF") - ("green" . "#008000") - ("lime" . "#00FF00") - ("olive" . "#808000") - ("yellow" . "#FFFF00") - ("navy" . "#000080") - ("blue" . "#0000FF") - ("teal" . "#008080") - ("aqua" . "#00FFFF")) + '(("AliceBlue" . "#F0F8FF") + ("AntiqueWhite" . "#FAEBD7") + ("Aqua" . "#00FFFF") + ("Aquamarine" . "#7FFFD4") + ("Azure" . "#F0FFFF") + ("Beige" . "#F5F5DC") + ("Bisque" . "#FFE4C4") + ("Black" . "#000000") + ("BlanchedAlmond" . "#FFEBCD") + ("Blue" . "#0000FF") + ("BlueViolet" . "#8A2BE2") + ("Brown" . "#A52A2A") + ("BurlyWood" . "#DEB887") + ("CadetBlue" . "#5F9EA0") + ("Chartreuse" . "#7FFF00") + ("Chocolate" . "#D2691E") + ("Coral" . "#FF7F50") + ("CornflowerBlue" . "#6495ED") + ("Cornsilk" . "#FFF8DC") + ("Crimson" . "#DC143C") + ("Cyan" . "#00FFFF") + ("DarkBlue" . "#00008B") + ("DarkCyan" . "#008B8B") + ("DarkGoldenRod" . "#B8860B") + ("DarkGray" . "#A9A9A9") + ("DarkGrey" . "#A9A9A9") + ("DarkGreen" . "#006400") + ("DarkKhaki" . "#BDB76B") + ("DarkMagenta" . "#8B008B") + ("DarkOliveGreen" . "#556B2F") + ("Darkorange" . "#FF8C00") + ("DarkOrchid" . "#9932CC") + ("DarkRed" . "#8B0000") + ("DarkSalmon" . "#E9967A") + ("DarkSeaGreen" . "#8FBC8F") + ("DarkSlateBlue" . "#483D8B") + ("DarkSlateGray" . "#2F4F4F") + ("DarkSlateGrey" . "#2F4F4F") + ("DarkTurquoise" . "#00CED1") + ("DarkViolet" . "#9400D3") + ("DeepPink" . "#FF1493") + ("DeepSkyBlue" . "#00BFFF") + ("DimGray" . "#696969") + ("DimGrey" . "#696969") + ("DodgerBlue" . "#1E90FF") + ("FireBrick" . "#B22222") + ("FloralWhite" . "#FFFAF0") + ("ForestGreen" . "#228B22") + ("Fuchsia" . "#FF00FF") + ("Gainsboro" . "#DCDCDC") + ("GhostWhite" . "#F8F8FF") + ("Gold" . "#FFD700") + ("GoldenRod" . "#DAA520") + ("Gray" . "#808080") + ("Grey" . "#808080") + ("Green" . "#008000") + ("GreenYellow" . "#ADFF2F") + ("HoneyDew" . "#F0FFF0") + ("HotPink" . "#FF69B4") + ("IndianRed" . "#CD5C5C") + ("Indigo" . "#4B0082") + ("Ivory" . "#FFFFF0") + ("Khaki" . "#F0E68C") + ("Lavender" . "#E6E6FA") + ("LavenderBlush" . "#FFF0F5") + ("LawnGreen" . "#7CFC00") + ("LemonChiffon" . "#FFFACD") + ("LightBlue" . "#ADD8E6") + ("LightCoral" . "#F08080") + ("LightCyan" . "#E0FFFF") + ("LightGoldenRodYellow" . "#FAFAD2") + ("LightGray" . "#D3D3D3") + ("LightGrey" . "#D3D3D3") + ("LightGreen" . "#90EE90") + ("LightPink" . "#FFB6C1") + ("LightSalmon" . "#FFA07A") + ("LightSeaGreen" . "#20B2AA") + ("LightSkyBlue" . "#87CEFA") + ("LightSlateGray" . "#778899") + ("LightSlateGrey" . "#778899") + ("LightSteelBlue" . "#B0C4DE") + ("LightYellow" . "#FFFFE0") + ("Lime" . "#00FF00") + ("LimeGreen" . "#32CD32") + ("Linen" . "#FAF0E6") + ("Magenta" . "#FF00FF") + ("Maroon" . "#800000") + ("MediumAquaMarine" . "#66CDAA") + ("MediumBlue" . "#0000CD") + ("MediumOrchid" . "#BA55D3") + ("MediumPurple" . "#9370D8") + ("MediumSeaGreen" . "#3CB371") + ("MediumSlateBlue" . "#7B68EE") + ("MediumSpringGreen" . "#00FA9A") + ("MediumTurquoise" . "#48D1CC") + ("MediumVioletRed" . "#C71585") + ("MidnightBlue" . "#191970") + ("MintCream" . "#F5FFFA") + ("MistyRose" . "#FFE4E1") + ("Moccasin" . "#FFE4B5") + ("NavajoWhite" . "#FFDEAD") + ("Navy" . "#000080") + ("OldLace" . "#FDF5E6") + ("Olive" . "#808000") + ("OliveDrab" . "#6B8E23") + ("Orange" . "#FFA500") + ("OrangeRed" . "#FF4500") + ("Orchid" . "#DA70D6") + ("PaleGoldenRod" . "#EEE8AA") + ("PaleGreen" . "#98FB98") + ("PaleTurquoise" . "#AFEEEE") + ("PaleVioletRed" . "#D87093") + ("PapayaWhip" . "#FFEFD5") + ("PeachPuff" . "#FFDAB9") + ("Peru" . "#CD853F") + ("Pink" . "#FFC0CB") + ("Plum" . "#DDA0DD") + ("PowderBlue" . "#B0E0E6") + ("Purple" . "#800080") + ("Red" . "#FF0000") + ("RosyBrown" . "#BC8F8F") + ("RoyalBlue" . "#4169E1") + ("SaddleBrown" . "#8B4513") + ("Salmon" . "#FA8072") + ("SandyBrown" . "#F4A460") + ("SeaGreen" . "#2E8B57") + ("SeaShell" . "#FFF5EE") + ("Sienna" . "#A0522D") + ("Silver" . "#C0C0C0") + ("SkyBlue" . "#87CEEB") + ("SlateBlue" . "#6A5ACD") + ("SlateGray" . "#708090") + ("SlateGrey" . "#708090") + ("Snow" . "#FFFAFA") + ("SpringGreen" . "#00FF7F") + ("SteelBlue" . "#4682B4") + ("Tan" . "#D2B48C") + ("Teal" . "#008080") + ("Thistle" . "#D8BFD8") + ("Tomato" . "#FF6347") + ("Turquoise" . "#40E0D0") + ("Violet" . "#EE82EE") + ("Wheat" . "#F5DEB3") + ("White" . "#FFFFFF") + ("WhiteSmoke" . "#F5F5F5") + ("Yellow" . "#FFFF00") + ("YellowGreen" . "#9ACD32")) "Alist of HTML colors. Each entry should have the form (COLOR-NAME . HEXADECIMAL-COLOR)." :group 'rainbow) @@ -145,7 +286,7 @@ background is COLOR. The foreground is computed using `rainbow-color-luminance', and is either white or black." (put-text-property (match-beginning 0) (match-end 0) - 'face `((:foreground ,(if (> 128.0 (rainbow-x-color-luminance color)) + 'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color)) "white" "black")) (:background ,color)))) @@ -159,7 +300,8 @@ background is COLOR. The foreground is computed using (defun rainbow-colorize-by-assoc (assoc-list) "Colorize a match with its association from ASSOC-LIST." - (rainbow-colorize-match (cdr (assoc (match-string-no-properties 0) assoc-list)))) + (rainbow-colorize-match (cdr (assoc-string (match-string-no-properties 0) + assoc-list t)))) (defun rainbow-rgb-relative-to-absolute (number) "Convert a relative NUMBER to absolute. If NUMBER is absolute, return NUMBER. @@ -170,6 +312,36 @@ This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"." (/ (* (string-to-number (substring number 0 string-length)) 255) 100) (string-to-number number)))) +(defun rainbow-hue-to-rgb (x y h) + "Convert X Y H to RGB value." + (when (< h 0) (incf h)) + (when (> h 1) (decf h)) + (cond ((< h (/ 1 6.0)) (+ x (* (- y x) h 6))) + ((< h 0.5) y) + ((< h (/ 2.0 3.0)) (+ x (* (- y x) (- (/ 2.0 3.0) h) 6))) + (t x))) + +(defun rainbow-hsl-to-rgb-fractions (h s l) + "Convert H S L to fractional RGB values." + (let (m1 m2) + (if (<= l 0.5) + (setq m2 (* l (+ s 1))) + (setq m2 (- (+ l s) (* l s)))) + (setq m1 (- (* l 2) m2)) + (list (rainbow-hue-to-rgb m1 m2 (+ h (/ 1 3.0))) + (rainbow-hue-to-rgb m1 m2 h) + (rainbow-hue-to-rgb m1 m2 (- h (/ 1 3.0)))))) + +(defun rainbow-colorize-hsl () + "Colorize a match with itself." + (let ((h (/ (string-to-number (match-string-no-properties 1)) 360.0)) + (s (/ (string-to-number (match-string-no-properties 2)) 100.0)) + (l (/ (string-to-number (match-string-no-properties 3)) 100.0))) + (rainbow-colorize-match + (multiple-value-bind (r g b) + (rainbow-hsl-to-rgb-fractions h s l) + (format "#%02X%02X%02X" (* r 255) (* g 255) (* b 255)))))) + (defun rainbow-colorize-rgb () "Colorize a match with itself." (let ((r (rainbow-rgb-relative-to-absolute (match-string-no-properties 1))) @@ -185,15 +357,17 @@ This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"." (rainbow-colorize-match (format "#%02X%02X%02X" r g b)))) (defun rainbow-color-luminance (red green blue) - "Calculate the luminance of color composed of RED, BLUE and GREEN." - (floor (+ (* .2126 red) (* .7152 green) (* .0722 blue)) 256)) + "Calculate the luminance of color composed of RED, BLUE and GREEN. +Return a value between 0 and 1." + (/ (+ (* .2126 red) (* .7152 green) (* .0722 blue)) 256)) (defun rainbow-x-color-luminance (color) - "Calculate the luminance of a color string (e.g. \"#ffaa00\", \"blue\")." + "Calculate the luminance of a color string (e.g. \"#ffaa00\", \"blue\"). +Return a value between 0 and 1." (let* ((values (x-color-values color)) - (r (car values)) - (g (cadr values)) - (b (caddr values))) + (r (/ (car values) 256.0)) + (g (/ (cadr values) 256.0)) + (b (/ (caddr values) 256.0))) (rainbow-color-luminance r g b))) (defun rainbow-turn-on () -- 2.39.2