Emacs integration for tagref, a tool for managing cross-references in code.
Tagref helps you maintain cross-references in your codebase using simple tags:
[tag:name]defines a tag[ref:name]references a tag
This package provides Emacs support for working with these directives:
- Completion for
[ref:]and[tag:]with existing tag names - Navigation via
M-.to jump from a reference to its tag definition, andM-?to find all references of a tag - Validation via
M-x tagref-checkwith clickable error locations - Browsing via
M-x tagref-list-tagsto see all tags in the project
- Emacs 28.1 or later
- tagref CLI installed and available in your
PATH
(add-to-list 'load-path "/path/to/tagref.el")
(require 'tagref)(use-package tagref
:ensure t
:hook (prog-mode . tagref-mode))(straight-use-package
'(tagref :type git
:host github
:repo "vedang/tagref.el"))Enable tagref-mode in any buffer:
M-x tagref-mode
tagref-mode understands projects as defined by project.el and will
be turned on for all buffers of that project.
When tagref-mode is active, type [ref: or [tag: and invoke
completion:
| Key | Action |
|---|---|
C-M-i | Complete tag name |
M-TAB | Complete tag name (same) |
Completions show the tag name with its file location:
polynomial_nonzero src/math.rs:42 path_default src/main.rs:93
Smart conversion: When completing [tag: and you select an existing
tag, the directive is automatically converted to [ref: to prevent
duplicates.
Navigate between references and their definitions using standard xref keys:
| Key | Command | Action |
|---|---|---|
M-. | xref-find-definitions | Jump to tag definition |
M-, | xref-go-back | Return to previous location |
M-? | xref-find-references | Find all references to tag |
Place your cursor inside a [ref:name] and press M-. to jump to
where the tag is defined.
When on a [tag:name], press M-? to find all references. The
results include the tag definition as the first entry for context. If
there are no references, a message is shown.
Run tagref’s validation to find broken references:
M-x tagref-check
This opens a compilation buffer with any errors. Click on an error
(or press RET) to jump to that location.
Standard compilation-mode keys work:
| Key | Action |
|---|---|
RET | Go to error |
M-g M-n | Next error |
M-g M-p | Previous error |
g | Re-run check |
q | Close buffer |
Browse all tags in the project:
M-x tagref-list-tags
This shows a sortable table of all tags:
Tag File Line polynomial_nonzero src/math.rs 42 path_default src/main.rs 93 tag_sigil_default src/main.rs 103
| Key | Action |
|---|---|
RET | Jump to tag definition |
g | Refresh list |
S | Sort by column |
q | Close buffer |
;; Path to tagref executable (default: "tagref")
(setq tagref-executable "/path/to/tagref")
;; Additional arguments for tagref commands
(setq tagref-arguments '("--config" "custom.toml"))M-x customize-group RET tagref RET
| Command | Description |
|---|---|
tagref-mode | Toggle tagref minor mode for the current project |
tagref-check | Run tagref validation, show errors |
tagref-list-tags | Display all tags in a browsable buffer |
make test # Run Buttercup test suite
make check # Run byte-compile, checkdoc, package-lint
make all # Run everything├── Makefile # Build and test commands
├── README.org # This file
├── tagref.el # Main package
└── test/
└── tagref-test.el # Buttercup tests
- Verify tagref-mode is active: Check for ” Tagref” in the mode line.
- Verify tagref CLI works: Run
M-x tagref-list-tagsto see if tags are found. If this shows no tags, check thattagrefis in your PATH. - Check CAPF is registered:
(member 'tagref-completion-at-point completion-at-point-functions)
- With Corfu/Company: Completion should trigger automatically when you type
[ref:or[tag:. If not, manually invoke withC-M-iorM-TAB. - Debug the CAPF: Evaluate this with point inside a
[ref:directive:(tagref-completion-at-point)It should return a list like
(START END CANDIDATES ...).
The error regexp matches the format @ path/to/file:42. If your errors
aren’t clickable, check that tagref output matches this format.
The package calls tagref list-tags on each completion. For very large
projects, this may cause a delay. Consider:
- Increasing
corfu-auto-delayif using Corfu - Using
M-x tagref-list-tagsto browse tags instead
GPL-3.0-or-later. See the source file for details.
