[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function
From: |
Stefan Monnier |
Subject: |
Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function |
Date: |
Fri, 10 Jun 2022 10:15:50 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Hi Lars,
> Allow REQUIRE-MATCH to be a function
>
> * doc/lispref/minibuf.texi (Minibuffer Completion): Document it.
>
> * lisp/minibuffer.el (completion--complete-and-exit): Allow
> REQUIRE-MATCH to be a function.
> (read-file-name): Mention it.
I see the motivation is for things like `read-file-name` where we
can't specify a completion table (otherwise we could also get the same
result with an appropriate completion table whose `test-completion` is
adjusted accordingly).
But besides the `test-completion` part of the completion table, this new
feature also overlaps with the `predicate` argument. I think it would
be good to write down somewhere how those three compare.
I wonder if that can also be used to solve the problem of completing
file names that "end in .pdf": previously using `test-completion` (via
the completion table or via `predicate`) had the problem that such
a test either ruled out completions to "foo/bar/" (which can be
indispensable on the way to the final "foo/bar/baz.pdf") or spuriously
allow hitting RET on "foo/bar/" even tho it doesn't end in `.pdf`.
> + ;; The CONFIRM argument is a predicate.
> + ((and (functionp minibuffer-completion-confirm)
> + (funcall minibuffer-completion-confirm
> + (buffer-substring beg end)))
> + (funcall exit-function))
> + ;; See if we have a completion from the table.
> + ((test-completion (buffer-substring beg end)
> + minibuffer-completion-table
> + minibuffer-completion-predicate)
> + ;; FIXME: completion-ignore-case has various slightly
> + ;; incompatible meanings. E.g. it can reflect whether the user
> + ;; wants completion to pay attention to case, or whether the
> + ;; string will be used in a context where case is significant.
> + ;; E.g. usually try-completion should obey the first, whereas
> + ;; test-completion should obey the second.
> + (when completion-ignore-case
> + ;; Fixup case of the field, if necessary.
> + (let* ((string (buffer-substring beg end))
> + (compl (try-completion
> + string
> + minibuffer-completion-table
> + minibuffer-completion-predicate)))
> + (when (and (stringp compl) (not (equal string compl))
> + ;; If it weren't for this piece of paranoia, I'd replace
> + ;; the whole thing with a call to do-completion.
> + ;; This is important, e.g. when the current minibuffer's
> + ;; content is a directory which only contains a single
> + ;; file, so `try-completion' actually completes to
> + ;; that file.
> + (= (length string) (length compl)))
> + (completion--replace beg end compl))))
> + (funcall exit-function))
> + ;; The user is permitted to exit with an input that's rejected
> + ;; by test-completion, after confirming her choice.
> + ((memq minibuffer-completion-confirm '(confirm confirm-after-completion))
> + (if (or (eq last-command this-command)
> + ;; For `confirm-after-completion' we only ask for confirmation
> + ;; if trying to exit immediately after typing TAB (this
> + ;; catches most minibuffer typos).
> + (and (eq minibuffer-completion-confirm 'confirm-after-completion)
> + (not (memq last-command minibuffer-confirm-exit-commands))))
> (funcall exit-function)
> - (minibuffer-message "Confirm")
> - nil))
> + (minibuffer-message "Confirm")
> + nil))
I see that the `minibuffer-completion-confirm` function completely
replaces the usual handling of require-match (i.e. the attempt to fix
the case and the prompting for confirmation).
Maybe this should be better documented, and also AFAICT currently
a `minibuffer-completion-confirm` function cannot reliably reproduce this
behavior by hand because it doesn't have access to `beg` and `end`.
I think we should make this "default behavior" more easily accessible
(e.g. put it into its own function and document it as something that can
be called from `minibuffer-completion-confirm`?).
Stefan
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function,
Stefan Monnier <=
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Lars Ingebrigtsen, 2022/06/11
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Stefan Monnier, 2022/06/11
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Lars Ingebrigtsen, 2022/06/11
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Stefan Monnier, 2022/06/11
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Lars Ingebrigtsen, 2022/06/12
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Stefan Monnier, 2022/06/12
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Lars Ingebrigtsen, 2022/06/13
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Stefan Monnier, 2022/06/13
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Lars Ingebrigtsen, 2022/06/14
- Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function, Stefan Monnier, 2022/06/14