Skip to content

vedang/tagref.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tagref.el

Emacs integration for tagref, a tool for managing cross-references in code.

Overview

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, and M-? to find all references of a tag
  • Validation via M-x tagref-check with clickable error locations
  • Browsing via M-x tagref-list-tags to see all tags in the project

images/tagref.png

Installation

Requirements

  • Emacs 28.1 or later
  • tagref CLI installed and available in your PATH

Manual Installation

(add-to-list 'load-path "/path/to/tagref.el")
(require 'tagref)

use-package

(use-package tagref
  :ensure t
  :hook (prog-mode . tagref-mode))

straight.el

(straight-use-package
 '(tagref :type git
          :host github
          :repo "vedang/tagref.el"))

Usage

Enabling the Mode

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.

Completion

When tagref-mode is active, type [ref: or [tag: and invoke completion:

KeyAction
C-M-iComplete tag name
M-TABComplete 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.

Navigation

Navigate between references and their definitions using standard xref keys:

KeyCommandAction
M-.xref-find-definitionsJump to tag definition
M-,xref-go-backReturn to previous location
M-?xref-find-referencesFind 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.

Validation

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:

KeyAction
RETGo to error
M-g M-nNext error
M-g M-pPrevious error
gRe-run check
qClose buffer

Tag Browser

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
KeyAction
RETJump to tag definition
gRefresh list
SSort by column
qClose buffer

Configuration

Custom Variables

;; Path to tagref executable (default: "tagref")
(setq tagref-executable "/path/to/tagref")

;; Additional arguments for tagref commands
(setq tagref-arguments '("--config" "custom.toml"))

Customization Interface

M-x customize-group RET tagref RET

Commands

CommandDescription
tagref-modeToggle tagref minor mode for the current project
tagref-checkRun tagref validation, show errors
tagref-list-tagsDisplay all tags in a browsable buffer

Development

Running Tests

make test    # Run Buttercup test suite
make check   # Run byte-compile, checkdoc, package-lint
make all     # Run everything

Project Structure

├── Makefile           # Build and test commands
├── README.org         # This file
├── tagref.el          # Main package
└── test/
    └── tagref-test.el # Buttercup tests

Troubleshooting

Completion not appearing

  1. Verify tagref-mode is active: Check for ” Tagref” in the mode line.
  2. Verify tagref CLI works: Run M-x tagref-list-tags to see if tags are found. If this shows no tags, check that tagref is in your PATH.
  3. Check CAPF is registered:
    (member 'tagref-completion-at-point completion-at-point-functions)
        
  4. With Corfu/Company: Completion should trigger automatically when you type ​[ref: or ​[tag:. If not, manually invoke with C-M-i or M-TAB.
  5. Debug the CAPF: Evaluate this with point inside a ​[ref: directive:
    (tagref-completion-at-point)
        

    It should return a list like (START END CANDIDATES ...).

tagref-check shows no clickable errors

The error regexp matches the format @ path/to/file:42. If your errors aren’t clickable, check that tagref output matches this format.

Performance with large projects

The package calls tagref list-tags on each completion. For very large projects, this may cause a delay. Consider:

  • Increasing corfu-auto-delay if using Corfu
  • Using M-x tagref-list-tags to browse tags instead

License

GPL-3.0-or-later. See the source file for details.

About

A minor mode to interact with the tagref CLI command

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published