unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [PATCH] `completion-all-sorted-completions`: Add support for completion boundaries
Date: Sat, 24 Apr 2021 18:19:48 -0400	[thread overview]
Message-ID: <jwvlf97z6az.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <9beb1aa3-d934-c3ae-7c26-26256e34ae43@daniel-mendler.de> (Daniel Mendler's message of "Sat, 24 Apr 2021 22:14:27 +0200")

> 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




  reply	other threads:[~2021-04-24 22:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24 20:14 [PATCH] `completion-all-sorted-completions`: Add support for completion boundaries Daniel Mendler
2021-04-24 22:19 ` Stefan Monnier [this message]
2021-04-24 22:27   ` Daniel Mendler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvlf97z6az.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=mail@daniel-mendler.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).