rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 176 forks source link

Fix rust-mode lazy loading #530

Closed jroimartin closed 3 months ago

jroimartin commented 4 months ago

This PR fixes the following error that happends when opening a .rs file:

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

It conditionally autoloads the proper rust-mode version depending on the user environment.

Fixes #528

psibi commented 4 months ago

Thanks, @jroimartin can you see why the tests are failing ?

jroimartin commented 4 months ago

Sure, I'm working on it.

jroimartin commented 4 months ago

@psibi PTAL. I think this is the smallest required change. On the flip side, it is a bit tricky. But having two major modes with the same name and loading them conditionally seems problematic. So, I opted for allowing the stub function (called rust-mode) to be redefined when the actual mode gets loaded.

psibi commented 4 months ago

Thanks, LGTM. @condy0919 Can you see if it works in your setup too ? I will test drive this PR too.

condy0919 commented 4 months ago

Thanks, LGTM. @condy0919 Can you see if it works in your setup too ? I will test drive this PR too.

Sorry, I'm in a touring🥺 can't help that

jroimartin commented 4 months ago

No rush. There is a valid workaround which is just adding (require 'rust-mode) to init.el. It is just that it is nice to support lazy loading :slightly_smiling_face: This change also make rust-mode just work for people using plain package.el.

psibi commented 4 months ago

No worries, I'm also going to be on travel for the next two days. I will test this out more properly after that.

jroimartin commented 3 months ago

@psibi @condy0919 what do you think of db7d086? This option does not require messing up with the rust-mode function definition.

condy0919 commented 3 months ago

@psibi @condy0919 what do you think of db7d086? This option does not require messing up with the rust-mode function definition.

This solution comes to mind at first, and the trick is used in the evil-exchange package.

psibi commented 3 months ago

I did some testing and this seems to work fine. @jroimartin Thanks for the PR. @condy0919 Thanks for testing and review.