forked from emacs-exordium/exordium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
;;; batch-flycheck.el --- Run flycheck on command line arguments -*- lexical-binding: t -*- | ||
|
||
;;; Commentary: | ||
;; This is a transformation of batch-checkdoc.el to handle support `emacs-lisp' | ||
;; checker, with `flycheck-checker-shell-command'. | ||
|
||
;;; Code: | ||
|
||
(require 'flycheck) | ||
(require 'rx) | ||
(require 'cl-lib) | ||
|
||
(defun exordium--relevant-flycheck-warnings-and-errors (buffer source) | ||
"Find relevant flycheck warning and errors in BUFFER, in reverse order. | ||
SOURCE is the source file used to compile with | ||
`flycheck-checker-shell-command'." | ||
(with-current-buffer buffer | ||
(goto-char (point-min)) | ||
(let (matches | ||
(not-errors | ||
(list | ||
(rx "the function ‘exordium--require-load’ might not be defined at runtime.")))) | ||
(when-let* (((re-search-forward (rx-to-string `(seq " -- " ,source line-end)) | ||
nil t)) | ||
(pattern (rx-to-string | ||
`(group line-start ,(file-name-nondirectory source) | ||
(optional ":" (one-or-more digit) | ||
":" (optional (one-or-more digit))) | ||
": " (or "Warning" "Error") ": " | ||
(one-or-more not-newline) line-end)))) | ||
(while (re-search-forward pattern nil t) | ||
(push (buffer-substring-no-properties (match-beginning 1) (match-end 1)) | ||
matches))) | ||
(cl-remove-if | ||
(lambda (match) | ||
(cl-some (lambda (pat) | ||
(string-match pat match)) | ||
not-errors)) | ||
matches)))) | ||
|
||
(defun batch-flycheck () | ||
"Run `flycheck-checker-shell-command' on the files remaining on the command line." | ||
(let (errors | ||
(number-of-errors 0)) | ||
(unwind-protect | ||
(let | ||
((jka-compr-inhibit t)) | ||
(when | ||
(equal | ||
(car command-line-args-left) | ||
"--") | ||
(setq command-line-args-left | ||
(cdr command-line-args-left))) | ||
(unless | ||
(require 'elisp-mode nil 'no-error) | ||
(require 'lisp-mode)) | ||
(require 'cl-lib) | ||
(while command-line-args-left | ||
(let | ||
((source | ||
(car command-line-args-left)) | ||
(buffer-name "*exordium flycheck compile*") | ||
(process-default-directory default-directory)) | ||
(with-temp-buffer | ||
(insert-file-contents source 'visit) | ||
(setq buffer-file-name source) | ||
(setq default-directory process-default-directory) | ||
(with-demoted-errors "Error in flycheck: %S" | ||
(delay-mode-hooks | ||
(emacs-lisp-mode)) | ||
(setq delayed-mode-hooks nil) | ||
(let ((comp-buf | ||
(compilation-start | ||
(flycheck-checker-shell-command 'emacs-lisp) | ||
nil (lambda (&rest _) buffer-name)))) | ||
(when-let* ((comp-proc (get-buffer-process comp-buf))) | ||
(while (process-live-p comp-proc) | ||
(sleep-for 0 1))) ;; 1ms | ||
(with-current-buffer comp-buf | ||
(princ | ||
(buffer-substring-no-properties | ||
(point-min) | ||
(point-max))) | ||
(princ "\n") | ||
(dolist (err (exordium--relevant-flycheck-warnings-and-errors | ||
comp-buf source)) | ||
(push err errors) | ||
(cl-incf number-of-errors)) | ||
(kill-buffer)))))) | ||
(setq command-line-args-left (cdr command-line-args-left)))) | ||
(setq command-line-args-left nil) | ||
(when (< 0 number-of-errors) | ||
(message "\n===Errors and Warnings===\n%s\n" | ||
(mapconcat #'identity errors "\n")) | ||
(let ((msg (format "There are %s flycheck errors!" number-of-errors))) | ||
(if (version< "30" emacs-version) | ||
(message msg) | ||
(error msg))))))) | ||
|
||
(provide 'batch-flycheck) | ||
|
||
;;; batch-flycheck.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
set -e | ||
|
||
EMACS_DIR="$(cd "${GITHUB_WORKSPACE:-${HOME}}/${1:-.emacs.d}" && pwd -P)" | ||
EMACS=${EMACS:=emacs} | ||
|
||
for pattern in "modules/*.el" "init.el" "themes/*.el" ".ci/*.el"; do | ||
echo "===Flycheck: ${pattern}===" | ||
|
||
# Use find to find file names such that globs are expanded while prevent | ||
# splitting paths on spaces | ||
mapfile -t files <<< \ | ||
"$(find "${EMACS_DIR}" -type f -path "${EMACS_DIR}/${pattern}")" | ||
${EMACS} -Q --batch \ | ||
--eval ' | ||
(progn | ||
(setq debug-on-error t | ||
eval-expression-print-length 100 | ||
edebug-print-length 500 | ||
user-emacs-directory "'"${EMACS_DIR}"'/") | ||
(load-file "'"${EMACS_DIR}"'/init.el") | ||
(load-file "'"${EMACS_DIR}"'/.ci/batch-flycheck.el") | ||
(message "===Flycheck start===") | ||
(batch-flycheck))' \ | ||
"${files[@]}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters