Subject: bug#16621: 24.3.50; Periodic timer + overlays = flickering near point

From: Eli Zaretskii <[email-masked]>
Date: Sun, 02 Feb 2014 18:39:48 +0200

> From: Dmitry Gutov <[email-masked]>
> Date: Sun, 02 Feb 2014 03:01:26 +0200
> 
> It happens with different overlays, and with the default monospaced font

I don't think this is related to overlays, not directly anyway.

> of my system (Ubuntu GNU/Linux), but it's easiest to reproduce doing
> isearch, and using Fira Mono (TrueType version, available from
> https://www.mozilla.org/en-US/styleguide/products/firefox-os/typeface/,
> see the bottom of the page). Steps from emacs -Q:
> 
> 1. Evaluate (run-at-time nil 0.01 'ignore)
> 
> 2. Evaluate (set-face-attribute 'default nil :height 105 :family "Fira Mono")
> 
> This is optional, but with the default font the flickering is harder to
> reproduce.
> 
> 3. Open a text file press C-s (or C-r), enter some letters, preferably
> common to that file, press C-s or C-r again. Repeat multiple times.
> Maybe do that for a couple of minutes, even.
> 
> 4. Observe flickering letters, usually one to the left, or one to the
> right of the cursor.
> 
> Most of the time the flickering happens 2 or 3 times and stops

No, it doesn't stop, at least not with the above recipe.  To see that,
type "M-x trace-redisplay RET" while running the above experiment --
on my system, this causes the flickering to become much more prominent
and never stop, until I exit isearch and type some simple command,
like C-f, afterwards (to remove the echo-area message).

I'm guessing that the apparent cease of the flickering is actually due
to the fact that the timer frequency is an integral multiple of the
hardware screen update rate (but I didn't pursue this line of
investigation, as I don't think it is of interest).

> This is in no way limited to isearch. For example, I can also see it
> when typing, when using the fancy highlight-tail-mode
> (http://www.emacswiki.org/emacs-en/highlight-tail.el), at least with
> settings highlight-tail-steps 14, highlight-tail-timer 0.02.

What you see is result of redrawing the cursor at a very high
frequency.  Normally, redrawing the cursor would only flicker the
character below the cursor, but with some fonts, the adjacent
characters are also affected, if the character under the cursor
"overhangs" to the left and/or to the right into the neighboring
character cells -- then Emacs redraws those adjacent characters as
well.

Why is the cursor redrawn with such a high frequency, you ask?
Because of the timer that expires every 10 msec.  When some timer
expires, Emacs always triggers redisplay.  If it didn't, features like
highlight-tail could not produce their effect.

When a timer expires and triggers redisplay, and nothing have changed
on display, Emacs normally sees that, and doesn't update the screen.
But if there is an echo-area message, like the one displayed by
isearch, this optimization is disabled, and we redisplay the echo
area.  Redisplaying the echo area involves calling the frame update
function, which redraws the cursor.  And that is what you see in the
isearch case.

With highlight-tail-mode, I see flickering only when I type text.
This is expected, since typing text modifies the color of the overlays
at a very high frequency (50 Hz with your customizations), which again
requires redrawing the current line and the cursor.  If you see
something else with highlight-tail-mode, please describe the recipe.

All of the above is quite normal, so I don't see where there would be
a bug.  Granted, Emacs 24.3 and Emacs 23 behave the same.

Thanks.