bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66224: [PATCH] Add optional PREDICATE argument to read-directory-nam


From: Philip Kaludercic
Subject: bug#66224: [PATCH] Add optional PREDICATE argument to read-directory-name
Date: Thu, 28 Sep 2023 09:05:03 +0000

Joseph Turner <joseph@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@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)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]