Subject: bug#77361: [PATCH] New user option to hide minor mode lighters

From: Pengji Zhang <[email-masked]>
Date: Sun, 06 Apr 2025 16:17:54 +0800

Daniel Mendler <[email-masked]> writes:

> Hello Pengji!

Hi Daniel!

> This is a good idea. I've used both minions and diminish and it is nice
> to have this functionality ootb. I have some concerns however regarding
> the frequent mode line recomputation during redisplay. Do you see a
> possibility to cache the computed minor mode menu and collapsed lighter?
> In any case, the computation should be as efficient as possible. For
> profiling I suggest to enable your new user option and then scroll
> repeatedly in order to force redisplays and mode line recomputations. If
> certain mode line functions appear prominently in the profile they are
> candidates for optimization, in order to reduce redisplay latency.

Thanks! I did not consider the performance issue much. How about
deferring the computation of the minor mode menu, the most costly part?

+          (unless (string= "" (format-mode-line `("" ,hidden)))
+            (let* ((menu
+                    ;; FIXME: This is to defer the computation of the
+                    ;; menu, but may not play well with touchscreen.
+                    (lambda (e)
+                      (interactive "@e")
+                      (if-let* ((m (mode-line--make-lighter-menu hidden)))
+                          (popup-menu m e)
+                        (message "No menu available"))))
+                   (keymap
+                    (define-keymap
+                      :parent mode-line-minor-mode-keymap
+                      "<mode-line> <down-mouse-1>" menu
+                      "<mode-line> <mouse-2>" #'describe-mode)))
+              `(:propertize ,(if (char-displayable-p ?…) " …" " ...")
+                            mouse-face mode-line-highlight
+                            help-echo "Hidden minor modes\n\
+mouse-1: Display hidden minor modes\n\
+mouse-2: Show help for enabled minor modes\n\
+mouse-3: Toggle minor modes"
+                            local-map ,keymap)))

Still we need to split 'minor-mode-alist' and do some other work, but my
profiling showed that there was little impact to the performance.

Pengji