From EmacsWiki: Hex Colour, it is explained how to get in-line syntax highlighting of hex code, and other formats of color. For instance with

(defvar hexcolour-keywords
      (0 (put-text-property (match-beginning 0)
                            (match-end 0)
                            'face (list :background 
                                        (match-string-no-properties 0)))))))

But when I try this with some emacs-lisp such as

(set-face-attribute 'org-todo nil
                    :weight 'bold :box '(:line-width 1 :color "#D8ABA7")
                    :foreground "#D8ABA7" :background "#FFE6E4")

the hex is not given the color face. If I try M-x describe-face on these, I find face is org-block-background. Is there a good way to override this?


You can also achieve this using rainbow-mode, which is part of ELPA. Install it with M-x package-install rainbow-mode and activate it with M-x rainbow-mode. It seems that the color changes don't occur until you edit the buffer.

| improve this answer | |
  • "There is a good chance that someone already solved the problem, and made a package out of it". And an extra plus, package automagically inverts foreground to black or white for readability. – Brady Trainor Nov 2 '14 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.