From 1ce4f8e26606462d73dc0895983d733580469124 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sat, 16 Mar 2024 23:05:05 +0100 Subject: [PATCH 1/2] rust--format-call: Delete file in case of error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That was always the intention, but the cleanup code was always placed outside the unwind forms. lib/rust-mode/rust-rustfmt.el:60:12: Warning: ‘unwind-protect’ without unwind forms --- rust-rustfmt.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-rustfmt.el b/rust-rustfmt.el index f609980..cab183c 100644 --- a/rust-rustfmt.el +++ b/rust-rustfmt.el @@ -87,8 +87,8 @@ (insert-file-contents tmpf) (rust--format-fix-rustfmt-buffer (buffer-name buf)) (error "Rustfmt failed, see %s buffer for details" - rust-rustfmt-buffername)))) - (delete-file tmpf)))))) + rust-rustfmt-buffername))) + (delete-file tmpf))))))) ;; Since we run rustfmt through stdin we get markers in the ;; output. This replaces them with the buffer name instead. From 7c5de035fab1b46926964b0defebef26357a5209 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Wed, 27 Mar 2024 16:53:42 +0100 Subject: [PATCH 2/2] Fix dependencies between rust-mode implementations "rust-prog-mode.el" and "rust-mode-treesitter.el" provide competing implementations of `rust-mode'. Both implementations depend on code in "rust-mode.el", and thus must require that. Doing that is complicated by the fact that "rust-mode.el" loads one of these libraries, depending on `rust-mode-treesitter-derive's value. Address this conflict by: 1. Requiring feature `rust-mode' in the two libraries that implement the `rust-mode' major-mode and that use things defined in "rust-mode.el". 2. Moving the require forms for these two libraries in "rust-mode.el", below the `provide' form for `rust-mode'. --- rust-mode-treesitter.el | 7 ++++--- rust-mode.el | 10 ++++++---- rust-prog-mode.el | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rust-mode-treesitter.el b/rust-mode-treesitter.el index 89c7cd4..21eab59 100644 --- a/rust-mode-treesitter.el +++ b/rust-mode-treesitter.el @@ -5,12 +5,13 @@ ;;; Code: +(require 'rust-mode) + +;; Do not compile or load on Emacs releases that don't support +;; this. See https://github.com/rust-lang/rust-mode/issues/520. (when (version<= "29.1" emacs-version) - ;; We have the when macro because of - ;; https://github.com/rust-lang/rust-mode/issues/520 (require 'treesit) (require 'rust-ts-mode) - (require 'rust-common) (define-derived-mode rust-mode rust-ts-mode "Rust" "Major mode for Rust code. diff --git a/rust-mode.el b/rust-mode.el index a0f6542..8d38295 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -71,10 +71,6 @@ instead of `prog-mode'. This option requires emacs29+." map) "Keymap for Rust major mode.") -(if (and (version<= "29.1" emacs-version) rust-mode-treesitter-derive) - (require 'rust-mode-treesitter) - (require 'rust-prog-mode)) - ;;;###autoload (autoload 'rust-mode "rust-mode" "Major mode for Rust code." t) @@ -82,6 +78,12 @@ instead of `prog-mode'. This option requires emacs29+." (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) (provide 'rust-mode) + +(if (and rust-mode-treesitter-derive + (version<= "29.1" emacs-version)) + (require 'rust-mode-treesitter) + (require 'rust-prog-mode)) + (require 'rust-utils) ;;; rust-mode.el ends here diff --git a/rust-prog-mode.el b/rust-prog-mode.el index 51e802d..05bc5e0 100644 --- a/rust-prog-mode.el +++ b/rust-prog-mode.el @@ -4,7 +4,8 @@ ;; rust-mode code deriving from prog-mode instead of rust-ts-mode ;;; Code: -(require 'rust-common) + +(require 'rust-mode) (defvar electric-pair-inhibit-predicate) (defvar electric-pair-skip-self)