TheBB / spaceline

Powerline theme from Spacemacs
GNU General Public License v3.0
539 stars 60 forks source link

Support segments for flymake #181

Open jabranham opened 6 years ago

jabranham commented 6 years ago

In Emacs 26, flymake got a major rewrite and now is about on-par with flycheck, feature wise. It would be nice if spaceline could provide segements showing flymake errors/warnings/notes similar to those it provides for flycheck errors/warnings/info.

deb0ch commented 6 years ago

Hi there, I never heard of Flymake before (or did I and then forgot ?) and I am not currenly working on any project where I would need it.

A PR for supporting it would be gladly welcomed though, if you or anyone else need help for writing it don't hesitate to ask questions 😸

lockie commented 5 years ago

For anyone interested, I've ended up with the following code in init.el to display flymake diagnostics count in spaceline:

  (defmacro my/spaceline-flymake-lighter (severity)
    `(let ((count
            (length
             (seq-filter
              (lambda (diag)
                (= ,severity
                   (flymake--severity (flymake-diagnostic-type diag))))
              (flymake-diagnostics)))))
       (if (not (zerop count)) (format spaceline-flycheck-bullet count))))
  (dolist (state '(error warning note))
    (let ((segment-name (intern (format "flymake-%S" state)))
          (face (intern (format "spaceline-flycheck-%S" state)))
          (severity (flymake--severity (intern (format ":%S" state)))))
      (eval
       `(spaceline-define-segment ,segment-name
          (when (bound-and-true-p flymake-mode)
            (let ((lighter (my/spaceline-flymake-lighter ,severity)))
              (when lighter (powerline-raw (s-trim lighter) ',face))))))))

It's kinda copycat of flycheck segment in spaceline code and it's overall raw and hackish, but it seems to work. I don't mind if someone gets this to proper PR :)