17
17
18
18
(eval-when-compile (require 'rx ))
19
19
20
- (require 'json )
21
20
(require 'thingatpt )
22
21
23
22
(defvar electric-pair-inhibit-predicate )
24
23
(defvar electric-pair-skip-self )
25
24
(defvar electric-indent-chars )
26
25
27
- (defvar rust-buffer-project nil )
28
- (make-variable-buffer-local 'rust-buffer-project )
29
-
30
26
; ;; Customization
31
27
32
28
(defgroup rust-mode nil
@@ -59,16 +55,6 @@ When nil, `where' will be aligned with `fn' or `trait'."
59
55
:safe #'booleanp
60
56
:group 'rust-mode )
61
57
62
- (defcustom rust-cargo-bin " cargo"
63
- " Path to cargo executable."
64
- :type 'string
65
- :group 'rust-mode )
66
-
67
- (defcustom rust-always-locate-project-on-open nil
68
- " Whether to run `cargo locate-project' every time `rust-mode' is activated."
69
- :type 'boolean
70
- :group 'rust-mode )
71
-
72
58
(defcustom rust-indent-return-type-to-arguments t
73
59
" Indent a line starting with the `->' (RArrow) following a function, aligning
74
60
to the function arguments. When nil, `->' will be indented one level."
@@ -266,11 +252,7 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
266
252
267
253
(add-hook 'before-save-hook 'rust-before-save-hook nil t )
268
254
(add-hook 'after-save-hook 'rust-after-save-hook nil t )
269
-
270
- (setq-local rust-buffer-project nil )
271
-
272
- (when rust-always-locate-project-on-open
273
- (rust-update-buffer-project)))
255
+ )
274
256
275
257
;;;### autoload
276
258
(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."
1569
1551
; ; There is no opening brace, so consider the whole buffer to be one "defun"
1570
1552
(goto-char (point-max ))))
1571
1553
1572
- (defun rust--compile (format-string &rest args )
1573
- (when (null rust-buffer-project)
1574
- (rust-update-buffer-project))
1575
- (let ((default-directory
1576
- (or (and rust-buffer-project
1577
- (file-name-directory rust-buffer-project))
1578
- default-directory)))
1579
- (compile (apply #'format format-string args))))
1580
-
1581
- (defun rust-check ()
1582
- " Compile using `cargo check`"
1583
- (interactive )
1584
- (rust--compile " %s check" rust-cargo-bin))
1585
-
1586
- (defun rust-compile ()
1587
- " Compile using `cargo build`"
1588
- (interactive )
1589
- (rust--compile " %s build" rust-cargo-bin))
1590
-
1591
- (defun rust-compile-release ()
1592
- " Compile using `cargo build --release`"
1593
- (interactive )
1594
- (rust--compile " %s build --release" rust-cargo-bin))
1595
-
1596
- (defun rust-run ()
1597
- " Run using `cargo run`"
1598
- (interactive )
1599
- (rust--compile " %s run" rust-cargo-bin))
1600
-
1601
- (defun rust-run-release ()
1602
- " Run using `cargo run --release`"
1603
- (interactive )
1604
- (rust--compile " %s run --release" rust-cargo-bin))
1605
-
1606
- (defun rust-test ()
1607
- " Test using `cargo test`"
1608
- (interactive )
1609
- (rust--compile " %s test" rust-cargo-bin))
1610
-
1611
1554
; ;; Secondary Commands
1612
1555
1613
1556
(defun rust-promote-module-into-dir ()
@@ -1632,35 +1575,6 @@ visit the new file."
1632
1575
(rename-file filename new-name 1 )
1633
1576
(set-visited-file-name new-name))))))
1634
1577
1635
- (defun rust-run-clippy ()
1636
- " Run `cargo clippy'."
1637
- (interactive )
1638
- (when (null rust-buffer-project)
1639
- (rust-update-buffer-project))
1640
- (let* ((args (list rust-cargo-bin " clippy"
1641
- (concat " --manifest-path=" rust-buffer-project)))
1642
- ; ; set `compile-command' temporarily so `compile' doesn't
1643
- ; ; clobber the existing value
1644
- (compile-command (mapconcat #'shell-quote-argument args " " )))
1645
- (rust--compile compile-command)))
1646
-
1647
- ; ;; Utilities
1648
-
1649
- (defun rust-update-buffer-project ()
1650
- (setq-local rust-buffer-project (rust-buffer-project)))
1651
-
1652
- (defun rust-buffer-project ()
1653
- " Get project root if possible."
1654
- (with-temp-buffer
1655
- (let ((ret (call-process rust-cargo-bin nil t nil " locate-project" )))
1656
- (when (/= ret 0 )
1657
- (error " `cargo locate-project' returned %s status: %s " ret (buffer-string )))
1658
- (goto-char 0 )
1659
- (let ((output (json-read )))
1660
- (cdr (assoc-string " root" output))))))
1661
-
1662
- ; ;; Secondary Commands
1663
-
1664
1578
(defun rust-insert-dbg ()
1665
1579
" Insert the dbg! macro."
1666
1580
(cond ((region-active-p )
0 commit comments