From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Newsgroups: gmane.emacs.devel Subject: Re: info faces for strings and quotations Date: Tue, 05 Oct 2004 07:56:40 -0400 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1096980586 7186 80.91.229.6 (5 Oct 2004 12:49:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 5 Oct 2004 12:49:46 +0000 (UTC) Cc: Lennart Borgman , Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 05 14:49:37 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CEol6-0007W6-00 for ; Tue, 05 Oct 2004 14:49:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CEork-00086L-5q for ged-emacs-devel@m.gmane.org; Tue, 05 Oct 2004 08:56:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CEor4-0007QE-Lo for emacs-devel@gnu.org; Tue, 05 Oct 2004 08:55:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CEor3-0007Pp-Pz for emacs-devel@gnu.org; Tue, 05 Oct 2004 08:55:45 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CEor3-0007PE-K4 for emacs-devel@gnu.org; Tue, 05 Oct 2004 08:55:45 -0400 Original-Received: from [206.47.199.166] (helo=simmts8-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CEok5-0004Dm-56 for emacs-devel@gnu.org; Tue, 05 Oct 2004 08:48:33 -0400 Original-Received: from empanada.home ([67.68.216.150]) by simmts8-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20041005124631.JAML1692.simmts8-srv.bellnexxia.net@empanada.home>; Tue, 5 Oct 2004 08:46:31 -0400 Original-Received: by empanada.home (Postfix, from userid 502) id 990FA311B06; Tue, 5 Oct 2004 07:56:40 -0400 (EDT) Original-To: "Drew Adams" In-Reply-To: (Drew Adams's message of "Tue, 5 Oct 2004 00:15:42 -0700") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (darwin) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:27935 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:27935 > (defun info-fontify-quotations () > "Fontify double-quote strings (\"...\") and text between single-quotes > (`...') > For single-quotes, use `info-quoted-name-face'. > For double-quotes, use `info-string-face'." > (goto-char (point-min)) > (let (;; double-quote strings: "...", "...\", "...\\", etc.; m1=\* > ;; or single-quote strings: `...' > (either-re "\"[^\"]*\\([\\\\]*\\)\"\\|`[^'\n]+'") > ;; ", \", \\", \\\" etc.; m2=\* > (dblquote-re "\\([\\\\]*\\)\"") > m0 p0b p0e ; Whole match: `...' or "..." > m1 p1b p1e ; \* subexp of "...\*" match > m2 p2b p2e ; \* subexp of "...\*" match > escaped-dblquote-p) > (while (re-search-forward either-re nil t) > (setq m0 (match-string 0) ; Whole match string > p0b (nth 0 (match-data)) ; Beginning of m0 Never do (nth x (match-data)). Always use (match-beginning N) or (match-end N) instead. Much more readable (and efficient). > p0e (nth 1 (match-data)) ; End of m0 > m1 (match-string 1) ; \* subexp of "...\*" match The code never seems to use `m1' so you can spare this string-allocation. > p1b (nth 2 (match-data)) ; Beginning of m1 > p1e (nth 3 (match-data))) ; End of m2 > (when (equal (char-after p0b) ?\") ; double-quote string: "..." > (when (> p1e p1b) ; May be escaped: \ inside "...\*" > (when (= (mod (- p1e p1b) 2) 1) ; Escaped (odd number of > backslashes: \", \\\",...) > (setq escaped-dblquote-p t) > (while escaped-dblquote-p > (if (not (re-search-forward dblquote-re nil t)) ; Look for \*" > (setq escaped-dblquote-p nil) ; No \*" > (setq m2 (match-string 0) ; \*" Similary `m2' is never used. > p2b (nth 0 (match-data)) ; Beginning of \*": \ or " > p2e (nth 1 (match-data)) ; End of \*": " > p0e p2e) ; Update pointer > (if (= p2e p2b) > (setq escaped-dblquote-p nil) ; Not escaped - ", \\", > \\\\", etc. > (when (= (mod (- p2e p2b) 2) 1) (setq escaped-dblquote-p > nil)))))))) Why not use (either-re "\"\\([^\\\"]\\|\\\\[\\\"]\\)*\"\\|`[^'\n]+'") and get rid of all this code (i.e. the regexp-matching does the escape-counting for you)? > (if (eq ?` (aref m0 0)) Use (eq ?` (char-after p0b)) and you can get rid of `m0'. > (put-text-property (1+ p0b) (1- p0e) 'face 'info-quoted-name-face) > (put-text-property p0b p0e 'face 'info-string-face))))) Why fontify the interior of `...' but fontify both the interior and the quotes for "..." ? I.e. why not use (put-text-property p0b p0e 'face (if (eq ?` (char-after p0b)) 'info-quoted-name-face 'info-string-face)) or (put-text-property (1+ p0b) (1- p0e) 'face (if (eq ?` (char-after p0b)) 'info-quoted-name-face 'info-string-face)) Is it just because your quoted face is bold and you don't like to see the ` and ' in bold, or is there a deeper reason? Stefan