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: Tue, 5 Oct 2004 21:19:56 -0700

Info highlighting off by default. I can live with that. What do others
think?

BTW, have you -- have others -- _tried_ the code? Your argument sounds,
well, hypothetical. In _practice_, there are only *4* nodes of the Elisp
Manual that exhibit any highlighting problem at all, and those pbs are
minor. This is a big manual.

Yes, it's obvious that there will always be some examples of code in the
Info doc (on different programming languages, for instance) that use
expressions (e.g. regexp expressions or byte-code examples) that won't
highlight 100% correctly. Info highlighting works perfectly 99% of the time,
however, including lots of crazy regexp expressions in the Elisp manual
(yes, it's surprising).

And, the same rare problems can be seen with font-lock highlighting of Emacs
Lisp code -- which is presumably one reason we turn off font-lock by
default. (Do the doc strings of font-lock functions mention that they
"occasionally can lead to anomalous highlighting"?  Are we worried about
being sued, here, or what?)

Some of the rare Info highlighting problems point out things that should
really be changed in the Info files themselves, such as ``region'' instead
of "region" at node (emacs)Top (highlighted from first ` to first '), or
this unnecessary single-quoting of a Lisp sexp at node (elisp)Auto Major
Mode: `("\\.gz\\'" FUNCTION t)'.

You say that Info markup is "intended for navigation, not highlighting". The
`...' convention is explicitly intended to _highlight_ (demarcate, delimit,
bring out, set off, draw attention to) commands, key sequences, and perhaps
file names. It has absolutely nothing to do with navigating. That's the
markup convention I want to exploit here -- that and "..." for strings. This
proposal has nothing to do with other, hidden info-file markup; it is all
about user-visible "highlighting".

Perhaps what you meant was that `...' was not _originally designed_ with an
eye to being highlighted. Agreed. But it lends itself to highlighting
remarkably well, with no changes needed.

Again, I invite you to try it, to see what it does in _practice_. Here is
the code, with the latest regexp, which allows escaped chars and newlines
inside `...' and "...".  (Some Info nodes, like (emacs)Visiting, split a key
sequence or command name over two lines.)

(defun info-fontify-quotations ()
    "Fontify double-quote strings (\"...\") and text between single-quotes
(`...')
For single-quotes, use face `info-quoted-name'.
For double-quotes, use face `info-string'."
    (while
        (re-search-forward

"\"\\(?:[^\\\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\"\\|`\\(?:[^'\\]\\|\\\\\\(?:.\\|[
\n]\\)\\)+'"
         nil t)
      (if (eq ?` (aref (match-string 0) 0))
          (put-text-property (1+ (match-beginning 0)) (1- (match-end 0))
                             'face 'info-quoted-name)
        (put-text-property (match-beginning 0) (match-end 0)
                           'face 'info-string))))

Again, to use this, just call `info-fontify-quotations' at the end of
`Info-fontify-node' -- add this just before the last line, which is
(set-buffer-modified-p nil):
        (goto-char (point-min))
        (when Info-fontify-quotations-p (info-fontify-quotations))

Hoping to hear from more people who have tried the code, regardless of which
way your opinion leans.

 - Drew

P.S. FYI, the 4 Elisp-manual nodes that do _not_ highlight 100% correctly
are these:

 - Example Major Modes -- an isolated " (?\")
 - Index -- an isolated "  (" entry in the index)
 - Auto Major Modes -- the single-quoted Lisp sexp mentioned above
 - Standard Error -- ' inside "..." inside `...' (`"Symbol's chain of
function indirections contains a loop"') -- this too should probably be
corrected in the doc itself

If the latter two were corrected in the Info files, there would be only *2*
nodes of the entire Elisp manual that were not 100% perfect. I don't think
we'll be sued.


-----Original Message-----
From: Luc Teirlinck [mailto:address@hidden

   So, what do you and others think of the _desirability_ of (optionally)
   highlighting quoted expressions in Info?

Info files are essentially plain text with some minimal markup that is
intended for navigation, not highlighting.  So I believe that there is
no way that one can do what you are trying to do completely reliably
any more than that it is possible to implement
Info-hide-note-references completely reliably.  To do that, one would
need to base the Emacs Info reader on the XML output format instead of
on the Info output format.  (Maybe somebody might actually do that
some day.)

So I would suggest that if any feature like this is added to the Emacs
Info reader, that it should be done as a user option, that is off by
default.  Also, the docstring should explicitly mention that it
occasionally can lead to anomalous highlighting.





reply via email to

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