Skip to content

Commit ccaeb6b

Browse files
committed
Update flymake lighter
1 parent 559db66 commit ccaeb6b

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

jcs-modeline.el

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868

6969
(defcustom jcs-modeline-checker-colors '((error . "#FB4933")
7070
(warning . "#FABD2F")
71-
(info . "#83A598"))
71+
(info . "#83A598")
72+
(note . "#83A598"))
7273
"Alist of colors for checkers."
7374
:type 'list
7475
:group 'jcs-modeline)
@@ -273,6 +274,19 @@
273274
;;
274275
;;; Flymake
275276

277+
(defun jcs-modeline--flymake-lighter (diags-by-type state running)
278+
"Return flycheck lighter by given STATE.
279+
280+
If argument RUNNING is non-nil, we turn lighter into question mark."
281+
(let* ((c-state (cl-case state
282+
(error :error)
283+
(warning :warning)
284+
(note :note)))
285+
(counts (length (gethash c-state diags-by-type)))
286+
(color (cdr (assoc state jcs-modeline-checker-colors)))
287+
(lighter (format "%s" (if running "?" counts))))
288+
(propertize lighter 'face `(:foreground ,color))))
289+
276290
(defun jcs-modeline--render-flymake ()
277291
"Render for flymake."
278292
(when (bound-and-true-p flymake-mode)
@@ -291,42 +305,43 @@
291305
(flymake--state-diags state)))
292306
flymake--state)
293307
(concat
294-
(cond
295-
(some-waiting (propertize "" 'face `(:foreground "#FABD2F")))
296-
((null known) (propertize "" 'face `(:foreground "#FABD2F")))
297-
(all-disabled (propertize "" 'face `(:foreground "#FB4933")))
298-
(t
299-
(apply #'concat
300-
(mapcar (lambda (args)
301-
(apply (lambda (num str face)
302-
(propertize (format str num) 'face face))
303-
args))
304-
`((,(length (gethash :error diags-by-type)) "•%d " error)
305-
(,(length (gethash :warning diags-by-type)) "•%d " warning)
306-
(,(length (gethash :note diags-by-type)) "•%d" success))))))
308+
(let* ((states '(error warning note))
309+
(last (car (last states)))
310+
result)
311+
(dolist (state states)
312+
(when-let ((lighter (jcs-modeline--flymake-lighter
313+
diags-by-type state
314+
(or some-waiting (null known) all-disabled))))
315+
(setq result (concat result lighter
316+
(unless (equal state last) "/")))))
317+
result)
307318
" "))))
308319

309320
;;
310321
;;; Flycheck
311322

312-
(defun jcs-modeline--flycheck-lighter (state)
313-
"Return flycheck information for the given error type STATE."
323+
(defun jcs-modeline--flycheck-lighter (state running)
324+
"Return flycheck lighter by given STATE.
325+
326+
If argument RUNNING is non-nil, we turn lighter into question mark."
314327
(let* ((counts (flycheck-count-errors flycheck-current-errors))
315328
(err (or (cdr (assq state counts)) "0"))
316-
(running (eq 'running flycheck-last-status-change)))
317-
(format "%s" (if running "?" err))))
329+
(color (cdr (assoc state jcs-modeline-checker-colors)))
330+
(lighter (format "%s" (if running "?" err))))
331+
(propertize lighter 'face `(:foreground ,color))))
318332

319333
(defun jcs-modeline--render-flycheck ()
320334
"Render for flycheck."
321335
(when (bound-and-true-p flycheck-mode)
322336
(concat
323-
(let ((last (caar (last jcs-modeline-checker-colors)))
324-
result)
325-
(dolist (state jcs-modeline-checker-colors)
326-
(let* ((lighter (jcs-modeline--flycheck-lighter (car state)))
327-
(lighter (propertize lighter 'face `(:foreground ,(cdr state)))))
337+
(let* ((states '(error warning info))
338+
(last (car (last states)))
339+
(running (eq 'running flycheck-last-status-change))
340+
result)
341+
(dolist (state states)
342+
(when-let ((lighter (jcs-modeline--flycheck-lighter state running)))
328343
(setq result (concat result lighter
329-
(unless (equal (car state) last) "/")))))
344+
(unless (equal state last) "/")))))
330345
result)
331346
" ")))
332347

0 commit comments

Comments
 (0)