This weekend I found myself doing some heavy-weight refactoring in CIDER. This
is the kind of situation where Flycheck helps a lot, but I still needed it to do
a bit more. Every time I made a significant change to a file, I had to visit 3
or 5 other files and trigger Flycheck on each one of them. It wasn’t long before
I decide there had to be a way to just Flycheck a whole directory.
Enter endless/flycheck-dir. This command runs Flycheck on all files in the
current directory and reports the result to the *Compile-Log* buffer. You can
then navigate through all issues for the entire directory by TAB-ing through
the buffer or using next-error.
(define-keyflycheck-command-map"d"#'endless/flycheck-dir)(defunendless/flycheck-dir(dir)"Run flycheck for each file in current directory.
Results are reported in a compilation buffer."(interactive"DDirectory: ")(displaying-byte-compile-warnings(let((pnil))(with-current-buffer(get-buffer-createbyte-compile-log-buffer)(setqdefault-directorydir)(unless(eqmajor-mode'compilation-mode)(compilation-mode))(goto-char(point-max))(let((inhibit-read-onlyt))(insert"\n\xc\n\n"))(setqp(point)))(dolist(file(directory-files"./"nil"\\`[^\\.].*\\'"))(endless/-flycheck-filefile))(with-selected-window(display-bufferbyte-compile-log-buffer)(goto-charp)(recenter1)))))(defunendless/-report-error(fmt&restargs)"Print an error on `byte-compile-log-buffer'."(let((inhibit-read-onlyt)(fill-prefix" "))(with-current-bufferbyte-compile-log-buffer(let((l(point)))(insert"\n"(apply#'formatfmtargs))(fill-region(1+l)(point))))))(defunendless/-flycheck-file(file)"Check FILE and report to `byte-compile-log-buffer'."(let((was-visited(find-buffer-visitingfile)))(with-current-buffer(orwas-visited(progn(find-filefile)(current-buffer)))(when(ignore-errors(flycheck-buffer))(while(flycheck-running-p)(accept-process-outputnil0.1))(pcaseflycheck-last-status-change((or`errored`suspicious)(endless/-report-error"%s: Something wrong here!"(file-name-nondirectory(buffer-file-name))))(`finished(dolist(eflycheck-current-errors)(endless/-report-error"%s:%s:%s:%s: %s"(file-name-nondirectory(buffer-file-name))(flycheck-error-linee)(flycheck-error-columne)(flycheck-error-levele)(flycheck-error-messagee))))))(ifwas-visited(bury-bufferwas-visited)(kill-buffer(current-buffer))))))
Flycheck a directory and report the results
21 Sep 2015, by Artur Malabarba.This weekend I found myself doing some heavy-weight refactoring in CIDER. This is the kind of situation where Flycheck helps a lot, but I still needed it to do a bit more. Every time I made a significant change to a file, I had to visit 3 or 5 other files and trigger Flycheck on each one of them. It wasn’t long before I decide there had to be a way to just Flycheck a whole directory.
Enter
endless/flycheck-dir
. This command runs Flycheck on all files in the current directory and reports the result to the*Compile-Log*
buffer. You can then navigate through all issues for the entire directory by TAB-ing through the buffer or usingnext-error
.Tags: programming, flycheck, init.el, emacs,
Predicting the future with M-n »
« Improving page (section) navigation
Related Posts
Turbo up your Ruby console in Emacs in programming
A few paredit keys that take over the world in programming
Restarting the compilation buffer in comint-mode in programming
Content © 2019, All rights reserved. Icons under CC3.0.