From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66224: [PATCH] Add optional PREDICATE argument to read-directory-name Date: Thu, 28 Sep 2023 21:19:24 -0700 Message-ID: <877co9y5jt.fsf@breatheoutbreathe.in> References: <877coch0q7.fsf@breatheoutbreathe.in> <874jje1xds.fsf@posteo.net> <87bkdly7t4.fsf@breatheoutbreathe.in> <871qehr5vs.fsf@web.de> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34732"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66224@debbugs.gnu.org, philipk@posteo.net To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 29 06:21:14 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qm506-0008oE-0T for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 29 Sep 2023 06:21:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qm4zk-0006VD-U8; Fri, 29 Sep 2023 00:20:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qm4zi-0006Uw-9k for bug-gnu-emacs@gnu.org; Fri, 29 Sep 2023 00:20:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qm4zg-0003mN-Do for bug-gnu-emacs@gnu.org; Fri, 29 Sep 2023 00:20:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qm4zu-0004W8-L1 for bug-gnu-emacs@gnu.org; Fri, 29 Sep 2023 00:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 29 Sep 2023 04:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66224 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: "Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors" , 66224@debbugs.gnu.org, Philip Kaludercic Original-Received: via spool by 66224-submit@debbugs.gnu.org id=B66224.169596121617272 (code B ref 66224); Fri, 29 Sep 2023 04:21:02 +0000 Original-Received: (at 66224) by debbugs.gnu.org; 29 Sep 2023 04:20:16 +0000 Original-Received: from localhost ([127.0.0.1]:54808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qm4z9-0004UU-Qq for submit@debbugs.gnu.org; Fri, 29 Sep 2023 00:20:16 -0400 Original-Received: from out-197.mta1.migadu.com ([2001:41d0:203:375::c5]:43533) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qm4z4-0004UF-Fo for 66224@debbugs.gnu.org; Fri, 29 Sep 2023 00:20:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1695961194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DKaIlgOIMXW6yvN+EX4GN4faypFbpBe+5YKWELfQyNM=; b=UNPH9qU1DSJa2svOZ6/iweX5Pk96N7xA9A0SApDDrNncde6WdN+nB1mMicX9uT9cqGRlc7 BBKhWte4C8lB82XY0py+pMUhFl+yfy0Up2XFxufxGlzJg/ln8GFKcBA/GnXbMc9ePHMNgB 3QJyVg7czSCaiPqmuVxl0+l7HyTVHUo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <871qehr5vs.fsf@web.de> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271465 Archived-At: --=-=-= Content-Type: text/plain Michael Heerdegen writes: > Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of > text editors" 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-optional-PREDICATE-argument-to-read-directory-na.patch >From 894e44bce60cf30c9e8bc8c5323eaed91d135bbb 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 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 --=-=-=--