diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-27 12:55:58 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-27 12:55:58 -0400 |
| commit | f9d9e003a208c22cd4d390125d990b79a4c0a0e7 (patch) | |
| tree | e2b414ec00c04a5a30d0292770cefc861eace14f /modules/system-lib.el | |
| parent | fd2fb02ab77eca1b7a75fe40aac33d5fedd3dac0 (diff) | |
| download | dotemacs-f9d9e003a208c22cd4d390125d990b79a4c0a0e7.tar.gz dotemacs-f9d9e003a208c22cd4d390125d990b79a4c0a0e7.zip | |
feat(completion): tag four pickers with categories for marginalia
Add cj/completion-table (and an annotated variant) to system-lib: a wrapper that tags any collection with a completion category so marginalia, embark, consult, and sorting can recognize the candidates. None of the config's completing-reads declared a category, so the rich-candidate pickers showed bare. This applies it to the four whose candidates match a standard category and so need no custom annotator: benchmark-method (function), ERC buffer switch (buffer), ai-term close (buffer), and theme switch (theme). Each now annotates for free.
Diffstat (limited to 'modules/system-lib.el')
| -rw-r--r-- | modules/system-lib.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/system-lib.el b/modules/system-lib.el index 49bb6cd1a..8b954c6a9 100644 --- a/modules/system-lib.el +++ b/modules/system-lib.el @@ -164,6 +164,29 @@ contributes its own modes regardless of load order." (setq font-lock-global-modes (cj/--font-lock-global-modes-excluding font-lock-global-modes mode)))) +(defun cj/completion-table (category collection) + "Return a completion table over COLLECTION tagged with completion CATEGORY. +COLLECTION is anything `completing-read' accepts (list, alist, obarray, hash +table, or another table). The table reports CATEGORY in its metadata so +marginalia (and embark, consult, sorting) can recognize and annotate the +candidates. Use a standard category (file, buffer, function, theme, ...) when +the candidates match one; marginalia then annotates them with no further work." + (lambda (string predicate action) + (if (eq action 'metadata) + `(metadata (category . ,category)) + (complete-with-action action collection string predicate)))) + +(defun cj/completion-table-annotated (category annotate collection) + "Like `cj/completion-table' but also attach ANNOTATE as the annotation function. +ANNOTATE is called with a candidate string and returns its annotation suffix, or +nil. Use this for a custom CATEGORY that marginalia has no built-in annotator +for: marginalia falls back to the table's own annotation function." + (lambda (string predicate action) + (if (eq action 'metadata) + `(metadata (category . ,category) + (annotation-function . ,annotate)) + (complete-with-action action collection string predicate)))) + (defun cj/format-region-with-program (program &rest args) "Replace the current buffer with PROGRAM ARGS run over its contents, via argv. Runs PROGRAM (with ARGS) on the whole buffer through `call-process-region' |
