GNU bug report logs -
#66224
[PATCH] Add optional PREDICATE argument to read-directory-name
Previous Next
Reported by: Joseph Turner <joseph <at> breatheoutbreathe.in>
Date: Wed, 27 Sep 2023 01:20:02 UTC
Severity: wishlist
Tags: patch
Fixed in version 31.1
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #38 received at 66224 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:
>> Date: Tue, 26 Sep 2023 18:16:40 -0700
>> From: Joseph Turner via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> This patch makes read-directory-name accept an optional PREDICATE arg
>> so it can be used like read-file-name.
>
> Any rationale?
Mainly code clarity. If you want to prompt for a certain type of
directory, then IMO the intent is more clear like this:
(read-directory-name "Prompt: " "~/" nil nil nil #'my/predicate)
than like this:
(read-file-name "Prompt: " "~/" nil nil nil
(lambda (filename)
(and (funcall #'file-directory-p filename)
(funcall #'my/predicate filename))))
Also, I think that it would follow the principle of least suprise to
have read-file-name and read-directory-name accept the same args.
>> @@ -1719,7 +1719,9 @@ combining @var{directory} (or the current buffer's default directory
>> if @var{directory} is @code{nil}) and @var{initial}. If both
>> @var{default} and @var{initial} are @code{nil}, this function uses
>> @var{directory} as substitute default, or the current buffer's default
>> -directory if @var{directory} is @code{nil}.
>> +directory if @var{directory} is @code{nil}. The union of sixth arg
>> +@code{predicate} and @code{file-directory-p} is passed as the
>
> This should be elaborated: what is meant by "the union of sixth arg
> and 'file-directory-p'"?
>
>> +@code{predicate} argument to ‘read-file-name’.
> ^^^^^^^^^^^^^^^^
> That should be @code{read-file-name}
>
>> +** 'read-directory-name' now accepts an optional PREDICATE argument.
>> +The union of sixth arg PREDICATE and 'file-directory-p' is passed
>> +as the PREDICATE argument to 'read-file-name'.
>
> Likewise here, regarding the "union" part.
>
> Also, since you submit the patch for the manual, this NEWS entry
> should be marked with "+++".
>
>> Fifth arg INITIAL specifies text to start with.
>> DIR should be an absolute directory name. It defaults to
>> -the value of `default-directory'."
>> +the value of `default-directory'.
>> +The union of sixth arg PREDICATE and `file-directory-p' is passed
>> +as the PREDICATE argument to `read-file-name'."
>
> The "union" part again.
Thanks for the review!! Please see attached patch.
Best,
Joseph
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, attachment)]
This bug report was last modified 158 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.