From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#66114: [PATCH] Fix interactive prompt for selecting checkout directory Date: Sun, 24 Sep 2023 16:37:11 +0200 Message-ID: <87lecvbpt4.fsf@posteo.net> References: <87h6npfhoa.fsf@breatheoutbreathe.in> <87h6nmvcru.fsf@posteo.net> <87bkdsp2ns.fsf@breatheoutbreathe.in> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16995"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66114@debbugs.gnu.org To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 24 16:38:01 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 1qkQFF-00049J-2g for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Sep 2023 16:38:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkQF6-0000m1-7z; Sun, 24 Sep 2023 10:37:52 -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 1qkQF5-0000lr-4z for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 10:37:51 -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 1qkQF4-0002Ap-Sl for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 10:37:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qkQFG-0003G5-Dk for bug-gnu-emacs@gnu.org; Sun, 24 Sep 2023 10:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Sep 2023 14:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66114 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66114-submit@debbugs.gnu.org id=B66114.169556625612483 (code B ref 66114); Sun, 24 Sep 2023 14:38:02 +0000 Original-Received: (at 66114) by debbugs.gnu.org; 24 Sep 2023 14:37:36 +0000 Original-Received: from localhost ([127.0.0.1]:43394 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkQEp-0003FG-ND for submit@debbugs.gnu.org; Sun, 24 Sep 2023 10:37:36 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:39487) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qkQEk-0003Ez-2t for 66114@debbugs.gnu.org; Sun, 24 Sep 2023 10:37:33 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 14BD0240101 for <66114@debbugs.gnu.org>; Sun, 24 Sep 2023 16:37:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1695566232; bh=8VcFkjp/dLXRzWqodQqR6X5dwTxUdSAt7Lz9k3XJzNw=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=XGLt0OmzAVxJcluBRHE7TjR6zfgA2s31BmRyKl6I+8BjSm45P70n8MiLia9TjFQvG IAylQ94zRZKdCl97NS+HU4bjtsJvpQbNmMRi5aaD6vHoq0xykwQqkkZgH+7rgLjiig WedrsjB9MT5Jr4toY68rTWCQpTzHHNgHq54c8Zi43dIW/fvyHne5DtL4a1UUIgkepy 8jvaqD9ZUy+IbLahLm6fIPJgqWfz+77Z7dnkovAzd9BwoAVMh1gptZf2AQuqWnGXAg CXPqFqbMJmL1HOiAdTFP9soNefyJqWmXcTgW39lw+ymBQfD6Vg99JOBZKY40wrjSDx riRJxZQZNFZyg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RtpVv5B3bz9ryR; Sun, 24 Sep 2023 16:37:11 +0200 (CEST) In-Reply-To: <87bkdsp2ns.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Sat, 23 Sep 2023 22:06:06 -0700") X-Hashcash: 1:20:230924:joseph@breatheoutbreathe.in::gTIRL+ne/p0mcYua:ga2 X-Hashcash: 1:20:230924:66114@debbugs.gnu.org::rBL9w328YEmpiK1W:B6KY Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM 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:271248 Archived-At: Joseph Turner writes: > Philip Kaludercic writes: > >> Joseph Turner writes: >> >>> Tags: patch >>> >>> This patch fixes the interactive prompt in package-vc-checkout. See >>> commit message for details. >>> >>> From 70061d76542968575555f247d4715d18ed3c4e75 Mon Sep 17 00:00:00 2001 >>> From: Joseph Turner >>> Date: Tue, 19 Sep 2023 23:58:43 -0700 >>> Subject: [PATCH] Fix interactive prompt for selecting checkout directory >>> >>> * lisp/emacs-lisp/package-vc.el (package-vc-checkout): Use >>> read-directory-name instead of read-file-name with >>> predicate. Previously, it was impossible to interactively navigate to >>> a nested subdirectory. >> >> I can "navigate" into whatever directory I want, but I don't get completion. > > You're right. > >>> --- >>> lisp/emacs-lisp/package-vc.el | 17 +++++++++++------ >>> 1 file changed, 11 insertions(+), 6 deletions(-) >>> >>> diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el >>> index c7a30736e32..29b540d86b8 100644 >>> --- a/lisp/emacs-lisp/package-vc.el >>> +++ b/lisp/emacs-lisp/package-vc.el >>> @@ -823,12 +823,17 @@ repository. If REV has the special value >>> `:last-release' (interactively, the prefix argument), that stands >>> for the last released version of the package." >>> (interactive >>> - (let* ((name (package-vc--read-package-name "Fetch package source: "))) >>> - (list (cadr (assoc name package-archive-contents #'string=)) >>> - (read-file-name "Clone into new or empty directory: " nil nil t nil >>> - (lambda (dir) (or (not (file-exists-p dir)) >>> - (directory-empty-p dir)))) >>> - (and current-prefix-arg :last-release)))) >>> + (let* ((name (package-vc--read-package-name "Fetch package source: ")) >>> + (desc (cadr (assoc name package-archive-contents #'string=))) >>> + (dir (read-directory-name "Clone into new or empty directory: "))) >>> + (unless (or (not (file-exists-p dir)) >>> + (directory-empty-p dir)) >>> + (let ((subdir (expand-file-name (package-desc-full-name desc) dir))) >>> + (if (and (not (file-exists-p subdir)) >>> + (y-or-n-p (format "Create new directory %s ?" subdir))) >>> + (setf dir subdir) >> >> I'd prefer to use a setq here. >> >>> + (user-error "Directory not empty: %S" (expand-file-name dir))))) >> >> This seems like an anti-feature to me, because you need to know what >> directory is empty before confirming your choice, and if it is not >> empty, you have to restart the entire command again. > > Yes, I agree. > > IIUC, we want to read from the user a directory which is either > nonexistent or empty. However, we also want the completions to include > non-empty directories so that the user can easily select a deeply nested > directory. The current solution does not offer non-empty directories for > completions, meaning that users must manually type in a potentially long > path to a nested empty or nonexistent directory. It is funny to me, that I probably never noticed this issue because I have the habit of using hippie-expand to complete partial file names, including in the minibuffer :) > Here's a different idea I tried: > > (read-file-name "Clone into new or empty directory: " nil nil > ;; Must match a nonexistent or empty directory > (lambda (dir) (or (not (file-exists-p dir)) > (directory-empty-p dir))) > nil > ;; `read-directory-name' accepts no PREDICATE > ;; argument: hack `read-file-name' instead. > (lambda (file-name) (file-directory-p file-name))) > > but this erroneously returns the default filename, which might be > buffer-file-name or whatever string is currently in the minibuffer. An issue I am observing, is that it allows selecting non-empty directories. > I would have expected that when MUSTMATCH is a function and it returns > nil, a "[Match required]" message would appear. For the record, what completion system are you using. I don't appear to see this message at all. > However, the behavior of > read-file-name is unspecified when a MUSTMATCH function returns nil: > > - 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. > > Is this a bug, a case of under-documentation, or do I misunderstand something? > > I'm happy to post this in a separate bug thread if you think it's worth it. Perhaps that would be worth doing, that way the people who know more about completion than I do would be more likely to see it and help out. > > Joseph > >>> + (list desc dir (and current-prefix-arg :last-release)))) >>> (package-vc--archives-initialize) >>> (let ((pkg-spec (or (package-vc--desc->spec pkg-desc) >>> (and-let* ((extras (package-desc-extras pkg-desc)) -- Philip Kaludercic