all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Xah Lee'" <xahlee@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: how to attach properties to a piece of text?
Date: Thu, 19 Mar 2009 08:51:24 -0700	[thread overview]
Message-ID: <011d01c9a8aa$93a60ed0$c2b22382@us.oracle.com> (raw)
In-Reply-To: <3189ffdc-6fb6-4723-89a8-d87a78407aad@q30g2000prq.googlegroups.com>

> (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	other threads:[~2009-03-19 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19  0:20 how to attach properties to a piece of text? Xah Lee
2009-03-19  0:54 ` Miles Bader
2009-03-19  3:19   ` Xah Lee
2009-03-19 15:51     ` Drew Adams [this message]
2009-03-19 13:11   ` Xah Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='011d01c9a8aa$93a60ed0$c2b22382@us.oracle.com' \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=xahlee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.