unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Ralf Angeli <angeli@iwi.uni-sb.de>,
	bug-cc-mode@gnu.org, rms@gnu.org, emacs-devel@gnu.org
Subject: Re: [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows]
Date: Thu, 16 Feb 2006 11:27:37 -0500	[thread overview]
Message-ID: <87slqjcorr.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Pine.LNX.3.96.1060216083129.392B-100000@acm.acm> (Alan Mackenzie's message of "Thu, 16 Feb 2006 09:51:50 +0000 (GMT)")

>>> (i) font-lock-fontify-region would no longer be fontifying the region
>>> specified by its paramters, but a different (possibly larger) one.

>> That's already the case since font-lock-fontify-region will typically not
>> fontify from BEG to END from the beginning of line before BEG to the end of
>> line after END.  Then that can be extended yet further because of
>> font-lock-multiline.  Nobody has ever complained about this.

>> So why is it a problem?

> "Nobody complaining" has never been good evidence for something being OK.
[ Follows some exaggeration which I find tends to weaken your point, so
  I prefer to cut it. ]

But the fact is:
- font-lock-fontify-region doesn't have a docstring a doesn't seem
  documented in the Emacs manual either.  So when you say "functions MUST do
  what they say they do", it's not clear to me that font-lock-fontify-region
  says anything about what it does.
- font-lock-fontify-region AFAICT has *never* limited its scope to
  BEG...END.  So anybody expecting font-lock-fontify-region to only fontify
  from BEG to END is deluding himself.

Basically, the way it has been defined and used until now is the following:
fontify the smallest region that includes BEG..END and which doesn't
start or end in the middle of a font-lock-keyword.

For font-lock-keywords which can span several lines, this implies extending
the region by the corresponding number of lines.  Now the region matched by
a given font-lock-keyword can't be automatically determined by
font-lock-fontify-region, so the heuristic used is to extend the region to
a whole number of lines and if that's not enough some other piece of code
(e.g. user-provided code) has to tell it via the font-lock-multiline
property (or as I suggest, via a font-lock-extend-region-functions hook).

Now let's say you have a multiline element which your font-lock-keyword is
somehow able to (re)highlight line-by-line, then you indeed don't need to
extend the region in font-lock-fontify-region.

Of course it gets trickier when your font-lock-keyword can (re)highlight
your multiline element line-by-line but only if the first line of the
element has already been fontified (where it recognizes the element and
somehow marks the text so that fontification of further lines is done
properly).  And even worse if the fontification of the first line only
recognizes the whole element depending on some text further down
(e.g. a terminator), since then the first (and succeeding) line(s) need(s)
to be somehow rehighlighted when the terminator is added/removed.
For such a situation, I currently don't know of a "canonical" way to get
font/jit-lock to do the right thing, other than to simply force the whole
multiline element to always be rehighlighted as a whole (i.e. defeating your
efforts to make your font-lock-keyword able to (re)highlight on
a line-by-line basis).

If that's the case you're trying to solve, then an after-change-function
which marks the whole multiline entity for refontification whenever the
terminator is added/removed won't cut it: if the first line is outside of
the window, jit-lock won't refontify it.

Maybe what will cut it is: using some kind of after/before-change-function
(which doesn't have to be in font-lock-after-change-function) detect when
a terminator is added/removed and in that case add a font-lock-multiline
property on the whole element (which will cause the whole element to be
(re)fontified not matter what jit-lock thinks, but the whole-element
fontification will only happen this one time since the font-lock-multiline
property is removed afterwards).

Another way: move the special treatment of the first line from
font-lock-keywords to font-lock-syntactic-keywords.  Then the
after/before-change-function only needs to move
jit-lock-context-unfontify-pos.

Yet another way: again, move the special treatment of the first line from
font-lock-keywords to font-lock-syntactic-keywords, and have it place
a jit-lock-defer-multiline property on the whole element.  But if you need
the terminator to determine whether and where is the whole element, you
clearly can't use that since you wouldn't know where/when to put that
property such that adding a terminator causes the
appropriate refontification.


        Stefan


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642


  reply	other threads:[~2006-02-16 16:27 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1D94Wo-0006AP-W2@fencepost.gnu.org>
2005-03-09 21:18 ` [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows] Alan Mackenzie
2005-03-09 22:35   ` Stefan Monnier
2005-03-10  8:00     ` Alan Mackenzie
2005-03-10 13:01       ` Stefan Monnier
2005-03-10 15:16         ` D. R. E. Moonfire
2005-03-10 17:01           ` Stefan Monnier
2005-03-10 20:09         ` Alan Mackenzie
2005-03-10 20:53           ` Stefan Monnier
2005-03-10 22:42             ` Alan Mackenzie
2005-03-11 20:28           ` Richard Stallman
2005-03-11  1:48       ` Richard Stallman
2005-03-11 19:43         ` Alan Mackenzie
2005-03-10 22:13     ` Martin Stjernholm
2005-03-10 22:59       ` Stefan Monnier
2005-03-11 20:27         ` Richard Stallman
2005-03-13 16:19         ` Martin Stjernholm
2005-03-14  1:07           ` Stefan Monnier
2005-03-19 22:23             ` Martin Stjernholm
2005-03-19 22:30               ` Stefan Monnier
2005-03-11  1:47     ` Richard Stallman
2005-03-11  4:47       ` Stefan Monnier
2005-03-12  0:56         ` Richard Stallman
2005-03-12  1:00           ` Stefan Monnier
2005-03-13 15:30             ` Richard Stallman
2005-03-11  1:46   ` Richard Stallman
2005-03-11  1:46   ` Richard Stallman
2006-02-12 13:06     ` Ralf Angeli
2006-02-12 16:20       ` Stefan Monnier
2006-02-12 22:58         ` Ralf Angeli
2006-02-13 22:10           ` Stefan Monnier
2006-02-14  7:53             ` martin rudalics
2006-02-14 19:00               ` Stefan Monnier
2006-02-14 20:13                 ` martin rudalics
2006-02-14 21:08                   ` Stefan Monnier
2006-02-15 10:17                     ` martin rudalics
2006-02-15 10:38                       ` Ralf Angeli
2006-02-15 14:20                         ` martin rudalics
2006-02-15 14:56                           ` Ralf Angeli
2006-02-15 16:40                             ` martin rudalics
2006-02-15 17:03                               ` Ralf Angeli
2006-02-16 11:10                               ` Alan Mackenzie
2006-02-16 11:54                                 ` Vivek Dasmohapatra
2006-02-16 15:21                                 ` Stefan Monnier
2006-02-16 23:28                                   ` David Kastrup
2006-02-17 14:19                                     ` Stefan Monnier
2006-02-16 17:21                                 ` martin rudalics
2006-02-15 20:44                     ` Alan Mackenzie
2006-02-16  0:40                       ` Stefan Monnier
2006-02-15 20:56                   ` Alan Mackenzie
2006-02-16  8:56                     ` martin rudalics
2006-02-15 20:13               ` Alan Mackenzie
2006-02-16  9:02                 ` martin rudalics
2006-02-14  8:18             ` Werner LEMBERG
2006-02-14  8:49             ` Ralf Angeli
2006-02-14 19:05               ` Stefan Monnier
2006-02-14 21:12                 ` Ralf Angeli
2006-02-15 13:35                   ` Stefan Monnier
2006-02-15 14:05                     ` Ralf Angeli
2006-02-15 14:21                       ` Ralf Angeli
2006-02-15 20:33             ` Alan Mackenzie
2006-02-15 21:13               ` Stefan Monnier
2006-02-15 21:59                 ` Alan Mackenzie
2006-02-16 14:59                 ` Kim F. Storm
2006-02-16 16:37                   ` Stefan Monnier
2006-02-15 19:07         ` Alan Mackenzie
2006-02-15 21:42           ` Ralf Angeli
2006-02-16 11:20             ` Alan Mackenzie
2006-02-16 11:54               ` Ralf Angeli
2006-02-16 15:12                 ` Alan Mackenzie
2006-02-17  7:56                   ` martin rudalics
2006-02-17 11:32                     ` Ralf Angeli
2006-02-17 13:22                       ` martin rudalics
2006-02-17 13:33                         ` Ralf Angeli
2006-02-16 16:32                 ` Stefan Monnier
2006-02-16  0:38           ` Stefan Monnier
2006-02-16  9:51             ` Alan Mackenzie
2006-02-16 16:27               ` Stefan Monnier [this message]
2006-02-17  7:48                 ` martin rudalics
2006-02-17 14:36                   ` Stefan Monnier
2006-02-16 18:46               ` martin rudalics
2006-02-16  9:09           ` martin rudalics
2006-02-13  4:40       ` Richard M. Stallman
2006-02-13  5:25         ` Stefan Monnier
2006-02-14  0:39           ` Richard M. Stallman
2006-03-14 19:23         ` Alan Mackenzie
2006-03-14 22:11           ` Stefan Monnier
2006-03-15  8:52             ` martin rudalics
2006-03-15  9:02             ` Ralf Angeli
2006-03-15 10:22               ` Stefan Monnier
2006-03-15 11:40             ` Alan Mackenzie
2006-03-15 16:16               ` Stefan Monnier
2006-03-15 20:20           ` Richard Stallman
2006-03-20  8:16           ` font-lock-extend-region (was: [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows]) Stefan Monnier
2006-03-20 13:01             ` Alan Mackenzie
2006-03-20 17:18               ` font-lock-extend-region Stefan Monnier
2006-03-21 16:05                 ` font-lock-extend-region Alan Mackenzie
2006-03-21 21:32                   ` font-lock-extend-region Stefan Monnier
2006-03-23 15:23                     ` font-lock-extend-region Alan Mackenzie
2006-03-23 16:18                       ` font-lock-extend-region Stefan Monnier
2006-02-15 19:34       ` [sigra@home.se: C++-mode: Syntax highlighting: wrong color for function identifier depending on the kind of whitespace that follows] Alan Mackenzie
2006-02-16  9:07         ` Ralf Angeli
2006-02-16  9:07         ` martin rudalics

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87slqjcorr.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=angeli@iwi.uni-sb.de \
    --cc=bug-cc-mode@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).