diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-18 16:56:22 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-18 16:56:22 -0500 |
| commit | 11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed (patch) | |
| tree | 4b5c5b3da9cefe6b570f86fad0106f5d153c6a11 /modules/music-config.el | |
| parent | 4e63f665bf153203377f58161aa782a25ffd5e9f (diff) | |
| download | dotemacs-11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed.tar.gz dotemacs-11de26eb9ac5d79ac1303ff89dfd995fd18cd0ed.zip | |
feat(completion): right-align custom category annotations
marginalia-align has been right for months, but annotations from the custom completion categories (radio stations, music files, and everything built through the system-lib table helpers) never went through marginalia. They rendered unaligned. A registration helper adds a builtin registry entry per category at table construction, which routes the table's own annotation function through marginalia's aligned field. The radio table converts from an affixation function with hand-rolled padding to a plain annotation, since marginalia now owns the alignment. Self-maintaining: any future custom category built through the helpers registers itself.
Diffstat (limited to 'modules/music-config.el')
| -rw-r--r-- | modules/music-config.el | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/modules/music-config.el b/modules/music-config.el index e9095838..a70516e2 100644 --- a/modules/music-config.el +++ b/modules/music-config.el @@ -306,7 +306,9 @@ Directories are suffixed with /; files are plain. Hidden dirs/files skipped." "Completion table for CANDIDATES preserving order and case-insensitive match. Tags the `cj-music-file' category and annotates each candidate (a path relative to `cj/music-root', with a trailing slash for directories) with its size and -modification date so marginalia can show them." +modification date so marginalia can show them. The category is registered +with marginalia (builtin) so the annotations render right-aligned." + (cj/completion-ensure-marginalia-align 'cj-music-file) (let ((annotate (cj/completion-file-annotator (lambda (c) (expand-file-name @@ -1790,32 +1792,22 @@ to one station. Pure helper." (puthash disp t seen) (push (cons disp st) out))))) -(defun cj/music-radio--affixate (cands candidates) - "Affixation triples for CANDS with annotations aligned to one column. -CANDIDATES is the (DISPLAY . STATION) alist. Station names vary in width, -so each suffix pads out to the widest candidate plus a gutter; with the -fixed-width fields in `cj/music-radio--format-candidate' the listing reads -as aligned columns. The \"[done]\" sentinel has no station and gets no -annotation rather than a bogus zero row." - (let ((width (apply #'max 0 (mapcar #'string-width cands)))) - (mapcar (lambda (c) - (let ((st (cdr (assoc c candidates)))) - (list c "" - (if st - (concat (make-string (+ 3 (- width (string-width c))) ?\s) - (propertize (cj/music-radio--format-candidate st) - 'face 'completions-annotations)) - "")))) - cands))) - (defun cj/music-radio--completion-table (candidates) - "Completion table over CANDIDATES carrying the Variant-B marginalia affix." + "Completion table over CANDIDATES carrying the Variant-B annotation. +Tagged `cj-radio-station' and registered with marginalia (builtin), so the +codec/bitrate/country/votes/tags annotation renders right-aligned like the +stock categories. The \"[done]\" sentinel has no station and annotates as +nil rather than a bogus zero row." + (cj/completion-ensure-marginalia-align 'cj-radio-station) (lambda (string pred action) (if (eq action 'metadata) `(metadata (category . cj-radio-station) - (affixation-function - . ,(lambda (cands) (cj/music-radio--affixate cands candidates)))) + (annotation-function + . ,(lambda (c) + (when-let ((st (cdr (assoc c candidates)))) + (concat " " (propertize (cj/music-radio--format-candidate st) + 'face 'completions-annotations)))))) (complete-with-action action (mapcar #'car candidates) string pred)))) (defun cj/music-radio--pick-loop (candidates) |
