diff options
| author | Graham Marlow <graham@onesignal.com> | 2023-06-13 12:57:31 -0700 |
|---|---|---|
| committer | Graham Marlow <graham@onesignal.com> | 2023-06-13 12:57:31 -0700 |
| commit | 708cf774693243dbc5945fa8e764f1da65ae4ef9 (patch) | |
| tree | fe75a6ef179c1436cac30eb355eea8495ac00723 | |
| parent | 1cd4bb5a543f7d9ba6e4bff772a74a31672aa6d3 (diff) | |
| download | flymake-clippy-708cf774693243dbc5945fa8e764f1da65ae4ef9.tar.gz | |
Code cleanup
| -rw-r--r-- | clippy-flymake.el | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/clippy-flymake.el b/clippy-flymake.el index 5427eec..42bc56a 100644 --- a/clippy-flymake.el +++ b/clippy-flymake.el @@ -27,8 +27,43 @@ (require 'cl-lib) +;; Capture group source example: +;; "warning: ..." +;; --> src/filename.rs +;; 98 | ... +(defun clippy--build-regexp (filename) + "Create a regular expression to search Clippy warnings for FILENAME." + (rx-to-string + `(seq line-start + ;; Message + (group "warning:" + (zero-or-more nonl)) + "\n" + ;; File + (group + (zero-or-more nonl) + nonl ,filename) + ":" + ;; Line + (group + (one-or-more + (any "0-9"))) + ":" + ;; Col + (group + (one-or-more + (any "0-9"))) + line-end))) + +(defvar clippy--flymake-proc nil + "Clippy subprocess object, used to ensure obsolete processes aren't reused.") + (defun clippy-flymake (report-fn &rest _args) - "Flymake backend for cargo clippy." + "Flymake backend for cargo clippy. REPORT-FN is passed in via +`flymake-diagnostic-functions' hook. + +Use `clippy-flymake-setup-backend' to register the backend +with the appropriate Flymake hook." (unless (executable-find "cargo") (error "Cannot find cargo")) @@ -52,11 +87,7 @@ ;; exposing them via `report-fn'. (cl-loop while (search-forward-regexp - ;; Capture group source example: - ;; "warning: ..." - ;; --> src/filename.rs - ;; 98 | ... - (concat "^\\(warning:.*\\)\n\\(.*" filename "\\):\\([0-9]+\\):\\([0-9]+\\)$") + (clippy--build-regexp filename) nil t) for msg = (match-string 1) for (beg . end) = (flymake-diag-region |
