unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#38049: C mode fontification broken with reposition-window
@ 2019-11-03 20:28 Juri Linkov
       [not found] ` <mailman.552.1572813126.13325.bug-gnu-emacs@gnu.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Juri Linkov @ 2019-11-03 20:28 UTC (permalink / raw)
  To: 38049

Version: 27.0.50

This is a reproducible test case:

0. emacs -Q
1. C-x C-f emacs/lib-src/emacsclient.c
2. M-: (progn (search-forward "create-frame" nil t) (reposition-window))

Then half screen displays unfontified lines.

Fontification doesn't fail in other modes, only in C mode.

This has something to do with interaction between c-font-lock
and buffer navigation in reposition-window.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
       [not found] ` <mailman.552.1572813126.13325.bug-gnu-emacs@gnu.org>
@ 2019-11-03 21:27   ` Alan Mackenzie
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-11-03 21:27 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 38049

In article <mailman.552.1572813126.13325.bug-gnu-emacs@gnu.org> you wrote:
> Version: 27.0.50

> This is a reproducible test case:

> 0. emacs -Q
> 1. C-x C-f emacs/lib-src/emacsclient.c
> 2. M-: (progn (search-forward "create-frame" nil t) (reposition-window))

> Then half screen displays unfontified lines.

Yes.  This is an interesting bug.

The unfontified area seems to be one jit-lock chunk immediately below
the line containing "create-frame".

> Fontification doesn't fail in other modes, only in C mode.

> This has something to do with interaction between c-font-lock
> and buffer navigation in reposition-window.

reposition-window, as far as I've been able to make out so far, seems to
assume that point starts in the current visible window.  That is not the
case here, where window-start is still at BOB, but point is at line 116.

I'll look at this in more detail when it's not so late.

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
  2019-11-03 20:28 bug#38049: C mode fontification broken with reposition-window Juri Linkov
       [not found] ` <mailman.552.1572813126.13325.bug-gnu-emacs@gnu.org>
@ 2019-11-05 21:07 ` Alan Mackenzie
       [not found] ` <20191105210737.GA6303@ACM>
  2 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-11-05 21:07 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 38049

Hello, Juri.

On Sun, Nov 03, 2019 at 22:28:05 +0200, Juri Linkov wrote:
> Version: 27.0.50

> This is a reproducible test case:

> 0. emacs -Q
> 1. C-x C-f emacs/lib-src/emacsclient.c
> 2. M-: (progn (search-forward "create-frame" nil t) (reposition-window))

> Then half screen displays unfontified lines.

> Fontification doesn't fail in other modes, only in C mode.

> This has something to do with interaction between c-font-lock
> and buffer navigation in reposition-window.

Indeed it does.

Briefly,
(i) reposition-window narrows to (2758 3940) in
repos-count-screen-lines.
(ii) This latter function uses vertical-motion to count the lines.
(iii) vertical-motion triggers jit-lock fontification.
(iv) This calls (eventually) c-font-lock-fontify-region.
(v) c-font-lock-fontify-region attempts to examine buffer text before
  the start of the jit-lock chunk to find syntactic context.
(vi) This is outside the visible region, so Emacs raises an exception.
(vii) The exception is caught and discarded by an unwind-protect in
  c-font-lock-fontify-region.
(viii) The jit-lock chunk remains unfontified.

As Stefan M has sometimes remarked, narrowing is often not a good idea.

It would seem undesirable for the vertical-motion in (iii) to trigger
font-locking, since it is merely trying to count lines.  Perhaps there
should be a macro `without-fontifying' which could be wrapped around
this call to vertical-motion, if there isn't such a thing anyway.

Maybe there are other calls of vertical-motion which are similarly
dangerous.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
       [not found] ` <20191105210737.GA6303@ACM>
@ 2019-11-05 22:10   ` Juri Linkov
  2019-11-06 17:13   ` Eli Zaretskii
  2019-11-09 14:45   ` Alan Mackenzie
  2 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2019-11-05 22:10 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 38049

> Briefly,
> (i) reposition-window narrows to (2758 3940) in
> repos-count-screen-lines.
> (ii) This latter function uses vertical-motion to count the lines.
> (iii) vertical-motion triggers jit-lock fontification.
> (iv) This calls (eventually) c-font-lock-fontify-region.
> (v) c-font-lock-fontify-region attempts to examine buffer text before
>   the start of the jit-lock chunk to find syntactic context.
> (vi) This is outside the visible region, so Emacs raises an exception.
> (vii) The exception is caught and discarded by an unwind-protect in
>   c-font-lock-fontify-region.
> (viii) The jit-lock chunk remains unfontified.
>
> As Stefan M has sometimes remarked, narrowing is often not a good idea.
>
> It would seem undesirable for the vertical-motion in (iii) to trigger
> font-locking, since it is merely trying to count lines.  Perhaps there
> should be a macro `without-fontifying' which could be wrapped around
> this call to vertical-motion, if there isn't such a thing anyway.

ISTR there was some macro to disable font-lock temporarily,
but I can't find it.  Maybe just let-binding font-lock-mode to nil
could help?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
       [not found] ` <20191105210737.GA6303@ACM>
  2019-11-05 22:10   ` Juri Linkov
@ 2019-11-06 17:13   ` Eli Zaretskii
  2019-11-06 20:56     ` Alan Mackenzie
  2019-11-09 14:45   ` Alan Mackenzie
  2 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2019-11-06 17:13 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 38049, juri

> Date: Tue, 5 Nov 2019 21:07:37 +0000
> From: Alan Mackenzie <acm@muc.de>
> Cc: 38049@debbugs.gnu.org
> 
> (i) reposition-window narrows to (2758 3940) in
> repos-count-screen-lines.
> (ii) This latter function uses vertical-motion to count the lines.
> (iii) vertical-motion triggers jit-lock fontification.
> (iv) This calls (eventually) c-font-lock-fontify-region.
> (v) c-font-lock-fontify-region attempts to examine buffer text before
>   the start of the jit-lock chunk to find syntactic context.
> (vi) This is outside the visible region, so Emacs raises an exception.
> (vii) The exception is caught and discarded by an unwind-protect in
>   c-font-lock-fontify-region.
> (viii) The jit-lock chunk remains unfontified.
> 
> As Stefan M has sometimes remarked, narrowing is often not a good idea.

Narrowing is part of life.

Why can't c-font-lock-fontify-region be fixed so as not to signal an
error in these cases?  If we do, will that fix the original problem?

> It would seem undesirable for the vertical-motion in (iii) to trigger
> font-locking, since it is merely trying to count lines.

vertical-motion calls functions from the display engine, which
fontifies the text it traverses.  It doesn't only count lines, it also
counts columns in canonical character width units (i.e. actually in
pixels).  So it cannot possibly avoid fontifications because
fontification might affect how many pixels characters take on
display.  Fontifications can also affect the line count, if some
fontification code actually puts display properties on the fontified
text -- something that you rarely if ever see, but Lisp programs can
rightfully expect that.  So this idea:

> Perhaps there should be a macro `without-fontifying' which could be
> wrapped around this call to vertical-motion, if there isn't such a
> thing anyway.

cannot fly, sorry.

Let's try to fix the problem in c-font-lock-fontify-region instead,
okay?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
  2019-11-06 17:13   ` Eli Zaretskii
@ 2019-11-06 20:56     ` Alan Mackenzie
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-11-06 20:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 38049, juri

Hello, Eli.

On Wed, Nov 06, 2019 at 19:13:44 +0200, Eli Zaretskii wrote:
> > Date: Tue, 5 Nov 2019 21:07:37 +0000
> > From: Alan Mackenzie <acm@muc.de>
> > Cc: 38049@debbugs.gnu.org

> > (i) reposition-window narrows to (2758 3940) in
> > repos-count-screen-lines.
> > (ii) This latter function uses vertical-motion to count the lines.
> > (iii) vertical-motion triggers jit-lock fontification.
> > (iv) This calls (eventually) c-font-lock-fontify-region.
> > (v) c-font-lock-fontify-region attempts to examine buffer text before
> >   the start of the jit-lock chunk to find syntactic context.
> > (vi) This is outside the visible region, so Emacs raises an exception.
> > (vii) The exception is caught and discarded by an unwind-protect in
> >   c-font-lock-fontify-region.
> > (viii) The jit-lock chunk remains unfontified.

> > As Stefan M has sometimes remarked, narrowing is often not a good idea.

> Narrowing is part of life.

Indeed.

> Why can't c-font-lock-fontify-region be fixed so as not to signal an
> error in these cases?  If we do, will that fix the original problem?

Yes.  Thinking about it, font locking might present
c-font-lock-fontify-region a chunk in any state of narrowing.  It just
doesn't happen that way very often, though.  So CC Mode needs to widen
the buffer to make sure it has adequate access.

> > It would seem undesirable for the vertical-motion in (iii) to trigger
> > font-locking, since it is merely trying to count lines.

> vertical-motion calls functions from the display engine, which
> fontifies the text it traverses.  It doesn't only count lines, it also
> counts columns in canonical character width units (i.e. actually in
> pixels).  So it cannot possibly avoid fontifications because
> fontification might affect how many pixels characters take on
> display.  Fontifications can also affect the line count, if some
> fontification code actually puts display properties on the fontified
> text -- something that you rarely if ever see, but Lisp programs can
> rightfully expect that.  So this idea:

> > Perhaps there should be a macro `without-fontifying' which could be
> > wrapped around this call to vertical-motion, if there isn't such a
> > thing anyway.

> cannot fly, sorry.

Yes, accepted and understood.

> Let's try to fix the problem in c-font-lock-fontify-region instead,
> okay?

I'll do that.  It just needs a simple widen in a save-restriction.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#38049: C mode fontification broken with reposition-window
       [not found] ` <20191105210737.GA6303@ACM>
  2019-11-05 22:10   ` Juri Linkov
  2019-11-06 17:13   ` Eli Zaretskii
@ 2019-11-09 14:45   ` Alan Mackenzie
  2 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-11-09 14:45 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 38049-done

Hello, Juri.

On Tue, Nov 05, 2019 at 21:07:37 +0000, Alan Mackenzie wrote:
> On Sun, Nov 03, 2019 at 22:28:05 +0200, Juri Linkov wrote:
> > Version: 27.0.50

> > This is a reproducible test case:

> > 0. emacs -Q
> > 1. C-x C-f emacs/lib-src/emacsclient.c
> > 2. M-: (progn (search-forward "create-frame" nil t) (reposition-window))

> > Then half screen displays unfontified lines.

> > Fontification doesn't fail in other modes, only in C mode.

> > This has something to do with interaction between c-font-lock
> > and buffer navigation in reposition-window.

> Indeed it does.

> Briefly,
> (i) reposition-window narrows to (2758 3940) in
> repos-count-screen-lines.
> (ii) This latter function uses vertical-motion to count the lines.
> (iii) vertical-motion triggers jit-lock fontification.
> (iv) This calls (eventually) c-font-lock-fontify-region.
> (v) c-font-lock-fontify-region attempts to examine buffer text before
>   the start of the jit-lock chunk to find syntactic context.
> (vi) This is outside the visible region, so Emacs raises an exception.
> (vii) The exception is caught and discarded by an unwind-protect in
>   c-font-lock-fontify-region.
> (viii) The jit-lock chunk remains unfontified.

[ .... ]

I have fixed this bug by widening around c-font-lock-fontify-region.  I
am closing the bug with this post.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-09 14:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-03 20:28 bug#38049: C mode fontification broken with reposition-window Juri Linkov
     [not found] ` <mailman.552.1572813126.13325.bug-gnu-emacs@gnu.org>
2019-11-03 21:27   ` Alan Mackenzie
2019-11-05 21:07 ` Alan Mackenzie
     [not found] ` <20191105210737.GA6303@ACM>
2019-11-05 22:10   ` Juri Linkov
2019-11-06 17:13   ` Eli Zaretskii
2019-11-06 20:56     ` Alan Mackenzie
2019-11-09 14:45   ` Alan Mackenzie

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).