rude.el is an Emacs package that enhances your development workflow by providing context-aware commands to run and debug code under the point. The name “rude” is a combination of RUn and DEbug, reflecting its core purpose.
It extends the built-in M-x compile and the popular debugging framework dape to intelligently suggest and execute relevant commands based on the code structure. This allows you to quickly run a single test, a whole test class, a Rust binary, or an example from a Cargo project without leaving your current context.
Features:
- Context-Aware Execution: Automatically detects the test method, class, or runnable project under the cursor.
- Seamless Debugging: Integrates with
dapeto start a debugging session for the code under the point with a single command. - Extensible: While it heavily relies on tree-sitter for accurate code parsing, it can be extended to support modes that do not have tree-sitter support.
rude-compile.webm
rude-debug.webm
You can install rude.el from MELPA. Here is an example using use-package:
(use-package rude
:ensure t
:init (rude-mode))Once installed and enabled, you can interact with the package as follows:
Running Commands with =M-x compile=
The main interface for running commands is through M-x compile (or M-x project-compile). With rude-mode enabled, rude.el populates the “future history” of the compile command.
- Place your cursor on a piece of code you want to run (e.g., a test function).
- Invoke
M-x compile. - Instead of pressing
M-pto access past commands, pressM-nto cycle through the context-aware suggestions provided byrude.el. - Press
RETto execute the suggested command.
Debugging with =dape=
For debugging, rude.el integrates with the dape package. It automatically sets the dape-command variable based on the code under the cursor, if it’s not already set.
- Place your cursor on a piece of code you want to debug.
- Invoke
M-x dape. - The command prompt will be pre-filled with the appropriate debug command.
- Press
RETto start the debug session.
| Language | Supported Runners | Debugging with dape |
|---|---|---|
| Python | pytest, unittest | Yes |
| Rust | Cargo | Yes |
There are several other packages that provide similar functionality:
- vim-test: A popular Vim plugin that provides a similar “run test under cursor” feature.
rude.elprovides a similar experience in Emacs. - quickrun.el: A generic runner for executing code snippets, but it is not as context-aware as
rude.elfor running tests or specific project targets. - Language-specific packages: Many language-specific packages (e.g.,
python.el,rust-mode) have their own functions for running tests.rude.elaims to provide a unified and consistent interface across different languages.
rude.el uses tree-sitter to parse the source code and identify the relevant code constructs (e.g., functions, classes, modules). This allows for a high degree of accuracy in its suggestions. The architecture is designed to be extensible, so support for new languages or runners can be added easily. In principle, it could be extended to support non tree-sitter enabled modes by using other parsing techniques.