emend documentation¶
A multi-language refactoring CLI built on tree-sitter. The name means “to make corrections to a text” – which is what it does, but with AST-aware precision instead of find-and-replace. Two complementary systems:
Structured Edits – Precise changes to symbol metadata using selectors like
file.py::func[params][0]Pattern Transforms – Code-pattern search and replace with capture variables like
print($X)tologger.info($X)
Contents:
- Installation
- Quick Start
- Selector Syntax
- Commands Reference
- Pattern Syntax
- Metavariables
- Type constraints
- Basic patterns
- Compound statement patterns
- Decorator patterns
- Lambda patterns
- Star expression patterns
- Dict patterns
- Chained comparison patterns
- Walrus operator patterns
- Replacements
- Scope constraints
- Literal patterns (no metavariables)
- Multi-file search
- JSON output
- DSL patterns (
--dsl) - Limitations
- Linting
- Mappings
- Recipes
- Migrate from unittest to pytest
- Replace print with logging
- Set up a lint rule to catch prints
- Add type annotations to function returns
- Add a parameter to every method in a class
- Replace deprecated API calls
- Rename a class everywhere
- Move a helper function to another module
- Find all functions that raise a specific exception
- Audit all open() calls (check for missing encoding)
- Find all places a function is called
- Understand what a function depends on
- Find where a variable is mutated
- Extract and move a nested function
- Rename a module
- Batch-add a decorator to all async functions
- Multi-step refactoring with batch
- Use the canonical find command
- Find imports from a specific module
- Scope-aware pattern searching
- Find dict literals with specific keys
- Find walrus operator usage
- Find chained comparisons
- Embedded SQL analysis
- Navigate regex named groups
- Language Support
- emend Grammar & Cookbook
- Technical Details