unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: "João Távora" <joaotavora@gmail.com>
Cc: 33740@debbugs.gnu.org, Andrii Kolomoiets <andreyk.mad@gmail.com>
Subject: bug#33740: [PATCH] Customizable flymake mode-line indicator
Date: Tue, 17 Sep 2019 00:22:08 +0200	[thread overview]
Message-ID: <87h85bq3u7.fsf@gnus.org> (raw)
In-Reply-To: <87bm4wjhgy.fsf@gmail.com> ("João Távora"'s message of "Fri, 04 Jan 2019 20:27:57 +0000")

João Távora <joaotavora@gmail.com> writes:

> Looks good, though I would prefer if the defcustom was a format-string
> where %s would be substituted by the error counts.  That way you could
> even get rid of the braces or use something else.

Below is a proof-of-this-concept-not-working when done via the normal
format-spec machinery.  :-)

I thought we could just put text properties on strings we feed to the
mode-line machinery, but it seems like these don't survive?  Do I
remember vaguely there being a long-running bug report about that
problem?  I thought it had been fixed by now.

Anybody remember?

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 6d47c8bb17..00c941ca5d 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1166,6 +1166,15 @@ flymake--mode-line-format
 
 (put 'flymake--mode-line-format 'risky-local-variable t)
 
+(defcustom flymake-mode-line-indicator-format " Flymake%s[%e %w %n]"
+  "Format to use for the Flymake mode line indicator.
+The following format characters can be used:
+
+%s: The status.
+%e: The number of errors.
+%w: The number of warnings.
+%n: The number of notes."
+  :type 'string)
 
 (defun flymake--mode-line-format ()
   "Produce a pretty minor mode indicator."
@@ -1183,71 +1192,74 @@ flymake--mode-line-format
                                       diags-by-type)))
                      (flymake--backend-state-diags state)))
              flymake--backend-state)
