help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to attach properties to a piece of text?


From: Drew Adams
Subject: RE: how to attach properties to a piece of text?
Date: Thu, 19 Mar 2009 08:51:24 -0700

> (defun convert-rgb-vector-to-hex (rgb)
>   "Convert color RGB from "[r g b]" notation to "\"rrggbb\"" notation.
> Example: (convert-rgb-vector-to-hex [0 1 0.5]) returns \"00ff80\""
>   (mapconcat (lambda (x) (format "%02x" (round (* x 255.0)) )) rgb ""))
> 
> (defun syntax-color-vector (start end)
>   "Make vectors <r,g,b> syntax colored "
>   (interactive "r")
>   (save-restriction
>     (narrow-to-region start end)
>     (goto-char (point-min))
>     (while (search-forward-regexp
>             "< *\\([0-9.]+\\) *, *\\([0-9.]+\\) *, *\\([0-9.]+\\) *>"
>             nil t)
>       (put-text-property (match-beginning 0)
>                          (match-end 0) 'face (list :background
> (concat "#" (convert-rgb-vector-to-hex
>              (vector (string-to-number (match-string 1))
>                      (string-to-number (match-string 2))
>                      (string-to-number (match-string 3))))))))))
> 
> spent some 4 hours on this. Some 80% time is spend on the hex/decimal
> conversion, digging into some details of emacs float, string, hex,
> round, etc issues. (^_^)


http://www.emacswiki.org/emacs/hexrgb.el (e.g. `hexrgb-rgb-to-hex')

But it's always rewarding to code something oneself - never a waste of time.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]