unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: bug-cc-mode@gnu.org, martin rudalics <rudalics@gmx.at>,
	Ralf Angeli <angeli@iwi.uni-sb.de>,
	"Richard M. Stallman" <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: Wed, 15 Mar 2006 11:16:28 -0500	[thread overview]
Message-ID: <jwvacbrso7p.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <Pine.LNX.3.96.1060315084719.514A-100000@acm.acm> (Alan Mackenzie's message of "Wed, 15 Mar 2006 11:40:45 +0000 (GMT)")

>> Also, I thought we had agreed that this new feature should be in
>> f-l-default-fontify-region rather than f-l-after-change-function.  I believe
>> it is *wrong* for it to be in f-l-after-change-function where it is mostly
>> useless:

> It actually works quite well, I've tested it.  :-)

Please re-read what I wrote.  I don't say it won't work.  It has various
problems, tho, which you most likely wouldn't notice in random testing,
especially if you turn off jit-lock.

> I'm convinced this feature needs to be in the font-lock/jit-lock
> after-change-functions.  The fontification region is determined by the
> _change_, not merely by the buffer contents after the change.  For
> example:

> The stealth/display fontification would extend their regions using these
> functions,

Thinking of stealth fontification as a special case will not lead you to
a good solution.  Been there, done that.  All the problems I've ever
encountered that were supposedly "due to jit-lock" could also be reproduced
without jit-lock.

>> you can already get the same result by using an
>> (non-f-l)after-change-functions hook that sets the
>> font-lock-multiline property.

> OK, but for that, font-lock-multiline must first be documented.

Go for it.  Note that I'm not talking about the variable, but about the
text-property.

> I've tried to figure out from the source how f-l-multiline works, but
> haven't succeeded yet.  Can f-l-multiline be used to extend the
> fontification region backwards?

Of course.  Put font-lock-multiline property on all the chars of a region
that should be refontified as a whole because the font-lock-keywords don't
know how to refontify it correctly unless they get to see the whole thing
at once.  f-l-default-fontify-region then extends the region
forward&backward so the region it refontifies doesn't start or end in the
middle of a font-lock-multiline property.

> With the f-l-multiline approach, you need somehow to ensure that the
> non-f-l-after-change function gets called before f-l-after-change.

Not if you use jit-lock ;-)

> It can be done, but is hassle.  Also, f-l-multiline is an internal Font
> Lock mechanism, and major modes shouldn't have to manipulate it directly,
> since it would increase the coupling between modes and Font Lock
> enormously, making it expensive to change approach in the future.

The feature you added suffers from the exact same problem.

> #########################################################################

>>> More controversially, I've explicitly documented that the region returned
>>> by the f-l-extend-region may start or end in the middle of a line.

>> I don't care much either way.  If someone does that, it's his problem:
>> it won't hurt font-lock.el.  But it may screw up the other
>> font-lock-keywords.

> Why would it be a problem?  Given that f-l-extend-region-function and
> font-lock-keywords both belong to the major mode, they can be made to
> match eachother.

Exactly: the author can only shoot himself, so "it's his problem".
Except of course for minor modes which add their own keywords (via
font-lock-add-keywords, for example), but these already suffer from several
other comparable minor problems, so it's probably not making things
noticeably worse.

> A comment in jit-lock says that if the f-l region starts in the middle of
> a line, that line won't be re-displayed.

Which comment?

>>> The "baz" on L3 hasn't a snowball's chance in Hades of getting fontified
>>> with f-l-function-name-face unless the font lock region is allowed to
>>> start at the "int" on L2.

>> Why?  After all, when you open the file, the region will start at BOB.

> When you open the file, yes.

> (i) You type a space on L2, "baz" changes to variable-name-face.

> (ii) You then type a space on L3, it flips back to function-name-face,
> but "bar" goes to default face.  (font-lock-lines-before == 1)

> (iii) Type a space on L1, "bar" is restored to variable-name-face after
> ~0.5 second (contextual fontification?).

> (iv) reload the file, do (i), then put point over "baz" (currently
> variable-name-face).  Do C-u C-x =, to display its properties.  It
> changes instantly to function-name-face, which it reports in the other
> window.  Hello Heisenberg!

I dno't see where the above example requires the region to start "at the int
on L2" (or more generally in the middle of a line).

> I honestly don't think it's worthwhile to investigate each of these
> happenings individually - it's amusing to watch for a few minutes, but
> rapidly becomes tedious.  They all stem from a single cause, namely the
> misapprehension that font lock can start analyzing code at an
> arbitrary BOL.

It's not a misapprehension: it's a constraint.  If your font-lock-keywords
don't obey this constraint, then yes, you'll see funny things because your
font-lock-keywords are broken.  Lifting this constraint is what "adding
multiline keywords support" is all about.  But I still haven't seen any
example where it needs to be possible to start in the middle of a line.
What is often neded is to be able to prevent starting/ending at some
particular BOLs.

> OK, these are likely to be bugs in CC Mode's font lock patterns, but the
> uncertainty caused by font-lock's instability makes them more difficult
> to debug.

Easy: turn off jit-lock and it becomes much more deterministic (and those
bugs can still be easily reproduced).  Sometimes you just need to cut&paste
a block of text at the same spot (i.e. mark and then C-w C-y).

> (i) f-l-extend-region-function should be supplemented by
> f-l-safe-\(floor\|ceiling\)-position-function; if non-nil, these
> functions give guaranteed good boundaries for fontification.  They would
> render contextual fontification redundant.

No, it's still not redundant at all.  Contextual fontification is solving
other cases of multiline patterns where the approach of extending the region
is unworkable (because the region may end up extended much too far, bringing
Emacs to a crawl): e.g. removing/adding a " in a C file typically causes the
whole rest of the buffer to be refontified.

> (ii) Code expanding the font lock region to whole lines should be
> removed (except as in (iii)).  font-lock-multiline would become
> redundant.

I fail to see the conection between font-lock-multiline and whole lines.

> (iv) The interface between Font Lock and the display code should be
> amended so that a font lock region need not start at column 0.

I don't think there is any such requirement.


        Stefan


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642


  reply	other threads:[~2006-03-15 16:16 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
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 [this message]
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=jwvacbrso7p.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 \
    --cc=rudalics@gmx.at \
    /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).