conf-flymake.el 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ;;; Code:
  2. (require 'flymake)
  3. (defvar distopico:flymake-mode-line-error-counter
  4. `(:eval (distopico:flymake-maybe-show-counter :error t)))
  5. (defvar distopico:flymake-mode-line-warning-counter
  6. `(:eval (distopico:flymake-maybe-show-counter :warning t)))
  7. (defvar distopico:flymake-mode-line-note-counter
  8. `(:eval (distopico:flymake-maybe-show-counter :note t)))
  9. (defvar distopico:flymake-current-counters '())
  10. (setq flymake-no-changes-timeout 2 ;; seconds
  11. flymake-fringe-indicator-position 'right-fringe
  12. flymake-mode-line-counter-format
  13. '(""
  14. distopico:flymake-mode-line-error-counter
  15. distopico:flymake-mode-line-warning-counter
  16. distopico:flymake-mode-line-note-counter)
  17. flymake-mode-line-format
  18. '("["
  19. flymake-mode-line-title
  20. flymake-mode-line-counters
  21. "]"
  22. flymake-mode-line-exception))
  23. (define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
  24. (define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)
  25. (define-key flymake-mode-map (kbd "C-c ! n") 'flymake-goto-next-error)
  26. (define-key flymake-mode-map (kbd "C-c ! p") 'flymake-goto-prev-error)
  27. (define-key flymake-mode-map (kbd "C-c ! d") 'flymake-show-buffer-diagnostics)
  28. (define-key flymake-mode-map (kbd "C-c ! a") 'flymake-show-project-diagnostics)
  29. ;; Functions
  30. (defun distopico:flymake-maybe-show-counter (type &optional space-l)
  31. "Filter if the `flymake' mode-line counter should be shown.
  32. Only display the `TYPE' if have a number grater than 0 and
  33. remove the space `SPACE-L' left if it is non-nil."
  34. (let* ((mline (flymake--mode-line-counter type t))
  35. (counter (nth 1 mline))
  36. (count (plist-get counter :propertize))
  37. (countn (string-to-number (or count "")))
  38. (has-counter (> countn 0))
  39. (current-counters distopico:flymake-current-counters))
  40. (if has-counter
  41. (add-to-list 'distopico:flymake-current-counters type)
  42. (setq distopico:flymake-current-counters (remove type current-counters)))
  43. (when has-counter
  44. (cond (space-l (push '(:propertize " ") mline))
  45. (t mline)))))
  46. (defun distopico:flymake-enable-hook ()
  47. "Enable and setup `flymake' minor mode."
  48. (flymake-mode +1))
  49. (put 'distopico:flymake-mode-line-error-counter 'risky-local-variable t)
  50. (put 'distopico:flymake-mode-line-warning-counter 'risky-local-variable t)
  51. (put 'distopico:flymake-mode-line-note-counter 'risky-local-variable t)
  52. (put 'distopico:flymake-current-counters 'risky-local-variable t)
  53. ;; hooks
  54. (add-hook 'prog-mode-hook #'distopico:flymake-enable-hook)
  55. (provide 'conf-flymake)
  56. ;;; conf-flymake.el ends here