minad / marginalia

:scroll: marginalia.el - Marginalia in the minibuffer
GNU General Public License v3.0
780 stars 27 forks source link

Column alignment failure using marginalia--fields #178

Closed mgsb closed 3 months ago

mgsb commented 3 months ago

While using marginalia--fields in an annotator function, column alignment fails, most likely due to pilot error. The face attributes work correctly. This is for a mode that includes installing MicroPython (non-emacs) packages so the default annotator can't be used. The relevant functions:

(defun mp--package-annotator (pkg-list pkg-name)
  "Annotate the candidate PKG-NAME using metadata in PKG-LIST."
  (let* ((pkg (assoc (intern pkg-name) pkg-list))
         (description (cdr (assoc 'description pkg)))
         (version (cdr (assoc 'version pkg))))
    (if (fboundp 'marginalia--fields)
        (marginalia--fields
         (version :face 'marginalia-version)
         (description :face 'marginalia-documentation))
      (format "    %s - %s" version description))))

(defun mp-install-package ()
  "Query for one or more MicroPython packages to install using `mip install`."
  (interactive)
  (when (boundp 'marginalia-command-categories)
    (unless (assoc (intern  "mp-install-package") marginalia-command-categories)
      (add-to-list 'marginalia-command-categories
                   '(mp-install-package . not-emacs-package))))
  (let* ((pkg-list (mp--fetch-index))
         (completion-extra-properties `(:annotation-function ,(apply-partially 'mp--package-annotator pkg-list)))
         (pkgs (completing-read-multiple "Package: " pkg-list)))
    (message (format "installing: %s ..." (string-join pkgs " ")))
    (mp--install pkgs t)))

Any suggestions/corrections appreciated.