From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#66187: read-file-name unexpected behavior when MUSTMATCH is a function Date: Wed, 27 Sep 2023 03:43:25 +0200 Message-ID: <87h6ngs85e.fsf@web.de> References: <87r0mni6m1.fsf@breatheoutbreathe.in> <87bkdq3nw6.fsf@web.de> <875y3yx221.fsf@breatheoutbreathe.in> <87pm260wh9.fsf@web.de> <87v8bx48ww.fsf@breatheoutbreathe.in> <87msx8sbpv.fsf@web.de> <87bkdoh1gy.fsf@breatheoutbreathe.in> 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="15680"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: philipk@posteo.net, 66187@debbugs.gnu.org To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 27 03:44:10 2023 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 1qlJb0-0003tQ-RA for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 27 Sep 2023 03:44:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qlJag-0002d5-6U; Tue, 26 Sep 2023 21:43:50 -0400 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 1qlJae-0002cf-TX for bug-gnu-emacs@gnu.org; Tue, 26 Sep 2023 21:43:48 -0400 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 1qlJae-0006ub-Jt for bug-gnu-emacs@gnu.org; Tue, 26 Sep 2023 21:43:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qlJar-00053k-JZ for bug-gnu-emacs@gnu.org; Tue, 26 Sep 2023 21:44:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Sep 2023 01:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66187 X-GNU-PR-Package: emacs X-Debbugs-Original-Cc: Philip Kaludercic , "Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors" , 66187@debbugs.gnu.org Original-Received: via spool by 66187-submit@debbugs.gnu.org id=B66187.169577903819432 (code B ref 66187); Wed, 27 Sep 2023 01:44:01 +0000 Original-Received: (at 66187) by debbugs.gnu.org; 27 Sep 2023 01:43:58 +0000 Original-Received: from localhost ([127.0.0.1]:50145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlJan-00053M-Uu for submit@debbugs.gnu.org; Tue, 26 Sep 2023 21:43:58 -0400 Original-Received: from mout.web.de ([212.227.17.12]:40125) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qlJai-000531-V1 for 66187@debbugs.gnu.org; Tue, 26 Sep 2023 21:43:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1695779005; x=1696383805; i=michael_heerdegen@web.de; bh=uk5FsPfzwEVEXt5dnheE31v1oUXyfiEeXy/HMI9Zb+A=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=n8GhP5Apeos/mMxTyv0ogzX0y8GwToi0DYDZKN8W00/Xw6YIMrWhRz+AQJDzwgmG96fZU3z4RiE Rc8AZ0wMcOdeqQwdQwkRhd6yBTb/QWRYUJ1Ydseykcfad6RZg5EqlJsPnr5ifpeFVJxNmkCOS5Tlk ss3r44Uis2q9FcJjBm9omdqhNwyI+HjWM8eaYfFLSaHe82mp03aPy236XhOF8b9dogIzg272Wu94n EmkL57/czSq9PwIDnr9az/re3XLVAhgq1qob6V3c5Tdu7Ss0RV2nE/rIKgc9/XGKwZfTMhjyr5sdy khpD7PtWG/qPJJmVMK/kglwsCBqi48yp9lrA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([88.66.201.191]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Ml46w-1rWVI90vBU-00lYRl; Wed, 27 Sep 2023 03:43:25 +0200 In-Reply-To: <87bkdoh1gy.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Tue, 26 Sep 2023 17:55:37 -0700") X-Provags-ID: V03:K1:xl72ThruC5LxPiyYJV+9RjDLnxrwGCNuea7CJBi/VIFABgvNbYs mqCf+ClZViyj3AY5CUk1S3eu5bJ30fRCCeqk3G516ChOIdNSRHu0DqQ2dq7+b0q7AXaqc8U Y4XqZ2nt5NDIMj03VHBHHN/J0ljk0I9rbH0yGP+Dh4UZzRwzlStbX6dzMm0fpGcCMth0o/0 5I6d8z3wTpmDxh3oNcW3w== UI-OutboundReport: notjunk:1;M01:P0:A+ly6Ajqnnw=;4QoLm/0v6FXjNPnd0KsAFoxBJHd LumXibD+5YSJhlvFyHfVE6aJ0/2J0rUJrpKk0GBuJ57DG/QZQ2WNOBTXyIpv9M4Uo4LziLshl wSnfTZPsVriwv2HjYA7UiUypGyWJWwALkDAUT2E1tANzFqYzYIA76GxjDs+iyH/XWqcDEUKPx FPUZzcODazpAo8tVNUFyzN7uMYQHGgRwucjuOx88CMNhg3+jZzG99FesVbm0Xckp8201pWTpo aAEYRF+8qeeOrAo6FXZ3HGHai9X1kJHvK2VJhXUSUrFVHlmDLMyF3wIhGL5TvVpE4EZkLYgJx 7HylqZx06bCqFLe9aUpSJiDbX7/yV6hqDA/RqcXofWdZOC47OYHz0qEDmtSASX417qEzVtcaa fVy2ayuqCtiBENTQFkprpj6wTZMq5nF/hM04HyPXWkBbW6H7qVfTSQ6E63h+Zw8nILlLmF8Og wpEGMG8Bfamw0zQN0acIXlH8Gir9iZd1MVRqJzhonxSgUvqYFgkC/h1CjeLg26w/0FPPJrzli 10iDP8BiCWUlFBPW9dwZOmbXcsfGdGwX2cdWt8pqVigbp0x05lat3DbBkcwGWn6ajIkQ4DKYi sZUEjkl+tLs4rZF99lurZpsTW9u5aJ0kcnkjmt3mcyrz4yFAc7PnYMAkgbkTHLuekXJWj9i8y Kh3eIOX5ZFckbfiut8OpgFaozaHi3NzB6CtW+lQEw3s01pxUTCBQsM5ZFms+fwGFo9zwPNJiN ZubiZx8z08sqk1IfS96VM+2aW5nC1wzKSY+/dZAoI4pQ6M5ie/lR+XGZS/WvCOznTFcIOcai 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:271406 Archived-At: --=-=-= Content-Type: text/plain Joseph Turner writes: > > Yes, looks like a bug that this is not possible. It should be possible > > to complete directory names that do not match. > > I'm happy to work on the bug, if others agree that this change is > desired. I had a look and tried this: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-WIP-Bug-66187.patch Content-Transfer-Encoding: quoted-printable =46rom ad895d2df5c69e015c2c7eba5116ab2d440e1fbc Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Wed, 27 Sep 2023 03:32:37 +0200 Subject: [PATCH] WIP: Bug#66187 =2D-- lisp/minibuffer.el | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 2120e31775e..79a8786fbac 100644 =2D-- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3061,13 +3061,23 @@ completion-file-name-table (funcall (or pred 'file-exists-p) string))) (t - (let* ((name (file-name-nondirectory string)) + (let* ((test-directory (lambda (s) + (let ((len (length s))) + (and (> len 0) (eq (aref s (1- len)) ?= /))))) + (should-complete + (and pred + (if (eq pred 'file-directory-p) + test-directory + (lambda (f) + (or (funcall test-directory f) + (funcall pred f)))))) + (name (file-name-nondirectory string)) (specdir (file-name-directory string)) (realdir (or specdir default-directory))) (cond ((null action) - (let ((comp (file-name-completion name realdir pred))) + (let ((comp (file-name-completion name realdir should-complet= e))) (if (stringp comp) (concat specdir comp) comp))) @@ -3078,18 +3088,9 @@ completion-file-name-table ;; Check the predicate, if necessary. (unless (memq pred '(nil file-exists-p)) (let ((comp ()) - (pred - (if (eq pred 'file-directory-p) - ;; Brute-force speed up for directory checking= : - ;; Discard strings which don't end in a slash. - (lambda (s) - (let ((len (length s))) - (and (> len 0) (eq (aref s (1- len)) ?/)))= ) - ;; Must do it the hard (and slow) way. - pred))) - (let ((default-directory (expand-file-name realdir))) - (dolist (tem all) - (if (funcall pred tem) (push tem comp)))) + (default-directory (expand-file-name realdir))) + (dolist (tem all) + (if (funcall should-complete tem) (push tem comp))) (setq all (nreverse comp)))) all)))))) =2D- 2.39.2 --=-=-= Content-Type: text/plain I thought this would make Emacs complete as you want. But: what files should be shown when hitting TAB? I decided to show only matching files, plus all directories (seems logical, since these may contain matching files). But that gives a bad user experience: When I tried this I thought it would not work because completion did not accept an existing empty directory. Then I saw that it actually was not empty. But it contained only plain files, no subdirectories, and TAB displayed nothing. Quite confusing! > How about the attached patch? | diff --git a/lisp/files.el b/lisp/files.el | index b72f141c0ee..1fe124848b9 100644 | --- a/lisp/files.el | +++ b/lisp/files.el | @@ -817,7 +817,7 @@ non-empty string that was inserted by this function. | If the user exits with an empty minibuffer, this function returns | an empty string. (This can happen only if the user erased the | pre-inserted contents or if `insert-default-directory' is nil.) | -Fourth arg MUSTMATCH non-nil means require existing directory's name. | +Fourth arg MUSTMATCH is passed as-is to `read-file-name', which see. Ok from my side. What do others think about all of this? Thx, Michael. --=-=-=--