Skip to content

Instantly share code, notes, and snippets.

@casouri
Last active August 10, 2021 12:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save casouri/919088eb45114086e69a147be92a8d89 to your computer and use it in GitHub Desktop.
Save casouri/919088eb45114086e69a147be92a8d89 to your computer and use it in GitHub Desktop.
simple custom flymake modeline

Modified from flymake--mode-line-format. I only used diags-by-type, you can do stuff with known, running, disabled, etc.

I use unicode for each type of diagnose, flymake-error/warning/note-bitmap would be intersting to use, too.

Don’t read source of flymake--mode-line-format, your sanity will drop.

还可以用汉字代替unicode符号,比如“死”,“警”,“意”对应“error”,“warning”和“note”。 用汉字的话建议在汉字和数字之间加半个空格: M-x insert-char RET thin space RET

(defvar moon-flymake-mode-line-map (let ((map (make-sparse-keymap)))
(define-key map (vector 'mode-line
mouse-wheel-up-event) #'flymake-goto-prev-error)
(define-key map (vector 'mode-line
mouse-wheel-down-event) #'flymake-goto-next-error)
map))
(defun moon-flymake-mode-line ()
(require 'subr-x)
(let* ((known (hash-table-keys flymake--backend-state))
(running (flymake-running-backends))
(disabled (flymake-disabled-backends))
(reported (flymake-reporting-backends))
(diags-by-type (make-hash-table))
(all-disabled (and disabled (null running)))
(some-waiting (cl-set-difference running reported)))
(maphash (lambda (_b state)
(mapc (lambda (diag)
(push diag
(gethash (flymake--diag-type diag)
diags-by-type)))
(flymake--backend-state-diags state)))
flymake--backend-state)
(apply #'concat
(mapcar (lambda (args)
(apply (lambda (num str face)
(propertize
(format str num) 'face face 'keymap moon-flymake-mode-line-map))
args))
`((,(length (gethash :error diags-by-type)) "死 %d " error)
(,(length (gethash :warning diags-by-type)) "警 %d " warning)
(,(length (gethash :note diags-by-type)) "意 %d" success))))))
(defun moon-flymake-mode-line ()
(let* ((known (hash-table-keys flymake--backend-state))
(running (flymake-running-backends))
(disabled (flymake-disabled-backends))
(reported (flymake-reporting-backends))
(diags-by-type (make-hash-table))
(all-disabled (and disabled (null running)))
(some-waiting (cl-set-difference running reported)))
(maphash (lambda (_b state)
(mapc (lambda (diag)
(push diag
(gethash (flymake--diag-type diag)
diags-by-type)))
(flymake--backend-state-diags state)))
flymake--backend-state)
(apply #'concat
(mapcar (lambda (args)
(apply (lambda (num str face)
(propertize
(format str num) 'face face))
args))
`((,(length (gethash :error diags-by-type)) "☠%d " error)
(,(length (gethash :warning diags-by-type)) "⚠%d " warning)
(,(length (gethash :note diags-by-type)) "𝌆%d" success))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment