From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68815: Unexpected behavior with read-file-name and functional REQUIRE-MATCH argument Date: Wed, 31 Jan 2024 14:34:22 -0800 Message-ID: <87sf2d6sf8.fsf@breatheoutbreathe.in> References: <8734ufyxoy.fsf@breatheoutbreathe.in> <87ttmuhvxi.fsf@breatheoutbreathe.in> <875xz98975.fsf@breatheoutbreathe.in> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32603"; mail-complaints-to="usenet@ciao.gmane.io" Cc: michael_heerdegen@web.de, Philip Kaludercic , 68815@debbugs.gnu.org, Eli Zaretskii , stefankangas@gmail.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 31 23:38:23 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rVJDn-0008BT-TN for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 31 Jan 2024 23:38:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVJDR-0000Fw-PA; Wed, 31 Jan 2024 17:37:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVJDO-0000Fj-5n for bug-gnu-emacs@gnu.org; Wed, 31 Jan 2024 17:37:54 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVJDN-0001Sg-3i for bug-gnu-emacs@gnu.org; Wed, 31 Jan 2024 17:37:53 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVJDW-0006ca-DA for bug-gnu-emacs@gnu.org; Wed, 31 Jan 2024 17:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 31 Jan 2024 22:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68815 X-GNU-PR-Package: emacs Original-Received: via spool by 68815-submit@debbugs.gnu.org id=B68815.170674065425413 (code B ref 68815); Wed, 31 Jan 2024 22:38:02 +0000 Original-Received: (at 68815) by debbugs.gnu.org; 31 Jan 2024 22:37:34 +0000 Original-Received: from localhost ([127.0.0.1]:39195 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVJD3-0006bp-So for submit@debbugs.gnu.org; Wed, 31 Jan 2024 17:37:34 -0500 Original-Received: from out-174.mta1.migadu.com ([2001:41d0:203:375::ae]:61783) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVJD1-0006be-89 for 68815@debbugs.gnu.org; Wed, 31 Jan 2024 17:37:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1706740639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=G6NP5s2Z5qrnEZJK7ioGejECDd/aDFazWNcdAW+pYug=; b=N7F9GF9FjDxfiOY5tkpyN++FGL9hDvIX+qpbcEtTZWolc/aJFs8mGEcwAcFPZe3otxlipV rOfLdhBB09hm1VzyNkLn9bSZ53KDltacFbDt1Hk2LH5PXJxCEMUZCtlJKmeyXFr8TGEbSS lNOr80kzGKCaP8g2U/GdHwyvqpPUCa0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279250 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >>> Also, performance can be a concern (in many cases it makes more sense >>> to make the caller pass the unquoted name rather than force it to quote >>> the name only for PRED to unquote it). >> >> The REQUIRE-MATCH function is only called once when the user attempts to >> exit the minibuffer. Would you please explain the performance concern? > > Oh, sorry, I got confused. Indeed, you're wrapping the REQUIRE-MATCH > arg, not the PRED arg I was ranting about. Duh! > > It would be OK for `emacs-29`, indeed. Eli? Stefan? Any objection? Great! I've CC'd Stefan as well in this email. > In the mean time, could you update the docs to clarify the behavior. > E.g. currently the docstring of `read-file-name` says: > > - a function, which will be called with the input as the > argument. [...] > > which could be understood to suggest it really receives the contents of > the minibuffer (i.e. the quoted file name) rather than the value we'd > extract from it (the unquoted file name). Please see the attached patch. Thanks! Joseph --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Pass-unquoted-filename-to-user-supplied-MUSTMATCH-pr.patch >From 208c7abff97f842057540fa2dfacd99808f17015 Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Tue, 30 Jan 2024 22:08:50 -0800 Subject: [PATCH] Pass unquoted filename to user-supplied MUSTMATCH predicate * lisp/minibuffer.el (read-file-name-default): Pass REQUIRE-MATCH argument through substitute-in-file-name. * lisp/minibuffer.el (read-file-name): Update docstring. Resolves bug#68815. --- lisp/minibuffer.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index faa7f543ece..a9e3ec937f9 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3262,9 +3262,10 @@ Fourth arg MUSTMATCH can take the following values: input, but she needs to confirm her choice if she called `minibuffer-complete' right before `minibuffer-complete-and-exit' and the input is not an existing file. -- a function, which will be called with the input as the - argument. If the function returns a non-nil value, the - minibuffer is exited with that argument as the value. +- a function, which will be called with a single argument, the + input unquoted by `substitute-in-file-name', which see. If the + function returns a non-nil value, the minibuffer is exited with + that argument as the value. - anything else behaves like t except that typing RET does not exit if it does non-null completion. @@ -3353,7 +3354,13 @@ See `read-file-name' for the meaning of the arguments." (let ((ignore-case read-file-name-completion-ignore-case) (minibuffer-completing-file-name t) (pred (or predicate 'file-exists-p)) - (add-to-history nil)) + (add-to-history nil) + (require-match (if (functionp mustmatch) + (lambda (input) + (funcall mustmatch + ;; User-supplied MUSTMATCH expects an unquoted filename + (substitute-in-file-name input))) + mustmatch))) (let* ((val (if (or (not (next-read-file-uses-dialog-p)) @@ -3389,7 +3396,7 @@ See `read-file-name' for the meaning of the arguments." (read-file-name--defaults dir initial)))) (set-syntax-table minibuffer-local-filename-syntax)) (completing-read prompt 'read-file-name-internal - pred mustmatch insdef + pred require-match insdef 'file-name-history default-filename))) ;; If DEFAULT-FILENAME not supplied and DIR contains ;; a file name, split it. -- 2.41.0 --=-=-=--