From a567eee4a5fc1f6129da5df463d29aa45edae3f4 Mon Sep 17 00:00:00 2001 From: Joseph Turner 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 argument. * doc/lispref/minibuf.texi (Reading File Names): Document above change. (Bug#66224) (cherry picked from commit 3f1d84d593bf864b72043ff2a598b18b5e9b05be) --- doc/lispref/minibuf.texi | 2 +- lisp/files.el | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index c10b6709db5..3447be2fe29 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -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. diff --git a/lisp/files.el b/lisp/files.el index f27c4f41ddf..a3d5d526fba 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -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))) (defun pwd (&optional insert) -- 2.39.5