Setup Emacs for Rust on MacOS

  1. Install Rustup

curl -sSf | sh

you may need to uninstall existing rust on your machine

sudo /usr/local/lib/rustlib/

Install Racer

rustup component add rust-src
source $HOME/.cargo/env
cargo install racer

Start your emacs

make sure “melpa” is in your package-archives

(require 'package)
(add-to-list 'package-archives '("melpa" . ""))

 Make Sure you installed racer-mode and company packages, you can view activated packaged list by C-h v package-activated-list 

Add following code in your emacs init file

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)

(require 'rust-mode)
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t)

you can find your init file by M-: (Alt + Shift + ; ) and type (find-file user-init-file)

you can let emacs to eval your new setting by type M-x eval-buffer


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s