Open GaryBlackbourne opened 2 years ago
I too remember getting this error message: Could not locate executable "rustfmt".
I think your approach to fix the issue is fine. More approaches follow.
Note there's also a customizable variable rust-rustfmt-bin
, which is set to rustfmt
by default. This variable can be changed to the full path to the rustfmt
executable.
Now I wonder, might be ~/.cargo/bin/rustfmt
would be a better default (with similar change for rust-cargo-bin
)?
Or add rustfmt
directory to Emacs'
exec-path
variable (PATH
and Emacs
is a separate topic you can quite easily find information about).
For instance,
(add-to-list 'exec-path "~/.cargo/bin")
As for the README or code changes, I suspect this repo maintainers would be glad to consider/accept PRs with the improvements. Or consider adding a Wiki note on this. Though might be Discussions, if enabled, could be a better place for the topic we're in now.
Now I wonder, might be ~/.cargo/bin/rustfmt would be a better default (with similar change for rust-cargo-bin)?
We've already had this discussion several times and I've also changed it several times over the last years =)
As you already mentioned, this is an emacs issue not rust-mode.
Have you guys tried https://github.com/purcell/exec-path-from-shell ?
We've already had this discussion several times and I've also changed it several times over the last years
Not surprised.
Have you guys tried https://github.com/purcell/exec-path-from-shell ?
I tried it, but now happily live without it. BTW, my previous message contains a link to the SO thread that suggests this package among the other things.
I wonder why this still wasn't fixed in emacs. doom-emacs seem to have solved it.
doom-emacs seem to have solved it.
Looks like doom-emacs
generates a file with correct environment variables. There's an interesting comparison to exec-path-from-shell
below in that file too.
why this still wasn't fixed in emacs
I see this topic was mentioned several times on the dev/bug mailing lists and an overall impression I got:
Emacs
starts with the variables of the shell it's launched from. AFAIU, the Mac OS
users are affected the most, because Mac GUI
applications do not inherit shell variables by default (there're tweaks).
I have installed rust following the guide on rusts website, and installed rust-mode through melpa. When I put the autoformat on save hook into my
.emacs
file, it failed to findrustfmt
in my~/.cargo/bin
directory even if this is part of myPATH
variable.I fixed this with creating a simlink in my
/usr/local/bin
directory, and now, it seems to work. I think it might be good to add this to README or otherwise make it work with default install.