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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66224 in the body.
You can then email your comments to 66224 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Wed, 27 Sep 2023 01:20:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Joseph Turner <joseph <at> breatheoutbreathe.in>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 27 Sep 2023 01:20:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello!
This patch makes read-directory-name accept an optional PREDICATE arg
so it can be used like read-file-name.
Joseph
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 28 Sep 2023 09:06:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 66224 <at> debbugs.gnu.org (full text, mbox):
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
> Hello!
>
> This patch makes read-directory-name accept an optional PREDICATE arg
> so it can be used like read-file-name.
>
> Joseph
>
>>From 78ba02683bd163d8991b182ec4e8ec370e734f95 Mon Sep 17 00:00:00 2001
> From: Joseph Turner <joseph <at> breatheoutbreathe.in>
> Date: Tue, 26 Sep 2023 18:14:23 -0700
> Subject: [PATCH] Add optional PREDICATE argument to read-directory-name
>
> * lisp/files.el (read-directory-name): Add optional PREDICATE arg.
> * doc/lispref/minibuf.texi (Reading File Names): Document change.
> * etc/NEWS: Note change.
> ---
> doc/lispref/minibuf.texi | 6 ++++--
> etc/NEWS | 4 ++++
> lisp/files.el | 8 +++++---
> 3 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
> index 620c58ec6e9..c3528ea74d2 100644
> --- a/doc/lispref/minibuf.texi
> +++ b/doc/lispref/minibuf.texi
> @@ -1709,7 +1709,7 @@ If this variable is non-@code{nil}, @code{read-file-name} ignores case
> when performing completion.
> @end defopt
>
> -@defun read-directory-name prompt &optional directory default require-match initial
> +@defun read-directory-name prompt &optional directory default require-match initial predicate
> This function is like @code{read-file-name} but allows only directory
> names as completion alternatives.
>
> @@ -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
> +@code{predicate} argument to ‘read-file-name’.
> @end defun
>
> @defopt insert-default-directory
> diff --git a/etc/NEWS b/etc/NEWS
> index 1b3532b5657..ee0143b1958 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -3541,6 +3541,10 @@ This function is called to see whether what the user has typed is a
> match. This is also available from functions that call
> 'completing-read', like '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'.
> +
> ** 'posn-col-row' can now give position data based on windows.
> Previously, it reported data only based on the frame.
>
> diff --git a/lisp/files.el b/lisp/files.el
> index b72f141c0ee..e78e8ea0a36 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -807,7 +807,7 @@ See Info node `(elisp)Standard File Names' for more details."
> (dos-convert-standard-filename filename))
> (t filename)))
>
> -(defun read-directory-name (prompt &optional dir default-dirname mustmatch initial)
> +(defun read-directory-name (prompt &optional dir default-dirname mustmatch initial predicate)
> "Read directory name, prompting with PROMPT and completing in directory DIR.
> Value is not expanded---you must call `expand-file-name' yourself.
> Default name to DEFAULT-DIRNAME if user exits with the same
> @@ -821,14 +821,16 @@ Fourth arg MUSTMATCH non-nil means require existing directory's name.
> Non-nil and non-t means also require confirmation after completion.
> 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'."
> (unless dir
> (setq dir default-directory))
> (read-file-name prompt dir (or default-dirname
> (if initial (expand-file-name initial dir)
> dir))
> mustmatch initial
> - 'file-directory-p))
> + (and #'file-directory-p predicate)))
I am not sure this makes sense, #'file-directory-p is always non-nil but
a PREDICATE will only be passed on to `read-file-name' is PREDICATE is
also non-nil. So if no PREDICATE is passed, the expression ignored
#'file-directory-p, breaking `read-directory-name', or am I mistaken (I
haven't tried it out)?
>
>
> (defun pwd (&optional insert)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 03:32:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 66224 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Philip Kaludercic <philipk <at> posteo.net> writes:
>
> I am not sure this makes sense, #'file-directory-p is always non-nil but
> a PREDICATE will only be passed on to `read-file-name' is PREDICATE is
> also non-nil. So if no PREDICATE is passed, the expression ignored
> #'file-directory-p, breaking `read-directory-name', or am I mistaken (I
> haven't tried it out)?
Oops! Thanks for catching my error!! The attached patch should actually
do what I intended.
Joseph
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 03:32:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 66224 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Philip Kaludercic <philipk <at> posteo.net> writes:
>
> I am not sure this makes sense, #'file-directory-p is always non-nil but
> a PREDICATE will only be passed on to `read-file-name' is PREDICATE is
> also non-nil. So if no PREDICATE is passed, the expression ignored
> #'file-directory-p, breaking `read-directory-name', or am I mistaken (I
> haven't tried it out)?
Oops! Thanks for catching my error!! The attached patch should actually
do what I intended.
Joseph
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 03:55:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 66224 <at> debbugs.gnu.org (full text, mbox):
Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
> - 'file-directory-p))
> + (lambda (filename)
> + (if predicate
> + (and (file-directory-p filename)
> + (funcall predicate filename))
> + (file-directory-p filename)))))
Yip. Nitpick: The code will be faster if you move the test out of the
predicate (so that it will not be performed repeatedly):
#+begin_src emacs-lisp
(if predicate
(lambda (filename)
(and (file-directory-p filename)
(funcall predicate filename)))
#'file-directory-p)
#+end_src
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 03:56:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 04:21:02 GMT)
Full text and
rfc822 format available.
Message #23 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Michael Heerdegen <michael_heerdegen <at> web.de> writes:
> Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs <at> gnu.org> writes:
>
>> - 'file-directory-p))
>> + (lambda (filename)
>> + (if predicate
>> + (and (file-directory-p filename)
>> + (funcall predicate filename))
>> + (file-directory-p filename)))))
>
> Yip. Nitpick: The code will be faster if you move the test out of the
> predicate (so that it will not be performed repeatedly):
>
> #+begin_src emacs-lisp
> (if predicate
> (lambda (filename)
> (and (file-directory-p filename)
> (funcall predicate filename)))
> #'file-directory-p)
> #+end_src
Thank you!! See attached patch.
Joseph
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 04:21:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Fri, 29 Sep 2023 12:07:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 66224 <at> debbugs.gnu.org (full text, mbox):
> 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?
> @@ -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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Tue, 03 Oct 2023 03:33:26 GMT)
Full text and
rfc822 format available.
Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):
Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
> Thank you!! See attached patch.
Yes, thanks, the code LGTM now.
You know that the predicate will be ignored when MUSTMATCH is t?
The behavior is not different than for `read-file-name'.
I think your patch is definitely a step in the right direction, but I
also still think we should think about the semantics of the restricting
arguments as a whole.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Tue, 03 Oct 2023 03:33:45 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Tue, 03 Oct 2023 23:19:02 GMT)
Full text and
rfc822 format available.
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)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Tue, 03 Oct 2023 23:24:01 GMT)
Full text and
rfc822 format available.
Message #41 received at submit <at> debbugs.gnu.org (full text, mbox):
Michael Heerdegen <michael_heerdegen <at> web.de> writes:
> You know that the predicate will be ignored when MUSTMATCH is t?
> The behavior is not different than for `read-file-name'.
I'm not sure what you mean. In both of the following examples, PREDICATE
is used to narrow the completion candidates to only empty directories:
(read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
(read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
Thank you!
Joseph
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Tue, 03 Oct 2023 23:24:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 05 Oct 2023 01:25:01 GMT)
Full text and
rfc822 format available.
Message #47 received at submit <at> debbugs.gnu.org (full text, mbox):
Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
> I'm not sure what you mean. In both of the following examples, PREDICATE
> is used to narrow the completion candidates to only empty directories:
>
> (read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
> (read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
In the second version also non-empty directories will be accepted.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 05 Oct 2023 01:25:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 05 Oct 2023 01:37:02 GMT)
Full text and
rfc822 format available.
Message #53 received at submit <at> debbugs.gnu.org (full text, mbox):
Michael Heerdegen <michael_heerdegen <at> web.de> writes:
> Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs <at> gnu.org> writes:
>
>> I'm not sure what you mean. In both of the following examples, PREDICATE
>> is used to narrow the completion candidates to only empty directories:
>>
>> (read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
>> (read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
>
> In the second version also non-empty directories will be accepted.
Yes, PREDICATE narrows the completion candidates but doesn't determine a
valid return value.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 05 Oct 2023 01:37:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Sun, 12 Nov 2023 20:46:02 GMT)
Full text and
rfc822 format available.
Message #59 received at submit <at> debbugs.gnu.org (full text, mbox):
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
> Michael Heerdegen <michael_heerdegen <at> web.de> writes:
>
>> Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
>> text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>
>>> I'm not sure what you mean. In both of the following examples, PREDICATE
>>> is used to narrow the completion candidates to only empty directories:
>>>
>>> (read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
>>> (read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
>>
>> In the second version also non-empty directories will be accepted.
>
> Yes, PREDICATE narrows the completion candidates but doesn't determine a
> valid return value.
Ping! I'm happy to keep discussing this patch if others are interested.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Sun, 12 Nov 2023 20:46:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Sat, 13 Jan 2024 10:54:01 GMT)
Full text and
rfc822 format available.
Message #65 received at 66224 <at> debbugs.gnu.org (full text, mbox):
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
> Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
>
>> Michael Heerdegen <michael_heerdegen <at> web.de> writes:
>>
>>> Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
>>> text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>>
>>>> I'm not sure what you mean. In both of the following examples, PREDICATE
>>>> is used to narrow the completion candidates to only empty directories:
>>>>
>>>> (read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
>>>> (read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
>>>
>>> In the second version also non-empty directories will be accepted.
>>
>> Yes, PREDICATE narrows the completion candidates but doesn't determine a
>> valid return value.
>
> Ping! I'm happy to keep discussing this patch if others are interested.
Could you please send the latest version of your patch?
Severity set to 'wishlist' from 'normal'
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 13 Jan 2024 10:55:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Sat, 13 Jan 2024 19:29:01 GMT)
Full text and
rfc822 format available.
Message #70 received at 66224 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Stefan Kangas <stefankangas <at> gmail.com> writes:
> Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
>
>> Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
>>
>>> Michael Heerdegen <michael_heerdegen <at> web.de> writes:
>>>
>>>> Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of
>>>> text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>>>
>>>>> I'm not sure what you mean. In both of the following examples, PREDICATE
>>>>> is used to narrow the completion candidates to only empty directories:
>>>>>
>>>>> (read-directory-name "Prompt: " "~/" nil t nil #'directory-empty-p)
>>>>> (read-directory-name "Prompt: " "~/" nil nil nil #'directory-empty-p)
>>>>
>>>> In the second version also non-empty directories will be accepted.
>>>
>>> Yes, PREDICATE narrows the completion candidates but doesn't determine a
>>> valid return value.
>>
>> Ping! I'm happy to keep discussing this patch if others are interested.
>
> Could you please send the latest version of your patch?
Here you go!
[0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch (text/x-diff, inline)]
From 894e44bce60cf30c9e8bc8c5323eaed91d135bbb Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph <at> breatheoutbreathe.in>
Date: Thu, 28 Sep 2023 20:27:47 -0700
Subject: [PATCH] Add optional PREDICATE argument to read-directory-name
* lisp/files.el (read-directory-name): Add optional PREDICATE arg.
* doc/lispref/minibuf.texi (Reading File Names): Document change.
* etc/NEWS: Note change.
---
doc/lispref/minibuf.texi | 7 +++++--
etc/NEWS | 5 +++++
lisp/files.el | 13 ++++++++++---
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index 620c58ec6e9..bf4d6e13d3a 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -1709,7 +1709,7 @@ If this variable is non-@code{nil}, @code{read-file-name} ignores case
when performing completion.
@end defopt
-@defun read-directory-name prompt &optional directory default require-match initial
+@defun read-directory-name prompt &optional directory default require-match initial predicate
This function is like @code{read-file-name} but allows only directory
names as completion alternatives.
@@ -1719,7 +1719,10 @@ 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}. When optional sixth
+argument @code{predicate} is non-nil, the union of @code{predicate}
+and @code{file-directory-p} is passed as the @code{predicate} argument
+to @code{read-file-name}.
@end defun
@defopt insert-default-directory
diff --git a/etc/NEWS b/etc/NEWS
index 1b3532b5657..fb9f6a0b43f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3541,6 +3541,11 @@ This function is called to see whether what the user has typed is a
match. This is also available from functions that call
'completing-read', like 'read-file-name'.
+** 'read-directory-name' now accepts an optional PREDICATE argument.
+When optional sixth argument PREDICATE is non-nil, the union of
+PREDICATE and 'file-directory-p' is passed as the PREDICATE argument
+to 'read-file-name'.
+
** 'posn-col-row' can now give position data based on windows.
Previously, it reported data only based on the frame.
diff --git a/lisp/files.el b/lisp/files.el
index b72f141c0ee..68855cd1c6d 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -807,7 +807,7 @@ See Info node `(elisp)Standard File Names' for more details."
(dos-convert-standard-filename filename))
(t filename)))
-(defun read-directory-name (prompt &optional dir default-dirname mustmatch initial)
+(defun read-directory-name (prompt &optional dir default-dirname mustmatch initial predicate)
"Read directory name, prompting with PROMPT and completing in directory DIR.
Value is not expanded---you must call `expand-file-name' yourself.
Default name to DEFAULT-DIRNAME if user exits with the same
@@ -821,14 +821,21 @@ Fourth arg MUSTMATCH non-nil means require existing directory's name.
Non-nil and non-t means also require confirmation after completion.
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'.
+When sixth arg PREDICATE is non-nil, the union of PREDICATE and
+`file-directory-p' is passed as the PREDICATE argument to
+`read-file-name'. Otherwise, only `file-directory-p' is passed."
(unless dir
(setq dir default-directory))
(read-file-name prompt dir (or default-dirname
(if initial (expand-file-name initial dir)
dir))
mustmatch initial
- 'file-directory-p))
+ (if predicate
+ (lambda (filename)
+ (and (file-directory-p filename)
+ (funcall predicate filename)))
+ #'file-directory-p)))
(defun pwd (&optional insert)
--
2.41.0
Reply sent
to
Stefan Kangas <stefankangas <at> gmail.com>
:
You have taken responsibility.
(Thu, 13 Feb 2025 07:50:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Joseph Turner <joseph <at> breatheoutbreathe.in>
:
bug acknowledged by developer.
(Thu, 13 Feb 2025 07:50:02 GMT)
Full text and
rfc822 format available.
Message #75 received at 66224-done <at> debbugs.gnu.org (full text, mbox):
Version: 31.1
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
>> Could you please send the latest version of your patch?
>
> Here you go!
Thanks for the patch!
Installed on master as commit 3f1d84d593b. Note that I partially
omitted the addition to the manual since we treat other optional
arguments by simply referring back to the read-file-name documentation.
In the followup commit 069c8ff6d58, I also made substantial changes to
the `read-directory-name` docstring. The majority of that was not
directly related to your changes, however.
I'm consequently closing this bug report.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66224
; Package
emacs
.
(Thu, 13 Feb 2025 21:50:02 GMT)
Full text and
rfc822 format available.
Message #78 received at 66224 <at> debbugs.gnu.org (full text, mbox):
help-debbugs <at> gnu.org (GNU bug Tracking System) writes:
> Your bug report
>
> #66224: [PATCH] Add optional PREDICATE argument to read-directory-name
>
> which was filed against the emacs package, has been closed.
>
> The explanation is attached below, along with your original report.
> If you require more details, please reply to 66224 <at> debbugs.gnu.org.
Thank you, Stefan!
Joseph
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 14 Mar 2025 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 55 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.