emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: info faces for strings and quotations


From: Drew Adams
Subject: RE: info faces for strings and quotations
Date: Thu, 7 Oct 2004 22:13:06 -0700

This version works well. The fontify function is in line below; the full
patch is attached. This seems to do everything the previous version did,
plus treat initial \" correctly. Things like this from (ccmode)Indentation
Functions are not highlighted now, which is the correct behavior: (\"Hello
world!\");

Thanks to everyone who contributed suggestions. I went with David's
suggestion for treating initial \".

Per Luc's suggestion, I added a note to the doc string of
`Info-fontify-quotations-flag' explaining that fontification can never be
100% reliable, that occasional inappropriate highlighting is not a bug, and
that highlighting can be turned off. It is now off by default.

I won't be working any more on this. I think it is ready for prime time, and
I hope the decision will be to add it to Emacs.

BTW, with this highlighting, I noticed these additional Info text bugs (the
first one I had noticed earlier, but forgot to point out):

 - (eintr)the-the -- "the' should be "the"
 - (gnus)Fancy Mail Splitting: (any "address@hidden" -
"bugs-mypackage" "mypkg.list") -- I'm guessing that the backslash doesn't
belong here.
 - (elisp)Specification List -- `(spec .  [(more specs...)])') -- ' is in
wrong place.

 - Drew

;; The regexp has these parts: double-quoted string or single-quoted stuff.
;;
;; String has, inside "...", zero or more of these characters:
;;   - any character except \ and "
;;   - \ followed by any character
;;
;; Single-quoted stuff has, inside `...': any character except '
;;
;; The regexp matches `...' or "...". The latter case also includes
;; pseudo-strings that start with \". The second branch of the
;; conditional tests this: if that is the match, then it moves past
;; the \.
(defun info-fontify-quotations ()
  "Fontify text between double-quotes (\"...\") and single-quotes (`...')
For single-quotes, use face `info-quoted-name'.
For double-quotes, use face `info-string'."
  (while (re-search-forward             ; Match `...' or "..."
          "\"\\(?:[^\\\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\"\\|`[^']+'"
          nil t)
    (cond ((eq ?` (aref (match-string 0) 0))
           (put-text-property (1+ (match-beginning 0)) (1- (match-end 0))
                              'font-lock-face 'info-quoted-name))
          ((and (goto-char (match-beginning 0)) ; "...": If preceded by \,
skip it
                (= 1 (mod (save-excursion (skip-chars-backward "\\\\")) 2)))
           (forward-char 1))
          ((goto-char (match-end 0))    ; "..." not preceded by \
           (put-text-property (match-beginning 0) (match-end 0)
                              'font-lock-face 'info-string)))))


-----Original Message-----From: Stefan, quoting David, replying to Stefan
> If you don't need regexps, it is usually quite faster just to check with
> (zerop (mod (save-excursion (skip-chars-backward "\\\\")) 2)) whether you
> have an even number of preceding backslashes.

That's true.  The "\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*" prefix can slow down
regexp searching significantly.

Attachment: diff-info-highlight-quotations-fourth.txt
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]