1717
1818(eval-when-compile (require 'rx ))
1919
20- (require 'json )
2120(require 'thingatpt )
2221
2322(defvar electric-pair-inhibit-predicate )
2423(defvar electric-pair-skip-self )
2524(defvar electric-indent-chars )
2625
27- (defvar rust-buffer-project nil )
28- (make-variable-buffer-local 'rust-buffer-project )
29-
3026; ;; Customization
3127
3228(defgroup rust-mode nil
@@ -59,16 +55,6 @@ When nil, `where' will be aligned with `fn' or `trait'."
5955 :safe #'booleanp
6056 :group 'rust-mode )
6157
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-
7258(defcustom rust-indent-return-type-to-arguments t
7359 " Indent a line starting with the `->' (RArrow) following a function, aligning
7460to the function arguments. When nil, `->' will be indented one level."
@@ -266,11 +252,7 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
266252
267253 (add-hook 'before-save-hook 'rust-before-save-hook nil t )
268254 (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+ )
274256
275257;;;### autoload
276258(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."
15691551 ; ; There is no opening brace, so consider the whole buffer to be one "defun"
15701552 (goto-char (point-max ))))
15711553
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-
16111554; ;; Secondary Commands
16121555
16131556(defun rust-promote-module-into-dir ()
@@ -1632,35 +1575,6 @@ visit the new file."
16321575 (rename-file filename new-name 1 )
16331576 (set-visited-file-name new-name))))))
16341577
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-
16641578(defun rust-insert-dbg ()
16651579 " Insert the dbg! macro."
16661580 (cond ((region-active-p )
0 commit comments