all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan <monnier@iro.umontreal.ca>
Cc: Lennart Borgman <lennart.borgman.073@student.lu.se>,
	Emacs-Devel <emacs-devel@gnu.org>
Subject: Re: info faces for strings and quotations
Date: Tue, 05 Oct 2004 07:56:40 -0400	[thread overview]
Message-ID: <m1sm8t5r1g.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <FDELKNEBLPKKDCEBEJCBMEAPCIAA.drew.adams@oracle.com> (Drew Adams's message of "Tue, 5 Oct 2004 00:15:42 -0700")

> (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

  parent reply	other threads:[~2004-10-05 11:56 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-03  7:05 info faces for strings and quotations Drew Adams
2004-10-05  7:15 ` Drew Adams
2004-10-05  7:30   ` Miles Bader
2004-10-06  8:34     ` Matt Hodges
2004-10-05  8:58   ` Drew Adams
2004-10-05 11:43     ` Stefan
2004-10-05 11:56   ` Stefan [this message]
2004-10-05 16:11     ` Drew Adams
2004-10-06  2:25       ` Luc Teirlinck
2004-10-06  4:19         ` Drew Adams
2004-10-06  4:28           ` Miles Bader
2004-10-06  7:40             ` Drew Adams
2004-10-06 21:32               ` Drew Adams
2004-10-06  4:53           ` Stefan Monnier
2004-10-06  7:07             ` Drew Adams
2004-10-06 17:07               ` Robert J. Chassell
2004-10-06 21:36                 ` Drew Adams
2004-10-07  5:53                 ` Juri Linkov
2004-10-07  6:53                   ` Drew Adams
2004-10-07 14:58                     ` Stefan Monnier
2004-10-07 15:13                       ` David Kastrup
2004-10-07 17:01                         ` Stefan Monnier
2004-10-08  5:13                           ` Drew Adams
2004-10-07 15:13                       ` Kim F. Storm
2004-10-07 16:35                         ` David Kastrup
2004-10-08  0:33                   ` Luc Teirlinck
2004-10-08 16:04                   ` Richard Stallman
2004-10-08 16:51                     ` Luc Teirlinck
2004-10-09 15:45                       ` Richard Stallman
2004-10-08 20:00                     ` Robert J. Chassell
2004-10-07  5:57               ` Juri Linkov
2004-10-07 15:22               ` w3 mode Camm Maguire
2004-10-07 17:03                 ` Stefan Monnier
2004-10-07 17:25                   ` Camm Maguire
2004-10-07 17:37                     ` Mark Plaksin
2004-10-07 17:45                     ` Kevin Rodgers
2004-10-08 16:05                 ` Richard Stallman
2004-10-08 17:44                   ` David Kastrup
2004-10-07 15:28               ` unexec development Camm Maguire
2004-10-15 14:10                 ` Camm Maguire
2004-10-15 14:35                   ` Jan D.
2004-10-15 21:11                     ` Camm Maguire
2004-10-16 13:52                   ` Richard Stallman
2004-10-06  8:44         ` info faces for strings and quotations Oliver Scholz
2004-10-07  5:55       ` Juri Linkov
2004-10-07  7:13         ` Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2004-10-05 16:15 LENNART BORGMAN
2004-10-05 16:28 ` Drew Adams

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=m1sm8t5r1g.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman.073@student.lu.se \
    /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.