ilemming · 2022-05-12 17:05
I've recently needed to make a minibuffer completion with annotations. The [manual says](https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-Variables.html) you need to set `completion-extra-properties`, and I was able to make annotations, my `:annotation-function` looks something like this:
(defun my-annotation-fn (s)
(let-alist (cdr (assoc s minibuffer-completion-table))
(concat " " .version " " .description)))
Now, this works, but the annotations do not show up aligned (because every column in each row is delimited by fixed number of spaces), and that doesn't look very clean.
Of course, it is possible to calculate the exact number of required spaces for every column in each row, even though it would slightly sophisticate the annotation-function.
Another alternative (I think) is to extend the prompt for Marginalia and let it do its magic. But then it would only work for those who use Marginalia package.
So my question is, is there a convention or a simpler method of aligning the annotations?
bdarcus · 2022-05-12 17:27
Unfortunately no; at least not that I'm aware of.
[Here's a simple annotation function](https://github.com/bdarcus/citar/blob/9a6fc6da11ad2b475244cc4cbd51c77615e9aad3/citar-org.el#L246-L252) I wrote that includes the alignment.
Ideally we'd see improvements in completing-read in the future that could take care of this. There was a thread with some interesting ideas awhile back on emacs-devel about a possible "decoration function". But nothing has come of that so far.
_viz_ · 2022-05-13 03:23
FWIW, I used TAB before the annotation string in a command that I wrote and it aligned just fine for candidates that have the same length (1 or 2 in my case).
JDRiverRun · 2022-05-13 03:51
Including alignment with the annotation data is not ideal. But no good way to separate data from presentation has emerged. [Here's](https://github.com/minad/consult/issues/565#issuecomment-1114047219) a good overview of the situation by minad. Key quote:
>All these points hint at that we should move the entire alignment and truncation business to the frontend instead of scattering across backends and middleware.