Skip to content

Instantly share code, notes, and snippets.

@mooz
Created January 30, 2012 15:59
Show Gist options
  • Save mooz/1705123 to your computer and use it in GitHub Desktop.
Save mooz/1705123 to your computer and use it in GitHub Desktop.
Flymake Highlight Mode Line
;; ============================================================ ;;
;; Flymake Highlight Mode Line {{{
;; ============================================================ ;;
(defvar flypaint:error-face
'(:foreground "white" :background "red"))
(defvar flypaint:warning-face
'(:foreground "white" :background "orange red"))
(defvar flypaint:normal-face
'(:foreground "white" :background "forest green"))
(defun flypaint:get-mode-line-face (error-count warning-count info-count)
(cond
((> error-count 0)
flypaint:error-face)
((> warning-count 0)
flypaint:warning-face)
(t
flypaint:normal-face)))
(defun flypaint:propertize-mode-line (mode-line e-w)
(if (and e-w
(string-match "\\([0-9]\\)/\\([0-9]\\)/\\([0-9]\\)" e-w))
;; propertize
(let ((error-count (string-to-number
(match-string 1 e-w)))
(warning-count (string-to-number
(match-string 2 e-w)))
(info-count (string-to-number
(match-string 3 e-w))))
(propertize mode-line
'face
(flypaint:get-mode-line-face error-count
warning-count
info-count)))
;; otherwise, return normal string
(propertize mode-line 'face flypaint:normal-face)))
(defun flypaint:set-and-update-mode-line (mode-line)
(setcar (cdr (assq 'flymake-mode minor-mode-alist)) mode-line)
(force-mode-line-update))
;; hook
(defadvice flymake-report-status (around flypaint:update-mode-line-advice activate)
(flypaint:flymake-report-status e-w status))
(defun flypaint:flymake-report-status (e-w &optional status)
"Show status in mode line."
(when e-w
(setq flymake-mode-line-e-w e-w))
(when status
(setq flymake-mode-line-status status))
(let* ((base-line (concat "Flymake"
(if (> (length flymake-mode-line-e-w) 0)
(concat ":" flymake-mode-line-e-w)
;; otherwise
"")
flymake-mode-line-status))
(colored-base-line (flypaint:propertize-mode-line
(concat "[" base-line "]")
flymake-mode-line-e-w)))
(flypaint:set-and-update-mode-line
(list " " colored-base-line))))
;; ============================================================ ;;
;; }}} Flymake Highlight Mode Line
;; ============================================================ ;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment