Subject: Re: bug#33740: [PATCH] Customizable flymake mode-line indicator

From: Lars Ingebrigtsen <[email-masked]>
Date: Fri, 20 Sep 2019 14:32:00 +0200

Eli Zaretskii <[email-masked]> writes:

> It is.  Redrawing the mode line is a very frequent redisplay thing, so
> optimizing the heck out of it is justified.

In the simple case where the mode line element is a string, I can
definitely see that it's warranted.  In the Flymake case, where the
value is (:eval (flymake--mode-line-format)), which returns a long and
complex (:propertize) form that's then interpreted by this machinery --
it's pessimal.

> That's what I meant when I said "wisely": you need to create faces in
> advance, and take care to have each individual string you use to be of
> a uniform face.  And don't use propertize.

Most modes do not have dynamic lighters, and using (:propertize) forms
is a fine solution.  For something like Flymake, that updates its
lighter every time the mode line is redrawn, it just doesn't make much
sense.  If Flymake could just return a properly propertized string, then
that would be a lot more efficient (both cons-wise and time wise) having
it return this form (which I've lightly edited to elide the keymaps):

((:propertize " Flymake" mouse-face mode-line-highlight help-echo "3 known backends\n2 running\n1 disabled\nmouse-1: Display minor mode menu\nmouse-2: Show help for minor mode" keymap ...)
 (:propertize "[")
 (:propertize "0" face compilation-error mouse-face mode-line-highlight keymap ..
	      help-echo
	      #("0 diagnostics of type :error\nmouse-4/mouse-5: previous/next of this type" 0 1
		(face compilation-error)
		22 28
		(face compilation-error)))
 (:propertize " ")
 (:propertize "0" face compilation-warning mouse-face mode-line-highlight keymap ...
	      help-echo
	      #("0 diagnostics of type :warning\nmouse-4/mouse-5: previous/next of this type" 0 1
		(face compilation-warning)
		22 30
		(face compilation-warning)))
 (:propertize " ")
 (:propertize "14" face compilation-info mouse-face mode-line-highlight keymap ...
	      help-echo
	      #("14 diagnostics of type :note\nmouse-4/mouse-5: previous/next of this type" 0 2
		(face compilation-info)
		23 28
		(face compilation-info)))
 (:propertize "]"))

If there was a way to tell display_mode_element "don't do the caching
stuff on this element", then Flymake could just return a propertized
string and display_mode_element would have to do a whole lot less
processing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no