sharing my configuration for coding Rust with emacs

29 views
Skip to first unread message

Chakravarthy Raghunandan

unread,
May 22, 2017, 3:19:20 PM5/22/17
to Rust Bangalore Community
I had discovered some really neat refactoring tricks while browsing through the emacs configuration of a very popular contributor to emacs.

Here is the link to my emacs configuration for Rust: https://github.com/CSRaghunandan/.emacs.d/blob/master/setup-files/setup-rust.el

Some useful features:
1. Toggle the mutability of a variable at point
2. Toggle the public visibility of the function at point
3. Convert the vector expression at point to slice foo -> &foo[..]
4. Run the test at point
5. have a local playground for trying out rust snippets
6. automatically format the file with Rustfmt upon saving
7. Shortcuts for executing all cargo commands
8. linting using rustc error + warning messages
9. Autocomplete and jump to definition of variables, functions, types, etc. using Racer

Regards,
Raghunandan

Saifi

unread,
May 22, 2017, 9:07:01 PM5/22/17
to Rust Bangalore Community


Very nifty and interesting. Thanks so much for sharing, 'o wizard of emacs' !

setup-rust.el file contains reference to the following

https://github.com/rust-lang/rust-mode
https://github.com/flycheck/flycheck-rust
https://github.com/kwrooijen/cargo.el
https://github.com/racer-rust/emacs-racer

Could you please share your thoughts about how the variables and functions are accessed when multiple emacs lisp files are referenced ?

This would help folks, with exploring further.


warm regards
Saifi.

Chakravarthy Raghunandan

unread,
May 23, 2017, 5:33:04 AM5/23/17
to Rust Bangalore Community

No need to worry about the elisp files. Just copy over the below lines to the init file: ~/.emacs or ~/.emacs.d/init.el . (you might need to create the file if they don't exist):


(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)

(unless (package-installed-p 'use-package) ; unless it is already installed
(package-refresh-contents) ; updage packages archive
(package-install 'use-package)) ; install the latest version of use-package
(eval-when-compile (require 'use-package))
(setq use-package-always-ensure t)

And copy over the contents of setup-rust.el to your init file (either of the two files I mentioned above) and open emacs. It should automatically download all dependencies and your Rust setup is ready :)

Saifi

unread,
Jun 14, 2017, 4:56:24 AM6/14/17
to Rust Bangalore Community

This is cool.

Is there something similar to this for vi or zile ?

Chakravarthy Raghunandan

unread,
Jun 14, 2017, 6:17:38 AM6/14/17
to rus...@googlegroups.com
Hi Saifi,

I do not know much about vi/vim and their plugin ecosystem. But there is a way to bootstrap your vim/neovim configuration: https://vim-bootstrap.com/. Maybe you can checkout the Rust configuration there and load it to your ~/.vimrc


--
https://meetup.com/rustox
---
You received this message because you are subscribed to a topic in the Google Groups "Rust Bangalore Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rustox/M_uWStsJFZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rustox+unsubscribe@googlegroups.com.
To post to this group, send email to rus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards,
Raghunandan

Saifi

unread,
Jun 14, 2017, 7:10:54 AM6/14/17
to Rust Bangalore Community
> To unsubscribe from this group and all its topics, send an email to rustox+un...@googlegroups.com.
>
> To post to this group, send email to rus...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>
> --
>
>
>
> Thanks and Regards,
> Raghunandan


Thanks Raghu.

Will take a close look at this.


warm regards
Saifi.
Reply all
Reply to author
Forward
0 new messages