From 37049ee78c4576d340781179317e6cbaaf73b6c3 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 29 Dec 2020 03:10:00 +0100 Subject: [PATCH] Allow the flymake mode line indicator to be customized * doc/misc/flymake.texi (Customizable variables): Mention it. * lisp/progmodes/flymake.el (flymake-mode-line-indicator-format): New variable (bug#33740). (flymake--mode-line-format): Use it. --- doc/misc/flymake.texi | 3 + etc/NEWS | 5 + lisp/progmodes/flymake.el | 197 +++++++++++++++++++------------------- 3 files changed, 109 insertions(+), 96 deletions(-) diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 8f2954bdf4f..b8744f0323f 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -213,6 +213,9 @@ This section summarizes customization variables used for the configuration of the Flymake user interface. @vtable @code +@item flymake-mode-line-indicator-format +Format to use for the Flymake mode line indicator. + @item flymake-no-changes-timeout If any changes are made to the buffer, syntax check is automatically started after this many seconds, unless the user makes another change, diff --git a/etc/NEWS b/etc/NEWS index cd4006170d2..6348c1d8eef 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1732,6 +1732,11 @@ height of lines or width of chars. When non-nil, use a new xwidget webkit session after bookmark jump. Otherwise, it will use 'xwidget-webkit-last-session'. +** Flymake mode + ++++ +*** New user option 'flymake-mode-line-indicator-format'. + ** Flyspell mode +++ diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 40bb90d0f15..e78d5d32fff 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -1190,6 +1190,16 @@ default) no filter is applied." (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." + :version "28.1" + :type 'string) (defun flymake--mode-line-format () "Produce a pretty minor mode indicator." @@ -1207,102 +1217,97 @@ default) no filter is applied." 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) - '("?" nil "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)) - (type type)) - (define-key map (vector 'mode-line - mouse-wheel-down-event) - (lambda (event) - (interactive "e") - (with-selected-window (posn-window (event-start event)) - (flymake-goto-prev-error 1 (list type) t)))) - (define-key map (vector 'mode-line - mouse-wheel-up-event) - (lambda (event) - (interactive "e") - (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" - (propertize (format "%d" - (length diags)) - 'face face) - (propertize (format "%s" type) - '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 "]"))))))) + (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 (pcase-let ((`(,ind ,face ,explain) + (cond ((null known) + '("?" nil "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))))) + (if (not 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) + (lambda (event) + (interactive "e") + (with-selected-window (posn-window (event-start event)) + (flymake-goto-prev-error 1 (list type) t)))) + (define-key map (vector 'mode-line + mouse-wheel-up-event) + (lambda (event) + (interactive "e") + (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" + (propertize (format "%d" + (length diags)) + 'face face) + (propertize (format "%s" type) + 'face face)) + (format "%s/%s: previous/next of this type" + mouse-wheel-down-event + mouse-wheel-up-event)))))) + nil t))) ;;; Diagnostics buffer -- 2.39.5