<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -28,4 +28,48 @@
      (dolist (mode (list 'html-mode 'nxml-mode))
        (mmm-add-mode-ext-class mode &quot;\\.r?html\\(\\.erb\\)?$&quot; 'html-css))))
 
+
+
+;; Colourise CSS colour literals
+;; Inspired by http://xahlee.org/emacs/emacs_html.html, but much extended
+
+(require 'hexl)
+(defun choose-contrasting-colour (hex-colour)
+  (if (&gt; (hexl-hex-string-to-integer (substring hex-colour 1))
+         (hexl-hex-string-to-integer &quot;777777&quot;))
+      &quot;#000000&quot;
+    &quot;#ffffff&quot;))
+
+(defun three-hex-colour-to-six (three)
+  (let ((six &quot;#&quot;))
+    (progn
+      (dolist (c (string-to-list (substring three 1)))
+        (setq six (concat six (string c c))))
+      six)))
+
+(defun hexcolour-font-lock-face (hexcolour)
+  (list :background hexcolour :foreground (choose-contrasting-colour hexcolour)))
+
+(setq hexcolour-keywords
+  '((&quot;#[abcdef[:digit:]]\\{3\\}&quot;
+     (0 (put-text-property
+         (match-beginning 0)
+         (match-end 0)
+         'face (hexcolour-font-lock-face
+                (three-hex-colour-to-six (match-string-no-properties 0))))))
+    (&quot;#[abcdef[:digit:]]\\{6\\}&quot;
+     (0 (put-text-property
+         (match-beginning 0)
+         (match-end 0)
+         'face (hexcolour-font-lock-face
+                (match-string-no-properties 0)))))))
+
+(defun hexcolour-add-to-font-lock ()
+  (font-lock-add-keywords nil hexcolour-keywords))
+
+(add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)
+(add-hook 'html-mode-hook 'hexcolour-add-to-font-lock)
+(add-hook 'sass-mode-hook 'hexcolour-add-to-font-lock)
+
+
 (provide 'init-css)</diff>
      <filename>init-css.el</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d861ffb96a9f35417712c00efe2ae5ff63c67db8</id>
    </parent>
  </parents>
  <author>
    <name>Steve Purcell</name>
    <email>steve@sanityinc.com</email>
  </author>
  <url>http://github.com/purcell/emacs.d/commit/9cac1af731c890ac034b2d871052fd6e5ba27842</url>
  <id>9cac1af731c890ac034b2d871052fd6e5ba27842</id>
  <committed-date>2009-10-12T14:05:45-07:00</committed-date>
  <authored-date>2009-10-12T14:05:45-07:00</authored-date>
  <message>Colourise CSS colour literals so that, e.g., #0f0 appears in green</message>
  <tree>405799dc4b31259f3a782abd72d648b2ad623919</tree>
  <committer>
    <name>Steve Purcell</name>
    <email>steve@sanityinc.com</email>
  </committer>
</commit>
