Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ rude.el Public

Run and debug thing under the cursor!

hron/rude.el

Repository files navigation

rude.el - Run and Debug Seamlessly in Emacs

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 dape to 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.

Demo

Running a test under the cursor

rude-compile.webm

Debugging a test

rude-debug.webm

Installation and Usage

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.

  1. Place your cursor on a piece of code you want to run (e.g., a test function).
  2. Invoke M-x compile.
  3. Instead of pressing M-p to access past commands, press M-n to cycle through the context-aware suggestions provided by rude.el.
  4. Press RET to 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.

  1. Place your cursor on a piece of code you want to debug.
  2. Invoke M-x dape.
  3. The command prompt will be pre-filled with the appropriate debug command.
  4. Press RET to start the debug session.

Supported Languages

LanguageSupported RunnersDebugging with dape
Pythonpytest, unittestYes
RustCargoYes

Alternatives

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.el provides a similar experience in Emacs.
  • quickrun.el: A generic runner for executing code snippets, but it is not as context-aware as rude.el for 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.el aims to provide a unified and consistent interface across different languages.

Technical Details

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.

About

Run and debug thing under the cursor!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published