{"id":13438025,"url":"https://github.com/rust-lang/rust-mode","last_synced_at":"2025-05-14T13:02:46.194Z","repository":{"id":26550626,"uuid":"30004263","full_name":"rust-lang/rust-mode","owner":"rust-lang","description":"Emacs configuration for Rust","archived":false,"fork":false,"pushed_at":"2025-04-23T00:15:15.000Z","size":958,"stargazers_count":1172,"open_issues_count":66,"forks_count":185,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-05-08T00:03:51.504Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rust-lang.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-29T04:53:17.000Z","updated_at":"2025-05-07T06:55:36.000Z","dependencies_parsed_at":"2025-04-05T14:01:37.655Z","dependency_job_id":"d7049420-b9c9-4bee-acd4-3ab437c194ec","html_url":"https://github.com/rust-lang/rust-mode","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frust-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frust-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frust-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rust-lang%2Frust-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rust-lang","download_url":"https://codeload.github.com/rust-lang/rust-mode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149654,"owners_count":22022846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:02.275Z","updated_at":"2025-05-14T13:02:46.164Z","avatar_url":"https://github.com/rust-lang.png","language":"Emacs Lisp","readme":"# rust-mode\n\n[![NonGNU ELPA](https://elpa.nongnu.org/nongnu/rust-mode.svg)](https://elpa.nongnu.org/nongnu/rust-mode.html)\n[![MELPA](https://melpa.org/packages/rust-mode-badge.svg)](https://melpa.org/#/rust-mode)\n[![](https://github.com/rust-lang/rust-mode/workflows/CI/badge.svg)](https://github.com/rust-lang/rust-mode/actions?query=workflow%3ACI)\n\n\u003c!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --\u003e\n**Table of Contents**\n\n- [rust-mode](#rust-mode)\n    - [Introduction](#introduction)\n    - [Known issues](#known-issues)\n    - [Installation](#installation)\n        - [Melpa](#melpa)\n        - [Manual installation](#manual-installation)\n    - [Feature guide](#feature-guide)\n        - [Indentation](#indentation)\n        - [Code formatting](#code-formatting)\n        - [Prettifying](#prettifying)\n        - [Running / testing / compiling code](#running--testing--compiling-code)\n        - [Clippy](#clippy)\n        - [Easy insertion of dbg!](#easy-insertion-of-dbg)\n        - [More commands](#more-commands)\n    - [tree-sitter](#tree-sitter)\n    - [LSP](#lsp)\n        - [eglot](#eglot)\n        - [lsp-mode](#lsp-mode)\n    - [Auto-completion](#auto-completion)\n    - [Other recommended packages](#other-recommended-packages)\n        - [flycheck](#flycheck)\n        - [cargo.el](#cargoel)\n        - [cargo-mode](#cargo-mode)\n        - [rustic](#rustic)\n    - [Optional features](#optional-features)\n    - [For package maintainers](#for-package-maintainers)\n        - [Tests](#tests)\n    - [Contributing](#contributing)\n\n\u003c!-- markdown-toc end --\u003e\n\n## Introduction\n\n`rust-mode` makes editing [Rust](http://rust-lang.org) code with Emacs\nenjoyable. It requires Emacs 25 or later, and is included in both\n[Emacs Prelude](https://github.com/bbatsov/prelude) and\n[Spacemacs](https://github.com/syl20bnr/spacemacs) by default.\n\nThis mode provides:\n- Syntax highlighting (for Font Lock Mode)\n- Indentation\n- Integration with Cargo, clippy and rustfmt\n\nThis mode does _not_ provide auto completion, or jumping to function /\ntrait definitions. See [Auto-completion](#auto-completion) below for tips on how\nto enable this.\n\nIf you are missing features in rust-mode, please check out\n[rustic](https://github.com/emacs-rustic/rustic) before you open a feature\nrequest. It depends on rust-mode and provides additional features. This\nallows us to keep rust-mode light-weight for users that are happy with\nbasic functionality.\n\n## Known issues\n\n- `rust-syntax-propertize` and `adaptive-wrap-prefix-mode` can lead to\n  severe lag when editing larger files\n  (https://github.com/brotzeit/rustic/issues/107)\n\n## Installation\n\n### Melpa\n\nThe package is available on MELPA. Add this to your init.el.\n\n``` elisp\n(require 'package)\n(add-to-list 'package-archives\n             '(\"melpa\" . \"https://melpa.org/packages/\") t)\n(package-initialize)\n(package-refresh-contents)\n```\n\nNow you can install `rust-mode` with:\n\n`M-x package-install rust-mode`\n\nAnd put this in your config to load rust-mode automatically:\n\n`(require 'rust-mode)`\n\n### NonGNU ELPA\n\n[NonGNU ELPA](https://elpa.nongnu.org/) can be used out of the box in\nemacs28.\n\nFor older versions you need to add something like the following to\nyour init file:\n\n``` elisp\n(with-eval-after-load 'package (add-to-list 'package-archives '(\"nongnu\" . \"https://elpa.nongnu.org/nongnu/\")))\n```\n\n### Manual installation\n\nClone this repository locally, and add this to your init.el:\n\n``` elisp\n(add-to-list 'load-path \"/path/to/rust-mode/\")\n(autoload 'rust-mode \"rust-mode\" nil t)\n(add-to-list 'auto-mode-alist '(\"\\\\.rs\\\\'\" . rust-mode))\n```\n\n## Feature guide\n\n### Indentation\n\nCommands like \u003ckbd\u003eTAB\u003c/kbd\u003e should indent correctly.\n\nThe Rust style guide recommends spaces rather than tabs for\nindentation; to follow the recommendation add this to your init.el,\nwhich forces indentation to always use spaces.\n\n```elisp\n(add-hook 'rust-mode-hook\n          (lambda () (setq indent-tabs-mode nil)))\n```\n\nSince Emacs ≥ 24.4, [`electric-indent-mode`][] is turned on by\ndefault. If you do not like it, call `(electric-indent-mode 0)` in\n`rust-mode-hook`.\n\n[`electric-indent-mode`]: https://www.gnu.org/software/emacs/manual/html_node/emacs/Indent-Convenience.html\n\n### Code formatting\n\nThe `rust-format-buffer` function will format your code with\n[rustfmt](https://github.com/rust-lang/rustfmt) if installed. By\ndefault, this is bound to \u003ckbd\u003eC-c C-f\u003c/kbd\u003e.\n\nThe variable `rust-format-on-save` enables automatic formatting on\nsave. For example, add the following in your init.el to enable format\non save:\n\n``` elisp\n(setq rust-format-on-save t)\n```\n\n### Prettifying\n\nYou can toggle prettification of your code by running `M-x\nprettify-symbols-mode`.  If you'd like to automatically enable this\nfor all rust files, add the following to your init.el.\n\n```elisp\n(add-hook 'rust-mode-hook\n          (lambda () (prettify-symbols-mode)))\n```\n\nYou can add your own prettifications to `rust-prettify-symbols-alist`.\nFor example, to display `x.add(y)` as `x∔(y)`, simply add to your init\nfile `(push '(\".add\" . ?∔) rust-prettify-symbols-alist)`.\n\n### Running / testing / compiling code\n\nThe `rust-run`, `rust-test`, `rust-compile` and `rust-check` functions\nshell out to Cargo to run, test, build and check your code. Under the\nhood, these use the standard Emacs `compile` function.\n\nBy default these are bound to:\n\n- \u003ckbd\u003eC-c C-c C-u\u003c/kbd\u003e `rust-compile`\n- \u003ckbd\u003eC-c C-c C-k\u003c/kbd\u003e `rust-check`\n- \u003ckbd\u003eC-c C-c C-t\u003c/kbd\u003e `rust-test`\n- \u003ckbd\u003eC-c C-c C-r\u003c/kbd\u003e `rust-run`\n\nTo run programs requiring user input use universal argument when invoking\n `rust-run` (\u003ckbd\u003eC-u C-c C-c C-r\u003c/kbd\u003e).\n\n### Clippy\n\n`rust-run-clippy` runs\n[Clippy](https://github.com/rust-lang/rust-clippy), a linter. By\ndefault, this is bound to \u003ckbd\u003eC-c C-c C-l\u003c/kbd\u003e.\n\n### Easy insertion of dbg!\n\n`rust-dbg-wrap-or-unwrap` either wraps or unwraps the current region\nin `dbg!`. This can be useful for easily adding debug lines to your\nprogram.\n\nThis is bound to \u003ckbd\u003eC-c C-d\u003c/kbd\u003e by default.\n\n### More commands\n\n- `rust-toggle-mutability` toggle mut for var defined at current line\n\n## tree-sitter\n\nYou can try the new native treesitter mode `rust-ts-mode` with:\n\n```elisp\n(use-package rust-mode\n  :init\n  (setq rust-mode-treesitter-derive t))\n```\n\nIn case you want to use treesitter but can't use Emacs 29.1, you can\ntake a look at\n[tree-sitter](https://github.com/emacs-tree-sitter/elisp-tree-sitter). When\nthe dependencies are installed you can activate the feature with:\n\n```elisp\n(use-package tree-sitter\n  :config\n  (require 'tree-sitter-langs)\n  (global-tree-sitter-mode)\n  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))\n```\n\n## LSP\n\n### eglot\n\nA lightweight lsp client.\n\n```elisp\n(add-hook 'rust-mode-hook 'eglot-ensure)\n```\n\n### lsp-mode\n\nProvides more features and you can enhance the functionality\nby using additional packages. You can find more information in the\n[lsp-mode wiki](https://emacs-lsp.github.io/lsp-mode/page/installation/#vanilla-emacs).\n\n```elisp\n(add-hook 'rust-mode-hook #'lsp)\n```\n\n## Auto-completion\n\nYou can either use a lsp client or [racer](https://github.com/racer-rust/racer)\nwith [emacs-racer](https://github.com/racer-rust/emacs-racer#installation).\n\nNote that racer and rls are considered deprecated. You should use rust-analyzer\ninstead.\n\n## Other recommended packages\n\n### flycheck\n\n[flycheck](https://github.com/flycheck/flycheck) allows highlighting\ncompile errors and Clippy lints inline.\n\n### cargo.el\n\n[cargo.el](https://github.com/kwrooijen/cargo.el) provides a minor\nmode for integration with Cargo, Rust's package manager.\n\n### cargo-mode\n\n[cargo-mode](https://github.com/ayrat555/cargo-mode) is an Emacs minor\nmode which allows to dynamically select a Cargo command. The reasons\nbehind this package can be found in [the\npost](https://www.badykov.com/emacs/2021/05/29/emacs-cargo-mode/).\n\n### rustic\n\n[rustic](https://github.com/emacs-rustic/rustic) is based on rust-mode,\nextending it with other features such as integration with LSP and with\nflycheck.\n\n## Optional features\n\nThe features of the following files can be disabled with `rust-load-optional-libraries`.\n\n- rust-cargo.el\n- rust-compile.el\n- rust-playpen.el\n- rust-rustfmt.el\n\nThey are disabled by default when you use rustic as it has its own implementations\nfor those features.\n\n## Customization\n\n`rust-cargo-default-arguments` set additional cargo args used for check,compile,run,test\n\n## For package maintainers\n\n### Tests\n\nRun elisp tests:\n\n``` bash\nmake test\n```\n\n## Contributing\n\nContributions are very welcome. We are also looking for additional maintainers.\n","funding_links":[],"categories":["Development tools","开发工具 Development tools","Emacs Lisp","开发工具"],"sub_categories":["IDEs","编译器 IDEs","集成开发环境(IDE)","编辑器 IDEs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-lang%2Frust-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frust-lang%2Frust-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frust-lang%2Frust-mode/lists"}