Skip to content

Find nearest colors in Emacs 24

by mickey on December 15th, 2011

As I mentioned in my What’s New In Emacs 24 series (part one, part two) Emacs 24 can now sort the colors in M-x list-colors-display based on the RGB or HSV distance to another color. This is perhaps of most interest to web designers or color theme creators, but it’s still a fun little addition.

Unfortunately, this functionality is only available through the customize interface, and that means most people will never bother with it at all. Hence, I’ve written two helper commands below to make this neat addition to Emacs 24 easier to use.

If you’re looking up a named color (like red) then it must exist in M-x list-colors-display; if it’s an HTML color then as long as it is valid it will work.

To use it, you must invoke M-x find-nearest-color and enter the name of a color. The other command, find-nearest-color-at-point does just that: it looks at what your point is on and tries to look it up.

If you hack a lot of elisp you will notice that I’ve chosen to hack the syntax table (temporarily) to make thing-at-point play nice with the HTML color syntax (#ABCDEF) as the character — and this will depend on your mode and thus your syntax table, of course — # is rarely a “word” constituent. I think this is a much cleaner way of “getting” things at point than messing with regular expressions as you will inevitably end up reinventing most of thing-at-point doing so.

Share your thoughts

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS