forked from brotzeit/rustic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rustic-clippy.el
114 lines (96 loc) · 3.92 KB
/
rustic-clippy.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
;;; rustic-clippy.el --- clippy commands -*-lexical-binding: t-*-
;;; Commentary:
;; This library implements support for `clippy'.
;;; Code:
(require 'rustic-compile)
(defcustom rustic-cargo-clippy-fix-args "--allow-dirty"
"Default arguments when running 'clippy --fix'."
:type 'string
:group 'rustic-cargo)
(defcustom rustic-default-clippy-arguments "--benches --tests --all-features"
"Default arguments when running clippy."
:type 'string
:group 'rustic-cargo)
(defcustom rustic-lints-arguments "-f custom_lints.toml clippy"
"Default arguments when running cargo-lints."
:type 'string
:group 'rustic-cargo)
(defvar rustic-clippy-process-name "rustic-cargo-clippy-process"
"Process name for clippy processes.")
(defvar rustic-clippy-buffer-name "*cargo-clippy*"
"Buffer name for clippy buffers.")
(defvar rustic-clippy-arguments ""
"Holds arguments for 'cargo clippy', similar to `compilation-arguments`.")
(defvar rustic-cargo-clippy-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [remap recompile] 'rustic-cargo-clippy-rerun)
map)
"Local keymap for `rustic-cargo-clippy-mode' buffers.")
(define-derived-mode rustic-cargo-clippy-mode rustic-compilation-mode "cargo-clippy"
:group 'rustic)
;;;###autoload
(defun rustic-cargo-clippy-run (&rest args)
"Run `cargo clippy' with optional ARGS."
(interactive)
(let* ((command (list rustic-cargo-bin "clippy"))
(params (plist-get args :params))
(c (append command (split-string (if params params ""))))
(buf rustic-clippy-buffer-name)
(proc rustic-clippy-process-name)
(mode 'rustic-cargo-clippy-mode))
(unless (plist-get args :no-save)
(rustic-compilation-process-live))
(rustic-compilation c (list :buffer buf
:process proc
:mode mode
:sentinel (plist-get args :sentinel)
:no-display (plist-get args :silent)))))
;;;###autoload
(defun rustic-cargo-lints ()
"Run cargo-lints with optional ARGS."
(interactive)
(let* ((command `(,(rustic-cargo-bin)
"lints"
,@(split-string rustic-lints-arguments)))
(buf rustic-clippy-buffer-name)
(proc rustic-clippy-process-name)
(mode 'rustic-cargo-clippy-mode))
(rustic-compilation command (list :buffer buf :process proc :mode mode))))
;;;###autoload
(defun rustic-cargo-clippy (&optional arg)
"Run 'cargo clippy'.
If ARG is not nil, use value as argument and store it in `rustic-clippy-arguments'.
When calling this function from `rustic-popup-mode', always use the value of
`rustic-clippy-arguments'."
(interactive "P")
(rustic-cargo-clippy-run
:params (cond (arg
(setq rustic-clippy-arguments (read-from-minibuffer "Cargo clippy arguments: " rustic-default-clippy-arguments)))
((eq major-mode 'rustic-popup-mode)
(if (> (length rustic-clippy-arguments) 0)
rustic-clippy-arguments
rustic-default-clippy-arguments))
(t
rustic-default-clippy-arguments))))
;;;###autoload
(defun rustic-cargo-clippy-rerun ()
"Run 'cargo clippy' with `rustic-clippy-arguments'."
(interactive)
(rustic-cargo-clippy-run rustic-clippy-arguments))
(defun rustic-cargo-clippy-fix (&rest args)
"Run 'clippy fix'."
(interactive)
(rustic-cargo-clippy-run
:params (concat "--fix "
rustic-cargo-clippy-fix-args " "
rustic-default-clippy-arguments)
:no-save (plist-get args :no-save)
:silent t
:sentinel (lambda (proc msg)
(while (eq (process-status proc) 'run)
(sit-for 0.1))
(if (zerop (process-exit-status proc))
(kill-buffer (get-buffer rustic-clippy-buffer-name))
(funcall rustic-compile-display-method (process-buffer proc))))))
(provide 'rustic-clippy)
;;; rustic-clippy.el ends here