6/26/2023 0 Comments Doom emacs tutorialYou can still format a buffer on demand using C-c C-c C-o. To disable it set (setq rustic-format-on-save nil). If you would like to share a code snippet with others, M-x rustic-playpen will open your current buffer in where you can run the Rust code online and get a shareable link.Ĭode formatting on save is enabled and will use rustfmt. M-x rustic-cargo-add will allow you to add dependencies to your projects Cargo.toml (via cargo-edit that will be installed on demand). Rustic provides even more helpful integration with cargo, e.g. Very handy to run inline tests and to not always have switch back-and-forth between a terminal and Emacs.Ĭ-c C-p opens a popup buffer that will give you similar access to the commands shown above but will stick around. The shortcut C-c C-c C-c will run the test at point. To pass parameters to the executable itself use -arg1 -arg2. You will be asked for parameters and can for example specify -release to run in release mode or -bin other-bin to run the target named “other-bin” (instead of main.rs). You can use C-c C-c C-r to run the program via cargo run. Most of rustics features are bound to the C-c C-c prefix (that is press Control-c twice and then another key): (add-hook 'before-save-hook 'lsp-format-buffer nil t)) (setq-local buffer-save-without-query t)) save rust buffers that are not file visiting. so that run C-c C-c C-r works without having to confirm, but don't try to (add-hook 'rustic-mode-hook 'rk/rustic-mode-hook)) (setq lsp-enable-symbol-highlighting nil) It is the core of the setup and you can use just it without any other Emacs packages (and without rust-analyzer) if you just want code highlighting, compilation and cargo commands bound to emacs shortcuts, and a few other features. Rustic is an extension of rust-mode which adds a number of useful features (see the its github readme) to it. The essential modes being used are the following: Otherwise you can add a snippet like below to your init.el: (unless (package-installed-p 'use-package) It will be auto-installed in the standalone version of this config. Note that I use use-package for Emacs package management. Note that the config will likely work with older Emacs versions but Emacs 27 got substantial improvements around JSON parsing which speeds up LSP clients quite a bit. On Ubuntu adding another apt repository is necessary. On Windows I use the “nearby GNU mirror” link at gnu.org/software/emacs. This should work with older versions of the relevant emacs packages as well. The rksm/emacs-rust-config github repo contains a standalone.el file that you can use to start Emacs with: If you have already Rust and Emacs installed (see prerequisites) you can get quickly up and running without modifying any of your existing configuration. : add lsp-rust-analyzer-server-display-inlay-hints.: rust-analyzer installation / compatibility note.: Note about broken lsp-lens-mode / inlay hints.: Inlay hints fixed & more inlay hints available. : Clarified that rustic derives from rust-mode.: Note about potential LSP :: rust-analyzer failed to discover workspace error (thanks Fred Xia!).: Use lsp-format-buffer instead of rustic-format-on-save.: Currently inlay hints on rust-analyzer versions newer than won’t work.I’ve tested the configuration with Emacs 28.2, rust stable 1.66.0 and on macOS 13.1, Ubuntu 22.04 and Windows 10.įor a setup that uses the emacs-racer backend 1 please see David Crook’s guide. This post is accompanied by a github repository that you can use as a reference or directly checkout and run Emacs with ( see below). This setup will be based on rust-analyzer, a LSP server that is under very active development and powers the Rust support in VS Code as well. Building & running other cargo commands.Automatically import definitions if necessary (such as for Traits).Highlighting errors and warnings inline.Navigating the source code (go to to implementation, list references, outline module structure).This post will walk you through setting up Emacs to allow for: Rust support in Emacs improved a lot during the past two years.
0 Comments
Leave a Reply. |