all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: 66114@debbugs.gnu.org
Subject: bug#66114: [PATCH] Fix interactive prompt for selecting checkout directory
Date: Sun, 24 Sep 2023 14:27:53 -0700	[thread overview]
Message-ID: <87v8bzi7iz.fsf@breatheoutbreathe.in> (raw)
In-Reply-To: <87lecvbpt4.fsf@posteo.net>


Philip Kaludercic <philipk@posteo.net> writes:

> Joseph Turner <joseph@breatheoutbreathe.in> writes:
>
>> Philip Kaludercic <philipk@posteo.net> writes:
>>
>>> Joseph Turner <joseph@breatheoutbreathe.in> 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 <joseph@breatheoutbreathe.in>
>>>> 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 :)

Ah, that makes sense :)

>> 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.

I also do not see the message, but I expect to see it. I am using
vertico + orderless.

>>                                                  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.

Okay, thanks! I'll do that.

>>
>> 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))






  reply	other threads:[~2023-09-24 21:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20  7:02 bug#66114: [PATCH] Fix interactive prompt for selecting checkout directory Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found] ` <handler.66114.B.16951935749180.ack@debbugs.gnu.org>
2023-09-20  7:24   ` bug#66114: Acknowledgement ([PATCH] Fix interactive prompt for selecting checkout directory) Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-20  7:31     ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-22  8:21 ` bug#66114: [PATCH] Fix interactive prompt for selecting checkout directory Philip Kaludercic
2023-09-24  5:06   ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-24 14:37     ` Philip Kaludercic
2023-09-24 21:27       ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-01-30  8:42         ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-14 16:54           ` Philip Kaludercic
2024-02-15 17:27             ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8bzi7iz.fsf@breatheoutbreathe.in \
    --to=bug-gnu-emacs@gnu.org \
    --cc=66114@debbugs.gnu.org \
    --cc=joseph@breatheoutbreathe.in \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.