Subject: bug#58364: closed (Re: bug#58364: [PATCH] Add new function 'file-name-parent-p')

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 08 Oct 2022 07:22:02 +0000

Your bug report

#58364: [PATCH] Add new function 'file-name-parent-p'

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 [email-masked].

-- 
58364: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58364
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#58364: [PATCH] Add new function 'file-name-parent-p'
From: Philip Kaludercic <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked]
Date: Sat, 08 Oct 2022 07:21:01 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Eli Zaretskii <[email-masked]> writes:

>> From: Philip Kaludercic <[email-masked]>
>> Date: Fri, 07 Oct 2022 20:23:27 +0000
>> 
>> Unless I am mistaken, there is no direct function to quickly test if a
>> directory is a super-directory of file.  As I have encountered this
>> issue more than once the last few days of hacking, I would like to
>> propose the below function.
>
> We have file-in-directory-p.  Doesn't that fit the bill?

I hive tried it out and yes that was the function I was looking for.  My
apologies for the noise.

Subject: [PATCH] Add new function 'file-name-parent-p'
From: Philip Kaludercic <[email-masked]>
To: [email-masked]
Date: Fri, 07 Oct 2022 20:23:27 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

Unless I am mistaken, there is no direct function to quickly test if a
directory is a super-directory of file.  As I have encountered this
issue more than once the last few days of hacking, I would like to
propose the below function.

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-10-07 built on rhea
Repository revision: 51f5a7cf127934aa93d860c8fd3e8d58fbc594cb
Repository branch: feature/package+vc
System Description: Fedora Linux 36 (Workstation Edition)

Configured using:
 'configure --with-pgtk --with-imagemagick'

>From 87ca79778f3220c80826257d2b67e405940a9b11 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <[email-masked]>
Date: Fri, 7 Oct 2022 22:20:30 +0200
Subject: [PATCH] Add new function 'file-name-parent-p'

* doc/lispref/files.texi (Directory Names): Explain it.
* etc/NEWS: Mention in.
* lisp/files.el (file-name-parent-p): Add it.
---
 doc/lispref/files.texi | 5 +++++
 etc/NEWS               | 4 ++++
 lisp/files.el          | 5 +++++
 3 files changed, 14 insertions(+)

diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index e1aa2de523..30cc950ad2 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2454,6 +2454,11 @@ Directory Names
 non-@code{nil}, it ends in a slash.
 @end defun
 
+@defun file-name-parent-p directory filename
+This function will return a non-@code{nil} value if @var{directory} is
+a parent directory of @var{filename}.
+@end defun
+
 @node File Name Expansion
 @subsection Functions that Expand Filenames
 @cindex expansion of file names
diff --git a/etc/NEWS b/etc/NEWS
index 68cd8bd906..c02ff2ecb5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3675,6 +3675,10 @@ This returns a list of all the components of a file name.
 ** New function 'file-name-parent-directory'.
 This returns the parent directory of a file name.
 
++++
+** New function 'file-name-parent-p'.
+This checks if a directory is an eventual parent of a file.
+
 +++
 ** New macro 'with-undo-amalgamate'.
 It records a particular sequence of operations as a single undo step.
diff --git a/lisp/files.el b/lisp/files.el
index 43c5d7d1da..1a670b25a9 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5220,6 +5220,11 @@ file-name-parent-directory
      (t
       parent))))
 
+(defun file-name-parent-p (dir file)
+  "Return non-nil if DIR is a parent-directory of FILE."
+  (and (locate-dominating-file file (apply-partially #'file-equal-p dir))
+       t))
+
 (defcustom make-backup-file-name-function
   #'make-backup-file-name--default-function
   "A function that `make-backup-file-name' uses to create backup file names.
-- 
2.37.3