Skip to content

Instantly share code, notes, and snippets.

@CIAvash
Last active May 16, 2022 06:10
Show Gist options
  • Save CIAvash/2ebe4d14f8104c911a4762db9dd42d95 to your computer and use it in GitHub Desktop.
Save CIAvash/2ebe4d14f8104c911a4762db9dd42d95 to your computer and use it in GitHub Desktop.
Flymake module for awesome-tray package
(defface my/awesome-tray-flymake-error
'((t (:foreground "#FF564A")))
"Flymake error face."
:group 'awesome-tray)
(defface my/awesome-tray-flymake-warning
'((t (:foreground "#FF9800")))
"Flymake warning face."
:group 'awesome-tray)
(defface my/awesome-tray-flymake-note
'((t (:foreground "#2196F3")))
"Flymake note face."
:group 'awesome-tray)
(defun my/awesome-tray-flymake-info ()
"A module for showing Flymake state."
;; Parts of the code are from doom-modeline package
(let* ((known (hash-table-keys flymake--state))
(running (flymake-running-backends))
(disabled (flymake-disabled-backends))
(reported (flymake-reporting-backends))
(disabledp (and disabled (null running)))
(waiting (cl-set-difference running reported)))
(when-let
((flymake-state
(cond
(waiting "⏳")
((null known) "❔")
(disabledp "❕")
(t (let ((.error 0)
(.warning 0)
(.note 0))
(cl-loop
with warning-level = (warning-numeric-level :warning)
with note-level = (warning-numeric-level :debug)
for state being the hash-values of flymake--state
do (cl-loop
with diags = (flymake--state-diags state)
for diag in diags do
(let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity
(warning-numeric-level :error))))
(cond ((> severity warning-level) (cl-incf .error))
((> severity note-level) (cl-incf .warning))
(t (cl-incf .note))))))
(let ((num (+ .error .warning .note)))
(if (> num 0)
(string-clean-whitespace
(string-join
(list
(when (> .note 0)
(concat "🔵:" (propertize (number-to-string .note) 'face 'my/awesome-tray-flymake-note)))
(when (> .warning 0)
(concat "🟠:" (propertize (number-to-string .warning) 'face 'my/awesome-tray-flymake-warning)))
(when (> .error 0)
(concat "🔴:" (propertize (number-to-string .error) 'face 'my/awesome-tray-flymake-error))))
" "))
"🟢")))))))
flymake-state)))
(use-package awesome-tray
:straight (awesome-tray :host github :repo "manateelazycat/awesome-tray")
:hook (after-init . awesome-tray-mode)
:config
(add-to-list 'awesome-tray-module-alist
'("flymake" . (my/awesome-tray-flymake-info nil))))
@manateelazycat
Copy link

Hey,

Can you send me a PR that add this module in master branch?

Thanks for your work!

@CIAvash
Copy link
Author

CIAvash commented May 16, 2022

@manateelazycat done. I originally didn't make a PR, because I thought people might want more customization options.

@manateelazycat
Copy link

Thanks man, awesome work!

@CIAvash
Copy link
Author

CIAvash commented May 16, 2022

@manateelazycat Thank you for creating awesome-tray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment