Subject: bug#2773: feature request: option for css mode to
highlight #rrggbb text



this is a feature request, for a option for css mode to highlight #rrggbb text.

Explanation:

in CSS, there are lots of RGB values, e.g.

pre.c {border-color:#454545}
pre.java {border-color:#a020f0}
pre.haskell {border-color:#00b2ee}
pre.ocaml {border-color:#6b8e23}

it is very convenient if the rgb code can be colored by its value, so that users can visually see what color they represent.

the css-mode that comes with emacs 22 doesn't seems to support this feature. (doesn't seem to have customize-group support)

Here's a implementation that i've been using for a few months.

;; by Nikolaj Schumacher. http://www.emacswiki.org/emacs/HexColour
(defvar hexcolor-keywords
'(("#[abcdef[:digit:]]\\{6\\}"
(0 (put-text-property
(match-beginning 0)
(match-end 0)
'face (list :background
(match-string-no-properties 0)))))))

(defun hexcolor-add-to-font-lock ()
(interactive)
(font-lock-add-keywords nil hexcolor-keywords))
(add-hook 'css-mode-hook 'hexcolor-add-to-font-lock)

Note: CSS spec also allows this short form #RGB, where each of the rgb is a single char. e.g. #f3c is the same as #ff33cc. The above code need a bit tweak for this case.

In GNU Emacs 22.2.1 (powerpc-apple-darwin8.11.0, Carbon Version 1.6.0)
of 2008-04-05 on g5.tokyo.stp.isas.jaxa.jp


Thanks.

Xah
â http://xahlee.org/

â




...



Privacy