[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] `completion-all-sorted-completions`: Add support for complet
From: |
Stefan Monnier |
Subject: |
Re: [PATCH] `completion-all-sorted-completions`: Add support for completion boundaries |
Date: |
Sat, 24 Apr 2021 18:19:48 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> I attached a patch which adds support for completion boundaries to the
> sorting by history position. Tests are included.
Thanks, pushed.
> lisp/minibuffer.el (completion-all-sorted-completions): The history is
> preprocessed by the function `minibuffer--sort-preprocess-history`.
> The default value is prepended to the history. The completion base
> prefix string is removed from the history elements. This allows
> sorting by history position for completion tables which use completion
> boundaries, in particular the file completion table.
> test/lisp/minibuffer-tests.el (completion-all-sorted-completions): Add
> tests for various combinations of with/without history/base/default.
I massaged this to use the active voice and stick a bit closer to
our conventions.
> +(defun minibuffer--sort-preprocess-history (base)
> + "Preprocess history.
> +Remove completion BASE prefix string from history elements."
> + (let* ((def (if (stringp minibuffer-default)
> + minibuffer-default
> + (car-safe minibuffer-default)))
> + (hist (and (not (eq minibuffer-history-variable t))
> + (symbol-value minibuffer-history-variable)))
> + (base-size (length base)))
> + ;; Drop base string from the history elements
> + (when (/= base-size 0)
> + (setq hist (delq nil (mapcar
> + (lambda (c)
> + (when (string-prefix-p base c)
> + (substring c base-size)))
> + hist))))
> + ;; Default comes first
> + (setq hist (if def (cons def hist) hist))
> + hist))
I massaged this so that `def` is also filtered through `base`
(and also so that comments are properly punctuated).
> + (`(boundaries . ,_) `(boundaries ,(length base) . 0))
> + (_ (complete-with-action action
> + '(epsilon alpha gamma beta delta)
And I changed this completion table to a list of strings, since lists of
symbols happen to work most of the time but aren't officially supported
(we support alists whose keys are symbols, OTOH).
Stefan