emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode 4e7bf14bd0 1/4: add(rustfmt): introduce a new co


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode 4e7bf14bd0 1/4: add(rustfmt): introduce a new compilation-mode for rust-format
Date: Tue, 3 Sep 2024 10:10:31 -0400 (EDT)

branch: elpa/rust-mode
commit 4e7bf14bd074925b5f7b233a0f47b7a5ce4790ae
Author: roife <roifewu@gmail.com>
Commit: roife <roifewu@gmail.com>

    add(rustfmt): introduce a new compilation-mode for rust-format
---
 rust-rustfmt.el | 49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 45 insertions(+), 4 deletions(-)

diff --git a/rust-rustfmt.el b/rust-rustfmt.el
index ba3dbe2982..04dce459cd 100644
--- a/rust-rustfmt.el
+++ b/rust-rustfmt.el
@@ -7,6 +7,9 @@
 ;;; Code:
 ;;; Options
 
+(require 'rust-compile)
+(require 'compile)
+
 (defcustom rust-format-on-save nil
   "Format future rust buffers before saving using rustfmt."
   :type 'boolean
@@ -39,6 +42,34 @@
 
 (defconst rust-rustfmt-buffername "*rustfmt*")
 
+(define-compilation-mode rust-format-mode "rust-format"
+  "Major mode for Rust compilation output."
+
+  (setq-local compilation-error-regexp-alist-alist nil)
+  (add-to-list 'compilation-error-regexp-alist-alist
+               (cons 'rustc-refs rustc-refs-compilation-regexps))
+  (add-to-list 'compilation-error-regexp-alist-alist
+               (cons 'rustc rustc-compilation-regexps))
+  (add-to-list 'compilation-error-regexp-alist-alist
+               (cons 'rustc-colon rustc-colon-compilation-regexps))
+  (add-to-list 'compilation-error-regexp-alist-alist
+               (cons 'cargo cargo-compilation-regexps))
+  (add-to-list 'compilation-error-regexp-alist-alist
+               (cons 'rustc-panics rustc-panics-compilation-regexps))
+
+  (setq-local compilation-error-regexp-alist nil)
+  (add-to-list 'compilation-error-regexp-alist 'rustc-refs)
+  (add-to-list 'compilation-error-regexp-alist 'rustc)
+  (add-to-list 'compilation-error-regexp-alist 'rustc-colon)
+  (add-to-list 'compilation-error-regexp-alist 'cargo)
+  (add-to-list 'compilation-error-regexp-alist 'rustc-panics)
+
+  (add-hook 'next-error-hook #'rustc-scroll-down-after-next-error)
+
+  (if (or compilation-auto-jump-to-first-error
+          (eq compilation-scroll-output 'first-error))
+      (set (make-local-variable 'compilation-auto-jump-to-next) t)))
+
 (defun rust--format-call (buf)
   "Format BUF using rustfmt."
   (let ((path exec-path))
@@ -69,10 +100,20 @@
                         (with-current-buffer buf
                           (replace-buffer-contents rust-rustfmt-buffername))
                       (copy-to-buffer buf (point-min) (point-max))))
-               (let ((win (get-buffer-window rust-rustfmt-buffername)))
-                 (if win
-                     (quit-window t win)
-                   (kill-buffer rust-rustfmt-buffername))))
+                (let ((win (get-buffer-window rust-rustfmt-buffername)))
+                  (if win
+                      (quit-window t win)
+                    (kill-buffer rust-rustfmt-buffername))))
+               ((= ret 1)
+                (erase-buffer)
+                (insert-file-contents tmpf)
+
+                (rust-format-mode) ;; render compilation errors in 
compilation-mode
+                (setq-local compile-command (format "%s %s" rust-rustfmt-bin 
(buffer-file-name buf)))
+
+                (rust--format-fix-rustfmt-buffer (buffer-name buf))
+                (error "Rustfmt failed because of parsing errors, see %s 
buffer for details"
+                       rust-rustfmt-buffername))
                ((= ret 3)
                 (if (not (string= (buffer-string)
                                   (with-current-buffer buf (buffer-string))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]