[Top][All Lists]
[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: |
Tue, 5 Oct 2004 00:15:42 -0700 |
Below is code that highlights "..." and `...' quotations in Info. The minor
display pbs I mentioned earlier (escaped quotes) have been eliminated, with
input from Lennart Borgman. The only Info nodes in the Emacs manual that
still display with slight problems are these:
- Acknowledgements
- Etags Regexps
- Glossary (very minor)
These remaining display problems are because of isolated " characters. For
instance, in node Acknowledgements, this appears, which turns on
highlighting until the next " in the node:
Torbjo"rn Einarsson contributed the...
And this appears in Glossary, which highlights only between the first ` and
the first ':
ASCII printing character
ASCII printing characters include letters, digits, space, and these
punctuation characters: address@hidden& *()_-+=|\~` {}[]:;"' <>,.?/'.
The Etags Regexps pb is similar to the Glossary pb. Nothing to be done about
this. And as I say, I found only three such occurrences in the entire Emacs
manual.
I also went through the entire Elisp manual, and found only 7 nodes where
there were (similar) problems: Compilation Functions, Example Major Modes,
Auto Major Mode, Imenu, Regexp Example, Standard Errors, and Index.
So, I'm proposing these changes to `info.el':
1. Add these user options (or equivalent), for the quotation highlight faces
and for turning this highlighting on/off:
(defface info-quoted-name-face ; For `...'
'((((class color) (background light)) :foreground "red3")
(((class color) (background dark)) :foreground "white")
(t :weight bold :slant italic))
"Face used for quoted names (`...') in `info'."
:group 'info)
(defface info-string-face ; For "..."
'((((class color) (background light)) :foreground "green3")
(((class color) (background dark)) :foreground "yellow")
(t :slant italic))
"Face used for strings (\"...\") in `info'."
:group 'info)
(defcustom Info-fontify-quotations-flag t
"*Non-nil means `info' fontifies text between quotes.
This applies to double-quote strings (\"...\") and text between
single-quotes (`...')."
:type 'boolean
:group 'info)
Note: Whatever colors are picked, I think `info-quoted-name-face' should
stand out more than `info-string-face'.
2. Add this function (or equivalent) to `info.el':
(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
p0e (nth 1 (match-data)) ; End of m0
m1 (match-string 1) ; \* subexp of "...\*" match
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) ; \*"
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))))))))
(if (eq ?` (aref m0 0))
(put-text-property (1+ p0b) (1- p0e) 'face 'info-quoted-name-face)
(put-text-property p0b p0e 'face 'info-string-face)))))
3. Call `info-fontify-quotations' at the end of `Info-fontify-node' -- add
this just before the last line, (set-buffer-modified-p nil):
(goto-char (point-min))
(when Info-fontify-quotations-p (info-fontify-quotations))
Could others please try this and see if you think it should be added.
Thanks,
Drew
- info faces for strings and quotations, Drew Adams, 2004/10/03
- RE: info faces for strings and quotations,
Drew Adams <=
- Re: info faces for strings and quotations, Miles Bader, 2004/10/05
- RE: info faces for strings and quotations, Drew Adams, 2004/10/05
- Re: info faces for strings and quotations, Stefan, 2004/10/05
- RE: info faces for strings and quotations, Drew Adams, 2004/10/05
- Re: info faces for strings and quotations, Luc Teirlinck, 2004/10/05
- RE: info faces for strings and quotations, Drew Adams, 2004/10/06
- Re: info faces for strings and quotations, Miles Bader, 2004/10/06
- RE: info faces for strings and quotations, Drew Adams, 2004/10/06
- Prev by Date:
New2004, medicine, Bloodpressure, cancer, flu, health, 40, 000 hospitals, 25, 000 nursing homes and 400, 000 doctors.
- Next by Date:
Re: info faces for strings and quotations
- Previous by thread:
info faces for strings and quotations
- Next by thread:
Re: info faces for strings and quotations
- Index(es):