Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clippy command. #22

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cargo-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
;;; C-c a b - `cargo-mode-build` - Build the project (`cargo build`).
;;; C-c a o - `cargo-mode-test-current-buffer` - Run all tests in the current buffer.
;;; C-c a f - `cargo-mode-test-current-test` - Run the current test where pointer is located.
;;; C-c a c - `cargo-mode-clippy` - Run Clippy in the project (`cargo clippy`).
;;;
;;; Use `C-u` to add extra command line params before executing a command.

Expand Down Expand Up @@ -69,6 +70,11 @@
:type 'string
:group 'cargo-mode)

(defcustom cargo-mode-command-clippy "clippy"
"Subcommand used by `cargo-mode-clippy'."
:type 'string
:group 'cargo-mode)

(defconst cargo-mode-test-mod-regexp "^[[:space:]]*mod[[:space:]]+[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*[[:space:]]*{")

(defconst cargo-mode-test-regexp "^[[:space:]]*fn[[:space:]]*"
Expand Down Expand Up @@ -245,6 +251,14 @@ If PREFIX is non-nil, prompt for additional params."
(let ((project-root (cargo-mode--project-directory)))
(cargo-mode--start "execute" cargo-mode-command-build project-root prefix)))

;;;###autoload
(defun cargo-mode-clippy (&optional prefix)
"Run the `cargo clippy` command.
If PREFIX is non-nil, prompt for additional params."
(interactive "P")
(let ((project-root (cargo-mode--project-directory)))
(cargo-mode--start "clippy" cargo-mode-command-clippy project-root prefix)))

;;;###autoload
(defun cargo-mode-test-current-buffer (&optional prefix)
"Run the cargo test for the current buffer.
Expand Down Expand Up @@ -281,6 +295,7 @@ If PREFIX is non-nil, prompt for additional params."
(define-key km (kbd "t") 'cargo-mode-test)
(define-key km (kbd "o") 'cargo-mode-test-current-buffer)
(define-key km (kbd "f") 'cargo-mode-test-current-test)
(define-key km (kbd "c") 'cargo-mode-clippy)
km)
"Cargo-mode keymap after prefix.")
(fset 'cargo-mode-command-map cargo-mode-command-map)
Expand Down