From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: how to attach properties to a piece of text? Date: Wed, 18 Mar 2009 20:19:06 -0700 (PDT) Organization: http://groups.google.com Message-ID: <3189ffdc-6fb6-4723-89a8-d87a78407aad@q30g2000prq.googlegroups.com> References: <3f3f751a-a93a-4de6-a306-bf5f47bc9fea@v5g2000prm.googlegroups.com> <877i2mgwmr.fsf@catnip.gol.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1237441476 23604 80.91.229.12 (19 Mar 2009 05:44:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Mar 2009 05:44:36 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 19 06:45:51 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 1LkB4d-0001BE-LQ for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2009 06:45:48 +0100 Original-Received: from localhost ([127.0.0.1]:48918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkB3G-0006oQ-Q8 for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Mar 2009 01:44:23 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!q30g2000prq.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 67 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1237432746 10225 127.0.0.1 (19 Mar 2009 03:19:06 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 19 Mar 2009 03:19:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q30g2000prq.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167776 X-Mailman-Approved-At: Thu, 19 Mar 2009 01:32:15 -0400 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:63073 Archived-At: On Mar 18, 5:54 pm, Miles Bader wrote: > Xah Lee writes: > > i haven't studied emacs's face, display property etc systems. But > > could anyone give me a rough guide on what function i should use or > > lookup? > > `put-text-property' > > In particular, you may want the :foreground attribute of the `face' > property. > > E.g. try evaluating the following: > > (put-text-property (point) (mark) 'face '(:foreground "green")) > > However, note that if the buffer's mode uses font-lock, font-lock will > _override_ any `face' property you set (to be its own); in a font-lock'd > buffer, you can use the `font-lock-face' property instead: > > (put-text-property (point) (mark) 'font-lock-face '(:foreground "green= ")) Thanks Miles. Here's the code i did. (defun convert-rgb-vector-to-hex (rgb) "Convert color RGB from =E2=80=9C[r g b]=E2=80=9D notation to =E2=80=9C\"= rrggbb\"=E2=80=9D 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. (^_^) Xah =E2=88=91 http://xahlee.org/ =E2=98=84