From: Philip Kaludercic <philipk@posteo.net>
To: 58364@debbugs.gnu.org
Subject: bug#58364: [PATCH] Add new function 'file-name-parent-p'
Date: Fri, 07 Oct 2022 20:23:27 +0000 [thread overview]
Message-ID: <87h70f758g.fsf@posteo.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 597 bytes --]
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'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-function-file-name-parent-p.patch --]
[-- Type: text/patch, Size: 2059 bytes --]
From 87ca79778f3220c80826257d2b67e405940a9b11 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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
next reply other threads:[~2022-10-07 20:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-07 20:23 Philip Kaludercic [this message]
[not found] ` <handler.58364.B.16651742163752.ack@debbugs.gnu.org>
2022-10-07 20:46 ` bug#58364: Acknowledgement ([PATCH] Add new function 'file-name-parent-p') Philip Kaludercic
2022-10-07 21:10 ` bug#58364: [PATCH] Add new function 'file-name-parent-p' Drew Adams
2022-10-08 6:17 ` Eli Zaretskii
2022-10-08 7:21 ` Philip Kaludercic
2022-10-08 8:01 ` Eli Zaretskii
2022-10-08 9:23 ` Philip Kaludercic
2022-10-08 10:10 ` Eli Zaretskii
2022-10-08 10:29 ` Philip Kaludercic
2022-10-08 11:16 ` Eli Zaretskii
2022-10-08 17:20 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h70f758g.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=58364@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).