]> git.eshelyaron.com Git - emacs.git/commitdiff
Add optional PREDICATE argument to read-directory-name
authorJoseph Turner <joseph@breatheoutbreathe.in>
Fri, 29 Sep 2023 03:27:47 +0000 (20:27 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 13 Feb 2025 11:53:16 +0000 (12:53 +0100)
* lisp/files.el (read-directory-name): Add optional PREDICATE argument.
* doc/lispref/minibuf.texi (Reading File Names): Document above change.
(Bug#66224)

(cherry picked from commit 3f1d84d593bf864b72043ff2a598b18b5e9b05be)

doc/lispref/minibuf.texi
lisp/files.el

index c10b6709db55ff9675a8981902937646e9dfe32d..3447be2fe29533de5bb320e1e6cfc5a17a42c9be 100644 (file)
@@ -1700,7 +1700,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.
 
index f27c4f41ddf2125e0231aadaa7d43e6df9cf95d4..a3d5d526fba2e60309b3bff15e111e3a53ba601a 100644 (file)
@@ -869,7 +869,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
@@ -883,14 +883,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)))
 
 \f
 (defun pwd (&optional insert)