Skip to content

Commit

Permalink
Fix rust-mode lazy loading
Browse files Browse the repository at this point in the history
This PR fixes the following error that happends when opening a .rs
file:

	File mode specification error: (void-function rust-mode)

It adds a stub function called `rust-mode-choose` that selects the
appropriate `rust-mode` version (prog or treesitter) based on the
environment.

Fixes rust-lang#528
  • Loading branch information
jroimartin committed Mar 8, 2024
1 parent d8a09f2 commit 90ed0c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ 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
(defun rust-mode-choose ()
"Choose the appropriate rust-mode."
(if (and (version<= "29.1" emacs-version) rust-mode-treesitter-derive)
(require 'rust-mode-treesitter)
(require 'rust-prog-mode))
(rust-mode))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode-choose))

(provide 'rust-mode)
(require 'rust-utils)
Expand Down

0 comments on commit 90ed0c6

Please sign in to comment.