diff options
| author | jao <jao@gnu.org> | 2026-03-09 14:44:02 +0000 |
|---|---|---|
| committer | jao <jao@gnu.org> | 2026-03-09 14:44:02 +0000 |
| commit | f6b6191fd84dc3404b589acf95192cd94ebd5ae5 (patch) | |
| tree | db0d2246b0eea1ee1a37d3890fd0424e44d627f0 | |
| parent | 6fbc5dbf4e6a4c003c9ef8d80444ccdb8d5e183b (diff) | |
| download | elibs-main.tar.gz elibs-main.tar.bz2 | |
rust ergonomymain
| -rw-r--r-- | custom/jao-custom-programming.el | 13 | ||||
| -rw-r--r-- | lib/prog/jao-rust.el | 69 |
2 files changed, 79 insertions, 3 deletions
diff --git a/custom/jao-custom-programming.el b/custom/jao-custom-programming.el index 6fa5221..6106e9a 100644 --- a/custom/jao-custom-programming.el +++ b/custom/jao-custom-programming.el @@ -304,6 +304,8 @@ ;;;; Rust +(use-package jao-rust :demand t) + (use-package rust-mode :ensure t :demand t @@ -319,7 +321,7 @@ (setq-local completion-styles '(basic substring partial-completion emacs22))) :bind (:map rust-mode-map - ("<f3>" . hs-toggle-hiding) + ("C-c C" . jao-rust-open-cargo) ("C-c a" . eglot-code-actions) ("C-c m" . jao-transient-flymake) ("C-c r" . eglot-rename) @@ -334,9 +336,14 @@ :config (jao-define-attached-buffer '(major-mode . rustic-compilation-mode) 25) :custom - (rustic-cargo-use-last-stored-arguments t) + (rustic-cargo-use-last-stored-arguments nil) (rustic-analyzer-command '("rust-analyzer")) - :bind (:map rustic-mode-map (("C-c C-c d" . rustic-cargo-build-doc)))) + (rustic-cargo-test-runner 'nextest) + (rustic-cargo-nextest-exec-command '("nextest" "run" "--color=never" "--show-progress=none")) + :bind (:map rustic-mode-map (("C-c d" . rustic-cargo-build-doc) + ("C-c t w" . jao-rust-test-workspace) + ("C-c t m" . jao-rust-test-module) + ("C-c t t" . rustic-cargo-current-test)))) (use-package rust-playground :ensure t) diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el new file mode 100644 index 0000000..9c08e9b --- /dev/null +++ b/lib/prog/jao-rust.el @@ -0,0 +1,69 @@ +;;; jao-rust.el --- Utilities for rust programming -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Jose Ruiz + +;; Author: Jose Ruiz <mail@jao.io> +;; Keywords: languages + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(defun jao-rust--root () (project-root (project-current))) + +(defun jao-rust-open-cargo () + (interactive) + (let ((f (expand-file-name "Cargo.toml" (jao-rust--root)))) + (when (or (file-exists-p f) + (y-or-n-p "No Cargo.toml found. Create? ")) + (find-file f)))) + +(defun jao-rust-current-module-name () + (let* ((root (expand-file-name (jao-rust--root))) + (current (file-name-sans-extension (buffer-file-name))) + (rel (string-replace root "" current))) + (thread-last + rel + (replace-regexp-in-string "^src\\(/bin\\)?/" "") + (string-replace "-" "_") + (replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "") + (string-replace "/" "::")))) + +(defun jao-rust-buffer-tests () + (save-excursion + (goto-char (point-min)) + (let ((res '())) + (while (re-search-forward "#\\[\\(tokio::test\\|test\\|quickcheck\\)" nil t) + (forward-line) + (when (looking-at "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(") + (push (match-string-no-properties 3) res))) + res))) + +(defun jao-rust-test-module () + (interactive) + (let ((tests (jao-rust-buffer-tests))) + (if (seq-empty-p tests) + (messages "No tests in this module") + (let* ((mod (jao-rust-current-module-name)) + (tests (mapconcat (lambda (x) (format "%s::tests::%s" mod x)) tests " ")) + (rustic-test-arguments (format "-- --exact %s" tests))) + (rustic-cargo-test))))) + +(defun jao-rust-test-workspace () + (interactive) + (let ((rustic-test-arguments rustic-default-test-arguments)) + (rustic-cargo-test))) + +(provide 'jao-rust) +;;; jao-rust.el ends here |