-    `((:propertize " Flymake"
-                   mouse-face mode-line-highlight
-                   help-echo
-                   ,(concat (format "%s known backends\n" (length known))
-                            (format "%s running\n" (length running))
-                            (format "%s disabled\n" (length disabled))
-                            "mouse-1: Display minor mode menu\n"
-                            "mouse-2: Show help for minor mode")
-                   keymap
-                   ,(let ((map (make-sparse-keymap)))
-                      (define-key map [mode-line down-mouse-1]
-                        flymake-menu)
-                      (define-key map [mode-line mouse-2]
-                        (lambda ()
-                          (interactive)
-                          (describe-function 'flymake-mode)))
-                      map))
-      ,@(pcase-let ((`(,ind ,face ,explain)
-                     (cond ((null known)
-                            '("?" mode-line "No known backends"))
-                           (some-waiting
-                            `("Wait" compilation-mode-line-run
-                              ,(format "Waiting for %s running backend(s)"
-                                       (length some-waiting))))
-                           (all-disabled
-                            '("!" compilation-mode-line-run
-                              "All backends disabled"))
-                           (t
-                            '(nil nil nil)))))
-          (when ind
-            `((":"
-               (:propertize ,ind
-                            face ,face
-                            help-echo ,explain
-                            keymap
-                            ,(let ((map (make-sparse-keymap)))
-                               (define-key map [mode-line mouse-1]
-                                 'flymake-switch-to-log-buffer)
-                               map))))))
-      ,@(unless (or all-disabled
-                    (null known))
-          (cl-loop
-           with types = (hash-table-keys diags-by-type)
-           with _augmented = (cl-loop for extra in '(:error :warning)
-                                      do (cl-pushnew extra types
-                                                     :key #'flymake--severity))
-           for type in (cl-sort types #'> :key #'flymake--severity)
-           for diags = (gethash type diags-by-type)
-           for face = (flymake--lookup-type-property type
-                                                     'mode-line-face
-                                                     'compilation-error)
-           when (or diags
-                    (cond ((eq flymake-suppress-zero-counters t)
-                           nil)
-                          (flymake-suppress-zero-counters
-                           (>= (flymake--severity type)
-                               (warning-numeric-level
-                                flymake-suppress-zero-counters)))
-                          (t t)))
-           collect `(:propertize
-                     ,(format "%d" (length diags))
-                     face ,face
-                     mouse-face mode-line-highlight
-                     keymap
-                     ,(let ((map (make-sparse-keymap))
+    (format-spec
+     (propertize flymake-mode-line-indicator-format
+                 'mouse-face 'mode-line-highlight
+                 'help-echo
+                 (concat (format "%s known backends\n" (length known))
+                         (format "%s running\n" (length running))
+                         (format "%s disabled\n" (length disabled))
+                         "mouse-1: Display minor mode menu\n"
+                         "mouse-2: Show help for minor mode")
+                 'keymap
+                 (let ((map (make-sparse-keymap)))
+                   (define-key map [mode-line down-mouse-1]
+                     flymake-menu)
+                   (define-key map [mode-line mouse-2]
+                     (lambda ()
+                       (interactive)
+                       (describe-function 'flymake-mode)))
+                   map))
+     (cons
+      (cons ?s (cl-destructuring-bind
+                   (ind face explain)
+                   (cond ((null known)
+                          '("?" mode-line "No known backends"))
+                         (some-waiting
+                          `("Wait" compilation-mode-line-run
+                            ,(format "Waiting for %s running backend(s)"
+                                     (length some-waiting))))
+                         (all-disabled
+                          '("!" compilation-mode-line-run
+                            "All backends disabled"))
+                         (t
+                          '(nil nil nil)))
+                 (when ind
+                   (concat
+                    ":"
+                    (propertize ind
+                                'face face
+                                'help-echo explain
+                                'keymap
+                                (let ((map (make-sparse-keymap)))
+                                  (define-key map [mode-line mouse-1]
+                                    'flymake-switch-to-log-buffer)
+                                  map))))))
+      (cl-loop
+       with types = (hash-table-keys diags-by-type)
+       with _augmented = (cl-loop for extra in '(:error :warning)
+                                  do (cl-pushnew extra types
+                                                 :key #'flymake--severity))
+       for type in (cl-sort types #'> :key #'flymake--severity)
+       for diags = (gethash type diags-by-type)
+       for face = (flymake--lookup-type-property type
+                                                 'mode-line-face
+                                                 'compilation-error)
+       when (or diags
+                (cond ((eq flymake-suppress-zero-counters t)
+                       nil)
+                      (flymake-suppress-zero-counters
+                       (>= (flymake--severity type)
+                           (warning-numeric-level
+                            flymake-suppress-zero-counters)))
+                      (t t)))
+       collect (cons (elt (format "%s" type) 1)
+                     (propertize
+                      (format "%d" (length diags))
+                      'face face
+                      'mouse-face 'mode-line-highlight
+                      'keymap
+                      (let ((map (make-sparse-keymap))
                             (type type))
                         (define-key map (vector 'mode-line
                                                 mouse-wheel-down-event)
@@ -1262,8 +1274,8 @@ flymake--mode-line-format
                             (with-selected-window (posn-window (event-start event))
                               (flymake-goto-next-error 1 (list type) t))))
                         map)
-                     help-echo
-                     ,(concat (format "%s diagnostics of type %s\n"
+                      'help-echo
+                      (concat (format "%s diagnostics of type %s\n"
                                       (propertize (format "%d"
                                                           (length diags))
                                                   'face face)
@@ -1271,14 +1283,7 @@ flymake--mode-line-format
                                                   'face face))
                               (format "%s/%s: previous/next of this type"
                                       mouse-wheel-down-event
-                                      mouse-wheel-up-event)))
-           into forms
-           finally return
-           `((:propertize "[")
-             ,@(cl-loop for (a . rest) on forms by #'cdr
-                        collect a when rest collect
-                        '(:propertize " "))
-             (:propertize "]")))))))
+                                      mouse-wheel-up-event)))))))))
 
 ;;; Diagnostics buffer
 

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





  parent reply	other threads:[~2019-09-16 22:22 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-14  9:19 bug#33740: [PATCH] Customizable flymake mode-line indicator Andrii Kolomoiets
2019-01-04 20:27 ` João Távora
2019-06-22 14:15   ` Štěpán Němec
2019-09-16 22:22   ` Lars Ingebrigtsen [this message]
2019-09-17  6:09     ` Eli Zaretskii
2019-09-17 11:57       ` Lars Ingebrigtsen
2019-09-17 12:13         ` Eli Zaretskii
2019-09-17 12:22           ` Lars Ingebrigtsen
2019-09-17 12:44             ` Eli Zaretskii
2019-09-18 13:38               ` Lars Ingebrigtsen
2019-09-18 14:09                 ` Lars Ingebrigtsen
2019-09-19 15:28                   ` Lars Ingebrigtsen
2019-09-19 15:55                     ` Lars Ingebrigtsen
2019-09-19 16:23                       ` Lars Ingebrigtsen
2019-09-19 17:26                         ` Eli Zaretskii
2019-09-20 12:32                           ` Lars Ingebrigtsen
2019-09-20 13:06                             ` Eli Zaretskii
2019-09-20 13:13                               ` Lars Ingebrigtsen
2019-09-17 14:07     ` João Távora
2019-09-18 13:40       ` Lars Ingebrigtsen
2019-09-18 13:59         ` João Távora
2019-09-19 15:39           ` Lars Ingebrigtsen
2019-09-20 13:07             ` João Távora
2019-09-21  7:54               ` Lars Ingebrigtsen
2019-09-22 20:55                 ` Juri Linkov
2019-09-23  9:18                   ` João Távora
2019-09-23 18:10                     ` Lars Ingebrigtsen
2019-09-23  9:25                 ` João Távora
2019-09-23 18:11                   ` Lars Ingebrigtsen
2019-09-18 14:02         ` Noam Postavsky
2020-12-29  2:12   ` Lars Ingebrigtsen
2020-12-29  2:19     ` Lars Ingebrigtsen
2020-12-29 13:52       ` João Távora
2020-12-29 14:14         ` Lars Ingebrigtsen
2020-12-29 14:18       ` João Távora
2020-12-29 14:22         ` Lars Ingebrigtsen
2020-12-29 15:13           ` João Távora
2020-12-30  3:22             ` Lars Ingebrigtsen
2020-12-30  9:28               ` João Távora
2020-12-30 20:16                 ` Eli Zaretskii
2020-12-30 21:13                   ` João Távora
2020-12-31 14:05                     ` João Távora
2021-01-01 10:56                       ` Lars Ingebrigtsen
2021-01-02 11:27                         ` João Távora

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=87h85bq3u7.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=33740@debbugs.gnu.org \
    --cc=andreyk.mad@gmail.com \
    --cc=joaotavora@gmail.com \
    /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).