Skip to content

Commit

Permalink
Added support for commands from cargo-edit
Browse files Browse the repository at this point in the history
See: https://github.com/killercup/cargo-edit
May try to add support for completion in the crate selection prompts for rm and
upgrade in the future
  • Loading branch information
PhilipBAdams committed Jul 20, 2018
1 parent 1009358 commit e4cbede
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cargo-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
;; * cargo-process-fmt - Run the optional cargo command fmt.
;; * cargo-process-check - Run the optional cargo command check.
;; * cargo-process-clippy - Run the optional cargo command clippy.
;; * cargo-process-add - Run the optional cargo command add.
;; * cargo-process-rm - Run the optional cargo command rm.
;; * cargo-process-upgrade - Run the optional cargo command upgrade.


;;
;;; Code:
Expand Down Expand Up @@ -124,6 +128,13 @@

(defvar cargo-process--command-clippy "clippy")

(defvar cargo-process--command-add "add")

(defvar cargo-process--command-rm "rm")

(defvar cargo-process--command-upgrade "upgrade")


(defface cargo-process--ok-face
'((t (:foreground "#00ff00")))
"Ok face"
Expand Down Expand Up @@ -506,6 +517,45 @@ Requires Cargo clippy to be installed."
(interactive)
(cargo-process--start "Clippy" cargo-process--command-clippy))

;;;###autoload
(defun cargo-process-add (crate)
"Run the Cargo add command.
With the prefix argument, modify the command's invocation.
CRATE is the name of the crate to add.
Cargo: This command allows you to add a dependency to a Cargo.toml manifest file."
(interactive "sCrate name: ")
(cargo-process--start "Add" (concat cargo-process--command-add
" "
crate)))

;;;###autoload
(defun cargo-process-rm (crate)
"Run the Cargo rm command.
With the prefix argument, modify the command's invocation.
CRATE is the name of the crate to remove.
Cargo: Remove a dependency from a Cargo.toml manifest file."
(interactive "sCrate name: ")
(cargo-process--start "Remove" (concat cargo-process--command-rm
" "
crate)))
;;;###autoload
(defun cargo-process-upgrade (&optional all crates)
"Run the Cargo update command.
With the prefix argument, modify the command's invocation.
If ALL is t then update all crates, otherwise specify CRATES.
Cargo: Upgrade dependencies as specified in the local manifest file"
(interactive)
(let ((all (when (or all
(y-or-n-p "Upgrade all crates? "))
"--all"))
(crates (if (not all)
(read-string "Crates to upgrade: ")
nil)))
(cargo-process--start "Upgrade" (concat cargo-process--command-upgrade
" "
all
crates))))

;;;###autoload
(defun cargo-process-repeat ()
"Run the last cargo-process command."
Expand Down
6 changes: 6 additions & 0 deletions cargo.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
;; * C-c C-c C-m - cargo-process-fmt
;; * C-c C-c C-k - cargo-process-check
;; * C-c C-c C-K - cargo-process-clippy
;; * C-c C-c C-a - cargo-process-add
;; * C-c C-c C-D - cargo-process-rm
;; * C-c C-c C-U - cargo-process-upgrade

;;
;;; Code:
Expand Down Expand Up @@ -82,6 +85,9 @@
(define-key cargo-minor-mode-map (kbd "C-c C-c C-m") 'cargo-process-fmt)
(define-key cargo-minor-mode-map (kbd "C-c C-c C-k") 'cargo-process-check)
(define-key cargo-minor-mode-map (kbd "C-c C-c C-S-k") 'cargo-process-clippy)
(define-key cargo-minor-mode-map (kbd "C-c C-c C-a") 'cargo-process-add)
(define-key cargo-minor-mode-map (kbd "C-c C-c C-S-d") 'cargo-process-rm)
(define-key cargo-minor-mode-map (kbd "C-c C-c C-S-u") 'cargo-process-upgrade)

(provide 'cargo)
;;; cargo.el ends here

0 comments on commit e4cbede

Please sign in to comment.