From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: how to attach properties to a piece of text? Date: Thu, 19 Mar 2009 08:51:24 -0700 Message-ID: <011d01c9a8aa$93a60ed0$c2b22382@us.oracle.com> References: <3f3f751a-a93a-4de6-a306-bf5f47bc9fea@v5g2000prm.googlegroups.com><877i2mgwmr.fsf@catnip.gol.com> <3189ffdc-6fb6-4723-89a8-d87a78407aad@q30g2000prq.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1237480314 19059 80.91.229.12 (19 Mar 2009 16:31:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Mar 2009 16:31:54 +0000 (UTC) To: "'Xah Lee'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 19 17:33:11 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LkLAi-0003bO-FZ for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2009 17:32:44 +0100 Original-Received: from localhost ([127.0.0.1]:53245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkL9L-00075c-RA for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2009 12:31:19 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LkKX7-0007UR-2m for help-gnu-emacs@gnu.org; Thu, 19 Mar 2009 11:51:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LkKX2-0007SY-Cb for help-gnu-emacs@gnu.org; Thu, 19 Mar 2009 11:51:48 -0400 Original-Received: from [199.232.76.173] (port=59478 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkKX2-0007SO-5z for help-gnu-emacs@gnu.org; Thu, 19 Mar 2009 11:51:44 -0400 Original-Received: from rcsinet11.oracle.com ([148.87.113.123]:28244 helo=rgminet11.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LkKX1-0003f1-Ox for help-gnu-emacs@gnu.org; Thu, 19 Mar 2009 11:51:43 -0400 Original-Received: from rgminet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rgminet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n2JFsXXu010987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 Mar 2009 15:54:34 GMT Original-Received: from acsmt701.oracle.com (acsmt701.oracle.com [141.146.40.71]) by rgminet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n2JFpbMt012413; Thu, 19 Mar 2009 15:51:39 GMT Original-Received: from dradamslap1 (/130.35.178.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Mar 2009 15:51:30 +0000 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <3189ffdc-6fb6-4723-89a8-d87a78407aad@q30g2000prq.googlegroups.com> Thread-Index: AcmoVbWlWYKsZUCVQ06T38P2ih4G2QAU0QxA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 X-Source-IP: acsmt701.oracle.com [141.146.40.71] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A010209.49C26A06.011F:SCFSTAT928724,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:63099 Archived-At: > (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 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.