[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 649f492 484/486: Create rust-cargo.el from exist
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 649f492 484/486: Create rust-cargo.el from existing code |
Date: |
Sat, 7 Aug 2021 09:26:19 -0400 (EDT) |
branch: elpa/rust-mode
commit 649f492e073f449fb5e5557c4f7ff30ada8800e2
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: brotzeit <brotzeitmacher@gmail.com>
Create rust-cargo.el from existing code
---
Makefile | 1 +
rust-cargo.el | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rust-mode.el | 88 +------------------------------------------------
3 files changed, 105 insertions(+), 87 deletions(-)
diff --git a/Makefile b/Makefile
index ded2945..aaa652c 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ EMACS ?= emacs
EMACS_ARGS ?=
ELS = rust-mode.el
+ELS += rust-cargo.el
ELS += rust-compile.el
ELS += rust-playpen.el
ELS += rust-rustfmt.el
diff --git a/rust-cargo.el b/rust-cargo.el
new file mode 100644
index 0000000..30ba611
--- /dev/null
+++ b/rust-cargo.el
@@ -0,0 +1,103 @@
+;;; rust-cargo.el --- Support for cargo -*-lexical-binding: t-*-
+;;; Commentary:
+
+;; This library implements support for running `cargo'.
+
+;;; Code:
+
+(require 'json)
+
+;;; Options
+
+(defcustom rust-cargo-bin "cargo"
+ "Path to cargo executable."
+ :type 'string
+ :group 'rust-mode)
+
+(defcustom rust-always-locate-project-on-open nil
+ "Whether to run `cargo locate-project' every time `rust-mode' is activated."
+ :type 'boolean
+ :group 'rust-mode)
+
+;;; Buffer Project
+
+(defvar-local rust-buffer-project nil)
+
+(defun rust-buffer-project ()
+ "Get project root if possible."
+ (with-temp-buffer
+ (let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
+ (when (/= ret 0)
+ (error "`cargo locate-project' returned %s status: %s" ret
(buffer-string)))
+ (goto-char 0)
+ (let ((output (json-read)))
+ (cdr (assoc-string "root" output))))))
+
+(defun rust-update-buffer-project ()
+ (setq-local rust-buffer-project (rust-buffer-project)))
+
+(defun rust-maybe-initialize-buffer-project ()
+ (setq-local rust-buffer-project nil)
+ (when rust-always-locate-project-on-open
+ (rust-update-buffer-project)))
+
+(add-hook 'rust-mode-hook 'rust-maybe-initialize-buffer-project)
+
+;;; Internal
+
+(defun rust--compile (format-string &rest args)
+ (when (null rust-buffer-project)
+ (rust-update-buffer-project))
+ (let ((default-directory
+ (or (and rust-buffer-project
+ (file-name-directory rust-buffer-project))
+ default-directory)))
+ (compile (apply #'format format-string args))))
+
+;;; Commands
+
+(defun rust-check ()
+ "Compile using `cargo check`"
+ (interactive)
+ (rust--compile "%s check" rust-cargo-bin))
+
+(defun rust-compile ()
+ "Compile using `cargo build`"
+ (interactive)
+ (rust--compile "%s build" rust-cargo-bin))
+
+(defun rust-compile-release ()
+ "Compile using `cargo build --release`"
+ (interactive)
+ (rust--compile "%s build --release" rust-cargo-bin))
+
+(defun rust-run ()
+ "Run using `cargo run`"
+ (interactive)
+ (rust--compile "%s run" rust-cargo-bin))
+
+(defun rust-run-release ()
+ "Run using `cargo run --release`"
+ (interactive)
+ (rust--compile "%s run --release" rust-cargo-bin))
+
+(defun rust-test ()
+ "Test using `cargo test`"
+ (interactive)
+ (rust--compile "%s test" rust-cargo-bin))
+
+(defun rust-run-clippy ()
+ "Run `cargo clippy'."
+ (interactive)
+ (when (null rust-buffer-project)
+ (rust-update-buffer-project))
+ (let* ((args (list rust-cargo-bin "clippy"
+ (concat "--manifest-path=" rust-buffer-project)))
+ ;; set `compile-command' temporarily so `compile' doesn't
+ ;; clobber the existing value
+ (compile-command (mapconcat #'shell-quote-argument args " ")))
+ (rust--compile compile-command)))
+
+;;; _
+(provide 'rust-cargo)
+;;; rust-cargo.el ends here
diff --git a/rust-mode.el b/rust-mode.el
index 0b1f5d1..d4d61d7 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -17,16 +17,12 @@
(eval-when-compile (require 'rx))
-(require 'json)
(require 'thingatpt)
(defvar electric-pair-inhibit-predicate)
(defvar electric-pair-skip-self)
(defvar electric-indent-chars)
-(defvar rust-buffer-project nil)
-(make-variable-buffer-local 'rust-buffer-project)
-
;;; Customization
(defgroup rust-mode nil
@@ -59,16 +55,6 @@ When nil, `where' will be aligned with `fn' or `trait'."
:safe #'booleanp
:group 'rust-mode)
-(defcustom rust-cargo-bin "cargo"
- "Path to cargo executable."
- :type 'string
- :group 'rust-mode)
-
-(defcustom rust-always-locate-project-on-open nil
- "Whether to run `cargo locate-project' every time `rust-mode' is activated."
- :type 'boolean
- :group 'rust-mode)
-
(defcustom rust-indent-return-type-to-arguments t
"Indent a line starting with the `->' (RArrow) following a function, aligning
to the function arguments. When nil, `->' will be indented one level."
@@ -266,11 +252,7 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
(add-hook 'before-save-hook 'rust-before-save-hook nil t)
(add-hook 'after-save-hook 'rust-after-save-hook nil t)
-
- (setq-local rust-buffer-project nil)
-
- (when rust-always-locate-project-on-open
- (rust-update-buffer-project)))
+ )
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
@@ -1569,45 +1551,6 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
;; There is no opening brace, so consider the whole buffer to be one
"defun"
(goto-char (point-max))))
-(defun rust--compile (format-string &rest args)
- (when (null rust-buffer-project)
- (rust-update-buffer-project))
- (let ((default-directory
- (or (and rust-buffer-project
- (file-name-directory rust-buffer-project))
- default-directory)))
- (compile (apply #'format format-string args))))
-
-(defun rust-check ()
- "Compile using `cargo check`"
- (interactive)
- (rust--compile "%s check" rust-cargo-bin))
-
-(defun rust-compile ()
- "Compile using `cargo build`"
- (interactive)
- (rust--compile "%s build" rust-cargo-bin))
-
-(defun rust-compile-release ()
- "Compile using `cargo build --release`"
- (interactive)
- (rust--compile "%s build --release" rust-cargo-bin))
-
-(defun rust-run ()
- "Run using `cargo run`"
- (interactive)
- (rust--compile "%s run" rust-cargo-bin))
-
-(defun rust-run-release ()
- "Run using `cargo run --release`"
- (interactive)
- (rust--compile "%s run --release" rust-cargo-bin))
-
-(defun rust-test ()
- "Test using `cargo test`"
- (interactive)
- (rust--compile "%s test" rust-cargo-bin))
-
;;; Secondary Commands
(defun rust-promote-module-into-dir ()
@@ -1632,35 +1575,6 @@ visit the new file."
(rename-file filename new-name 1)
(set-visited-file-name new-name))))))
-(defun rust-run-clippy ()
- "Run `cargo clippy'."
- (interactive)
- (when (null rust-buffer-project)
- (rust-update-buffer-project))
- (let* ((args (list rust-cargo-bin "clippy"
- (concat "--manifest-path=" rust-buffer-project)))
- ;; set `compile-command' temporarily so `compile' doesn't
- ;; clobber the existing value
- (compile-command (mapconcat #'shell-quote-argument args " ")))
- (rust--compile compile-command)))
-
-;;; Utilities
-
-(defun rust-update-buffer-project ()
- (setq-local rust-buffer-project (rust-buffer-project)))
-
-(defun rust-buffer-project ()
- "Get project root if possible."
- (with-temp-buffer
- (let ((ret (call-process rust-cargo-bin nil t nil "locate-project")))
- (when (/= ret 0)
- (error "`cargo locate-project' returned %s status: %s" ret
(buffer-string)))
- (goto-char 0)
- (let ((output (json-read)))
- (cdr (assoc-string "root" output))))))
-
-;;; Secondary Commands
-
(defun rust-insert-dbg ()
"Insert the dbg! macro."
(cond ((region-active-p)
- [nongnu] elpa/rust-mode a789a25 266/486: Fix #168: use while in rust-rewind-irrelevant, (continued)
- [nongnu] elpa/rust-mode a789a25 266/486: Fix #168: use while in rust-rewind-irrelevant, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 936a187 276/486: handle indirect buffers and multiple windows in rust-format-buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 09efc45 320/486: Merge pull request #219 from Aankhen/highlight-question-mark, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b10ad41 326/486: Merge pull request #220 from Aankhen/highlight-string-interpolation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d71fe94 307/486: restore points when an error occurs too, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1b3db88 422/486: Add a function wrap and unwrap with the dbg! macro., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8733792 448/486: Drop Emacs-24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9eb2c63 460/486: Fix README internal link (#389), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 13c4335 462/486: Improve doc-strings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c23453d 463/486: rearrange I: Move options and faces to beginning of file, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 649f492 484/486: Create rust-cargo.el from existing code,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 198c777 386/486: Replaced font-lock-fontify-buffer with font-lock-ensure, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a871d10 390/486: Merge pull request #298 from jjwest/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0a94268 396/486: Merge pull request #307 from Bunogi/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86bc286 401/486: Add specific distribution for EVM, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 06b3b60 412/486: update readme (#327), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c0cc6dc 420/486: Allow pass custom flags to rustfmt. (#338), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 888f3de 442/486: rust--format-fix-rustfmt-buffer: replace "stdin:" as well as "<stdin>:"., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ef152ad 459/486: Minor fixes (#388), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0797e7b 017/486: add Url, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5375e54 454/486: Test byte compilation of test code., ELPA Syncer, 2021/08/07