diff --git a/racket-complete.el b/racket-complete.el index 3e7c1b07..25315d45 100644 --- a/racket-complete.el +++ b/racket-complete.el @@ -89,8 +89,8 @@ displaying inappropriate annotations." (_ (complete-with-action action completions prefix predicate))))) -(defun racket--affix (prop min-widths strs) - "Use with `apply-partially' to make an :affixation-function. +(defun racket--make-affix (min-widths &optional prop) + "Make an :affixation-function that aligns suffix columns. PROP is the symbol name of a text property that must be attached to all of the STRS, the value of which is a list of strings -- @@ -109,48 +109,50 @@ property -- as is done by `racket--doc-index-make-alist' -- ignore that for purposes of calculating widths." ;; Note: Below we use `cl-loop' because `seq-do-indexed' and ;; `seq-map-indexed' are unavailable in Emacs 25. - (let* ((max-widths (seq-copy min-widths)) - (rows - (seq-map (lambda (str) - (let ((visible-str - (substring str - 0 - (text-property-any 0 (length str) - 'display "" - str))) - (suffixes (get-text-property 0 prop str))) - ;; Mutate `max-widths'. + (let ((max-widths (seq-copy min-widths)) + (prop (or prop 'racket-affix))) + (lambda (strs) + (let* ((rows + (seq-map (lambda (str) + (let ((visible-str + (substring str + 0 + (text-property-any 0 (length str) + 'display "" + str))) + (suffixes (get-text-property 0 prop str))) + ;; Mutate `max-widths'. + (cl-loop + for col in (cons visible-str suffixes) + for ix from 0 + do (aset max-widths ix + (max (aref max-widths ix) + (1+ (length col))))) + (cons str suffixes))) + strs)) + (suffix-offsets + (apply #'vector + (let ((offset 0)) (cl-loop - for col in (cons visible-str suffixes) + for max-width across max-widths for ix from 0 - do (aset max-widths ix - (max (aref max-widths ix) - (1+ (length col))))) - (cons str suffixes))) - strs)) - (suffix-offsets - (apply #'vector - (let ((offset 0)) - (cl-loop - for max-width across max-widths - for ix from 0 - collect - (setq offset (+ offset max-width))))))) - (seq-map - (pcase-lambda (`(,str . ,suffixes)) - (let ((suffixes-str - (cl-loop - for suffix in suffixes - for offset across suffix-offsets - concat - (concat - (propertize " " - 'display - `(space :align-to ,offset)) - (propertize (or suffix "") - 'face 'completions-annotations))))) - (list str "" suffixes-str))) - rows))) + collect + (setq offset (+ offset max-width))))))) + (seq-map + (pcase-lambda (`(,str . ,suffixes)) + (let ((suffixes-str + (cl-loop + for suffix in suffixes + for offset across suffix-offsets + concat + (concat + (propertize " " + 'display + `(space :align-to ,offset)) + (propertize (or suffix "") + 'face 'completions-annotations))))) + (list str "" suffixes-str))) + rows))))) (provide 'racket-complete) diff --git a/racket-describe.el b/racket-describe.el index 95ea0e75..a7321e94 100644 --- a/racket-describe.el +++ b/racket-describe.el @@ -650,9 +650,7 @@ association list, to look up the path and anchor." (defun racket-describe-search () "Search installed documentation; view using `racket-describe-mode'." (interactive) - (let* ((affixator (apply-partially #'racket--affix - 'racket-affix - [16 16 32 0])) + (let* ((affixator (racket--make-affix [16 16 32 0])) (collection (racket--completion-table (racket--doc-index) `((category . ,racket--identifier-category) diff --git a/racket-input.el b/racket-input.el index c1039470..a2aa738b 100644 --- a/racket-input.el +++ b/racket-input.el @@ -321,13 +321,11 @@ currently provided by the Emacs UI for input method." (seq-map (pcase-lambda (`(,str ,v . _more)) (propertize str 'racket-affix (list v))) racket-input-translations)) - (affixator - (apply-partially #'racket--affix 'racket-affix [16 0])) - (collection - (racket--completion-table - translations - `((category . racket-symbol-name) - (affixation-function . ,affixator)))) + (affixator (racket--make-affix [16 0])) + (collection (racket--completion-table + translations + `((category . racket-symbol-name) + (affixation-function . ,affixator)))) (predicate nil) (require-match t)) (when-let (str (completing-read "Symbol: " diff --git a/racket-package.el b/racket-package.el index b19c604b..3334bb10 100644 --- a/racket-package.el +++ b/racket-package.el @@ -155,7 +155,7 @@ Allows users to customize via `completion-category-overrides'.") (propertize name 'racket-affix (list stat desc))) pkgs)) - (affix (apply-partially #'racket--affix 'racket-affix [16 10 0])) + (affix (racket--make-affix [16 10 0])) (val (completing-read "Describe Racket package: " (racket--completion-table pkgs diff --git a/racket-xp-complete.el b/racket-xp-complete.el index 607b0860..f50998a3 100644 --- a/racket-xp-complete.el +++ b/racket-xp-complete.el @@ -47,7 +47,7 @@ The table includes category and affixation-function metadata.") ;; for use as completion table. (let* ((all nil) (imports nil) - (affixator (apply-partially #'racket--affix 'racket-affix [32 0])) + (affixator (racket--make-affix [32 0])) (metadata `((category . ,racket--identifier-category) (affixation-function . ,affixator)))) (dolist (mod+syms mods+syms)