unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Daniel Mendler <daniel@mendler.net>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] `completing-read` - allow history=t, sorting improvements
Date: Mon, 19 Apr 2021 18:55:08 -0400	[thread overview]
Message-ID: <jwvv98hriy7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <ef7f0dba-0932-1ba5-4239-0be518602a8b@mendler.net> (Daniel Mendler's message of "Tue, 20 Apr 2021 00:29:24 +0200")

> Btw, I attached the updated patch for the boundaries. I am not sure if the
>  approach I took there is a good one, this works only in restricted set of
>  scenarios (not with partial-completion/initials unfortunately). So this
> should be discussed.

See my comment below.

> Then you mentioned test cases - to clarify, do you want to see some kind of
> integration test where a mockup minibuffer-completion-table is set-up and
> the results of `completion-all-sorted-completions` are checked,

I think that's what we'd want, yes.

> I looked briefly into
> test/lisp/minibuffer.el - the test should probably go there?
                    ^^^
                   -tests

Yes, indeed.

> +(defun minibuffer--sort-preprocess-history (start string)
> +  "Preprocess history, remove completion prefixes.
> +STRING is the minibuffer content.
> +START is the start position of the completion."
> +  (let* ((def (car-safe minibuffer-default))
> +         (hist (symbol-value minibuffer-history-variable))
> +         (hist (if def (cons def hist) hist))
> +         (bounds (completion-boundaries
> +                  (substring string 0 (- (point) start))
> +                  minibuffer-completion-table
> +                  minibuffer-completion-predicate
> +                  ""))

Actually, the caller has the info we need already in the (cdr last),
which it throws away in:

        (when last
          (setcdr last nil)

This info also has the advantage of working with partial-completion
because it comes from the completion-style output rather than from the
completion-table.
[ If (cdr last) is nil it's equivalent to 0.  ]

> +         (pre (substring string 0 (car bounds)))
> +         (pre-len (length pre)))
> +    ;; Preprocess history if completion boundaries are used
> +    (cond
> +     ;; Special handling of file name candidates.
> +     ;; Drop prefix and everything after the first "/".
> +     (minibuffer-completing-file-name

I hope that using (cdr last) will make it unnecessary to use such a hack.
If not, then please try and use the `category` from `md` rather than
`minibuffer-completing-file-name` which I consider as obsolete (tho it's
not marked as such yet).


        Stefan




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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 18:02 [PATCH] `completing-read` - allow history=t, sorting improvements Daniel Mendler
2021-04-19 19:14 ` Stefan Monnier
2021-04-19 19:36   ` Daniel Mendler
2021-04-19 20:15     ` Stefan Monnier
2021-04-19 20:44       ` Daniel Mendler
2021-04-19 21:52         ` Stefan Monnier
2021-04-19 22:29           ` Daniel Mendler
2021-04-19 22:55             ` Stefan Monnier [this message]
2021-04-19 23:47               ` Daniel Mendler
2021-04-20  1:55                 ` Stefan Monnier

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=jwvv98hriy7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=daniel@mendler.net \
    --cc=emacs-devel@gnu.org \
    /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).