all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58364: [PATCH] Add new function 'file-name-parent-p'
@ 2022-10-07 20:23 Philip Kaludercic
       [not found] ` <handler.58364.B.16651742163752.ack@debbugs.gnu.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Philip Kaludercic @ 2022-10-07 20:23 UTC (permalink / raw)
  To: 58364

[-- 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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-08 17:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-07 20:23 bug#58364: [PATCH] Add new function 'file-name-parent-p' Philip Kaludercic
     [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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.