summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2024-11-10 15:15:42 +0100
committerSimeon Simeonov2024-11-10 15:15:42 +0100
commit4227c712db2a11302ec4eda0c5035fecc4e3e4d2 (patch)
treea852a6515682594a0c6be6fcfa50755b41f56bea
parenta773e7ed865a1a7eb5bf00b9f0481e888534831a (diff)
Upgrade rust-mode and yasnippet
-rw-r--r--.emacs.d/lisp/rust-cargo-tests.el19
-rw-r--r--.emacs.d/lisp/rust-mode.el2
-rw-r--r--.emacs.d/lisp/rust-rustfmt.el51
-rw-r--r--.emacs.d/lisp/yasnippet.el67
4 files changed, 100 insertions, 39 deletions
diff --git a/.emacs.d/lisp/rust-cargo-tests.el b/.emacs.d/lisp/rust-cargo-tests.el
index f49cba0..fe78ac7 100644
--- a/.emacs.d/lisp/rust-cargo-tests.el
+++ b/.emacs.d/lisp/rust-cargo-tests.el
@@ -1,5 +1,6 @@
1;;; rust-cargo-tests.el --- ERT tests for rust-cargo.el -*- lexical-binding: t; -*- 1;;; rust-cargo-tests.el --- ERT tests for rust-cargo.el -*- lexical-binding: t; -*-
2(require 'rust-cargo) 2(require 'rust-cargo)
3(require 'rust-rustfmt)
3(require 'ert) 4(require 'ert)
4 5
5(defun rust-test--wait-process-exit () 6(defun rust-test--wait-process-exit ()
@@ -51,3 +52,21 @@
51 (rust-test--send-process-string "1234\n") 52 (rust-test--send-process-string "1234\n")
52 (rust-test--wait-process-exit) 53 (rust-test--wait-process-exit)
53 (should (rust-test--find-string "***run interactive: 1234"))))) 54 (should (rust-test--find-string "***run interactive: 1234")))))
55
56(ert-deftest rust-test-rustfmt ()
57 (skip-unless (executable-find "rustfmt"))
58 (rust-test--with-main-file-buffer
59 (let ((old-content (buffer-string))
60 (ret (rust-format-buffer)))
61 (should (string= ret "Formatted buffer with rustfmt."))
62 (should (string= old-content (buffer-string))))))
63
64(ert-deftest rust-test-rustfmt-parsing-errors ()
65 (skip-unless (executable-find "rustfmt"))
66 (with-temp-buffer
67 (insert "fn main() {")
68 (rust-format-buffer)
69 (with-current-buffer "*rustfmt*"
70 (should (eq major-mode 'rust-format-mode))
71 (should (rust-test--find-string "error:")))
72 (kill-buffer "*rustfmt*")))
diff --git a/.emacs.d/lisp/rust-mode.el b/.emacs.d/lisp/rust-mode.el
index 8d38295..52c5242 100644
--- a/.emacs.d/lisp/rust-mode.el
+++ b/.emacs.d/lisp/rust-mode.el
@@ -1,6 +1,6 @@
1;;; rust-mode.el --- A major-mode for editing Rust source code -*-lexical-binding: t-*- 1;;; rust-mode.el --- A major-mode for editing Rust source code -*-lexical-binding: t-*-
2 2
3;; Version: 1.0.5 3;; Version: 1.0.6
4;; Author: Mozilla <rust-mode@noreply.github.com> 4;; Author: Mozilla <rust-mode@noreply.github.com>
5;; Url: https://github.com/rust-lang/rust-mode 5;; Url: https://github.com/rust-lang/rust-mode
6;; Keywords: languages 6;; Keywords: languages
diff --git a/.emacs.d/lisp/rust-rustfmt.el b/.emacs.d/lisp/rust-rustfmt.el
index cab183c..04dce45 100644
--- a/.emacs.d/lisp/rust-rustfmt.el
+++ b/.emacs.d/lisp/rust-rustfmt.el
@@ -7,6 +7,9 @@
7;;; Code: 7;;; Code:
8;;; Options 8;;; Options
9 9
10(require 'rust-compile)
11(require 'compile)
12
10(defcustom rust-format-on-save nil 13(defcustom rust-format-on-save nil
11 "Format future rust buffers before saving using rustfmt." 14 "Format future rust buffers before saving using rustfmt."
12 :type 'boolean 15 :type 'boolean
@@ -30,7 +33,7 @@
30 :type 'string 33 :type 'string
31 :group 'rust-mode) 34 :group 'rust-mode)
32 35
33(defcustom rust-rustfmt-switches '("--edition" "2018") 36(defcustom rust-rustfmt-switches '("--edition" "2021")
34 "Arguments to pass when invoking the `rustfmt' executable." 37 "Arguments to pass when invoking the `rustfmt' executable."
35 :type '(repeat string) 38 :type '(repeat string)
36 :group 'rust-mode) 39 :group 'rust-mode)
@@ -39,6 +42,34 @@
39 42
40(defconst rust-rustfmt-buffername "*rustfmt*") 43(defconst rust-rustfmt-buffername "*rustfmt*")
41 44
45(define-compilation-mode rust-format-mode "rust-format"
46 "Major mode for Rust compilation output."
47
48 (setq-local compilation-error-regexp-alist-alist nil)
49 (add-to-list 'compilation-error-regexp-alist-alist
50 (cons 'rustc-refs rustc-refs-compilation-regexps))
51 (add-to-list 'compilation-error-regexp-alist-alist
52 (cons 'rustc rustc-compilation-regexps))
53 (add-to-list 'compilation-error-regexp-alist-alist
54 (cons 'rustc-colon rustc-colon-compilation-regexps))
55 (add-to-list 'compilation-error-regexp-alist-alist
56 (cons 'cargo cargo-compilation-regexps))
57 (add-to-list 'compilation-error-regexp-alist-alist
58 (cons 'rustc-panics rustc-panics-compilation-regexps))
59
60 (setq-local compilation-error-regexp-alist nil)
61 (add-to-list 'compilation-error-regexp-alist 'rustc-refs)
62 (add-to-list 'compilation-error-regexp-alist 'rustc)
63 (add-to-list 'compilation-error-regexp-alist 'rustc-colon)
64 (add-to-list 'compilation-error-regexp-alist 'cargo)
65 (add-to-list 'compilation-error-regexp-alist 'rustc-panics)
66
67 (add-hook 'next-error-hook #'rustc-scroll-down-after-next-error)
68
69 (if (or compilation-auto-jump-to-first-error
70 (eq compilation-scroll-output 'first-error))
71 (set (make-local-variable 'compilation-auto-jump-to-next) t)))
72
42(defun rust--format-call (buf) 73(defun rust--format-call (buf)
43 "Format BUF using rustfmt." 74 "Format BUF using rustfmt."
44 (let ((path exec-path)) 75 (let ((path exec-path))
@@ -69,10 +100,20 @@
69 (with-current-buffer buf 100 (with-current-buffer buf
70 (replace-buffer-contents rust-rustfmt-buffername)) 101 (replace-buffer-contents rust-rustfmt-buffername))
71 (copy-to-buffer buf (point-min) (point-max)))) 102 (copy-to-buffer buf (point-min) (point-max))))
72 (let ((win (get-buffer-window rust-rustfmt-buffername))) 103 (let ((win (get-buffer-window rust-rustfmt-buffername)))
73 (if win 104 (if win
74 (quit-window t win) 105 (quit-window t win)
75 (kill-buffer rust-rustfmt-buffername)))) 106 (kill-buffer rust-rustfmt-buffername))))
107 ((= ret 1)
108 (erase-buffer)
109 (insert-file-contents tmpf)
110
111 (rust-format-mode) ;; render compilation errors in compilation-mode
112 (setq-local compile-command (format "%s %s" rust-rustfmt-bin (buffer-file-name buf)))
113
114 (rust--format-fix-rustfmt-buffer (buffer-name buf))
115 (error "Rustfmt failed because of parsing errors, see %s buffer for details"
116 rust-rustfmt-buffername))
76 ((= ret 3) 117 ((= ret 3)
77 (if (not (string= (buffer-string) 118 (if (not (string= (buffer-string)
78 (with-current-buffer buf (buffer-string)))) 119 (with-current-buffer buf (buffer-string))))
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index 0d52a96..782c440 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -4128,39 +4128,40 @@ Returns the newly created snippet."
4128 (yas--letenv expand-env 4128 (yas--letenv expand-env
4129 ;; Put a single undo action for the expanded snippet's 4129 ;; Put a single undo action for the expanded snippet's
4130 ;; content. 4130 ;; content.
4131 (let ((buffer-undo-list t)) 4131 (unwind-protect
4132 (goto-char begin) 4132 (let ((buffer-undo-list t))
4133 (if (> emacs-major-version 29) 4133 (goto-char begin)
4134 ;; Don't use the workaround for CC-mode's cache, 4134 (if (> emacs-major-version 29)
4135 ;; since it was presumably a bug in CC-mode, so either 4135 ;; Don't use the workaround for CC-mode's cache,
4136 ;; it's fixed already, or it should get fixed. 4136 ;; since it was presumably a bug in CC-mode, so either
4137 (progn 4137 ;; it's fixed already, or it should get fixed.
4138 (insert content) 4138 (progn
4139 (narrow-to-region begin (point)) 4139 (insert content)
4140 (goto-char (point-min)) 4140 (narrow-to-region begin (point))
4141 (yas--snippet-parse-create snippet)) 4141 (goto-char (point-min))
4142 ;; Call before and after change functions manually, 4142 (yas--snippet-parse-create snippet))
4143 ;; otherwise cc-mode's cache can get messed up. Don't use 4143 ;; Call before and after change functions manually,
4144 ;; `inhibit-modification-hooks' for that, that blocks 4144 ;; otherwise cc-mode's cache can get messed up. Don't use
4145 ;; overlay and text property hooks as well! FIXME: Maybe 4145 ;; `inhibit-modification-hooks' for that, that blocks
4146 ;; use `combine-change-calls'? (Requires Emacs 27+ though.) 4146 ;; overlay and text property hooks as well! FIXME: Maybe
4147 (run-hook-with-args 'before-change-functions begin end) 4147 ;; use `combine-change-calls'? (Requires Emacs 27+ though.)
4148 (let ((before-change-functions nil) 4148 (run-hook-with-args 'before-change-functions begin end)
4149 (after-change-functions nil)) 4149 (let ((before-change-functions nil)
4150 ;; Some versions of cc-mode (might be the one with Emacs 4150 (after-change-functions nil))
4151 ;; 24.3 only) fail when inserting snippet content in a 4151 ;; Some versions of cc-mode (might be the one with Emacs
4152 ;; narrowed buffer, so make sure to insert before 4152 ;; 24.3 only) fail when inserting snippet content in a
4153 ;; narrowing. 4153 ;; narrowed buffer, so make sure to insert before
4154 (insert content) 4154 ;; narrowing.
4155 (narrow-to-region begin (point)) 4155 (insert content)
4156 (goto-char (point-min)) 4156 (narrow-to-region begin (point))
4157 (yas--snippet-parse-create snippet)) 4157 (goto-char (point-min))
4158 (run-hook-with-args 'after-change-functions 4158 (yas--snippet-parse-create snippet))
4159 (point-min) (point-max) 4159 (run-hook-with-args 'after-change-functions
4160 (- end begin)))) 4160 (point-min) (point-max)
4161 (when (listp buffer-undo-list) 4161 (- end begin))))
4162 (push (cons (point-min) (point-max)) 4162 (when (listp buffer-undo-list)
4163 buffer-undo-list)) 4163 (push (cons (point-min) (point-max))
4164 buffer-undo-list)))
4164 4165
4165 ;; Indent, collecting undo information normally. 4166 ;; Indent, collecting undo information normally.
4166 (yas--indent snippet) 4167 (yas--indent snippet)