An Emacs interface to ast-grep, a CLI tool for code structural search, lint and rewriting based on Abstract Syntax Tree patterns.
- Search code using ast-grep patterns with completing-read interface
- Project-wide search support
- Integration with completing-read frameworks (Vertico, etc.)
- Streaming JSON parsing for efficient processing
- Async search with live results when consult is available
- Emacs 28.1 or later
- ast-grep CLI tool installed and available in PATH
ast-grep
is available on MELPA. Install it using M-x package-install
command or your preferred package manager:
(use-package ast-grep :ensure t)
Add to your packages.el
:
(package! ast-grep)
(straight-use-package '(ast-grep :type git :host github :repo "SunskyXH/ast-grep.el"))
- Clone the repository:
git clone https://github.com/SunskyXH/ast-grep.el.git
- Add to your Emacs configuration:
(add-to-list 'load-path "/path/to/ast-grep.el") (require 'ast-grep)
ast-grep-search
- Search for patterns in current directoryast-grep-project
- Search for patterns in current projectast-grep-directory
- Search for patterns in specified directory
Enable ast-grep-mode
for ast-grep integration (useful for configuration hooks).
Customize the following variables:
ast-grep-executable
- Path to ast-grep executable (default: “ast-grep”)ast-grep-debug
- Enable debug output for troubleshooting (default: nil)ast-grep-async-min-input
- Minimum input length before triggering async search (default: 3)