From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: master 49e06183f5 1/3: Allow REQUIRE-MATCH to be a function Date: Fri, 10 Jun 2022 10:15:50 -0400 Message-ID: References: <165484935985.12525.14065631018362412932@vcs2.savannah.gnu.org> <20220610082240.A7222C01683@vcs2.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28897"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 10 16:18:00 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzfSa-0007ID-7r for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Jun 2022 16:18:00 +0200 Original-Received: from localhost ([::1]:52768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzfSY-0007xt-Pp for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Jun 2022 10:17:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzfQc-0006CG-FV for emacs-devel@gnu.org; Fri, 10 Jun 2022 10:15:58 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:41428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzfQZ-0007Ub-8n for emacs-devel@gnu.org; Fri, 10 Jun 2022 10:15:57 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 980BD807FB; Fri, 10 Jun 2022 10:15:53 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D37F78073F; Fri, 10 Jun 2022 10:15:51 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1654870551; bh=vTy2fjVmpqMNgQH6knCIGFWp3LRdNsiFm4C+SByY6rw=; h=From:Cc:Cc:Subject:References:Date:In-Reply-To:From; b=oO8MU4PIt32neP6k54j2FKfedgku0MsjoCUi4rTwNPa0y5CegvtUicSvgaBufyMaA fNsMnZZQOmVW1vMvvSUe7LhoP5n084gvEoGVWrLmzB++zv4Rn1sF3qKhaMrO7iV79Y FE3K8p0+tMxpfFLMoNV/zQ2eDUkysRrX55ZLFFgqoOshG2J7+1m37buCoercG55Kp7 8FkeDfzIb5sEIzK1gNPXaZIw/fdz9FMcrfpNv2BB8i00B5QDo9H0hyZiyixwQh4cqH liQ6Vo4GNr7w/HceY9VKRLHwpwo1SgtJbEO9IavQcjl4ifHaVvAOKpLz61nCJWawKi w0HDNIIClEnnA== Original-Received: from pastel (unknown [45.72.221.51]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A5C84120172; Fri, 10 Jun 2022 10:15:51 -0400 (EDT) Original-Cc: emacs-devel@gnu.org, Daniel Mendler In-Reply-To: <20220610082240.A7222C01683@vcs2.savannah.gnu.org> (Lars Ingebrigtsen's message of "Fri, 10 Jun 2022 04:22:40 -0400 (EDT)") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:291004 Archived-At: 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