From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#58364: [PATCH] Add new function 'file-name-parent-p' Date: Fri, 07 Oct 2022 20:23:27 +0000 Message-ID: <87h70f758g.fsf@posteo.net> 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="6326"; mail-complaints-to="usenet@ciao.gmane.io" To: 58364@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 07 22:24:12 2022 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 1ogttD-0001R7-Hr for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 Oct 2022 22:24:11 +0200 Original-Received: from localhost ([::1]:34314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogttC-0001oi-46 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 Oct 2022 16:24:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogtt4-0001oS-Jb for bug-gnu-emacs@gnu.org; Fri, 07 Oct 2022 16:24:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ogtt4-0007Uh-9M for bug-gnu-emacs@gnu.org; Fri, 07 Oct 2022 16:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ogtt3-0000z8-SI for bug-gnu-emacs@gnu.org; Fri, 07 Oct 2022 16:24:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 07 Oct 2022 20:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58364 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16651742163752 (code B ref -1); Fri, 07 Oct 2022 20:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Oct 2022 20:23:36 +0000 Original-Received: from localhost ([127.0.0.1]:37499 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogtse-0000yS-8v for submit@debbugs.gnu.org; Fri, 07 Oct 2022 16:23:36 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:43832) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogtsc-0000yH-JF for submit@debbugs.gnu.org; Fri, 07 Oct 2022 16:23:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogtsc-0001lu-EP for bug-gnu-emacs@gnu.org; Fri, 07 Oct 2022 16:23:34 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:35793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogtsa-0007Sx-HY for bug-gnu-emacs@gnu.org; Fri, 07 Oct 2022 16:23:34 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id F3BB2240103 for ; Fri, 7 Oct 2022 22:23:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1665174209; bh=H/NHws3jP8j5PE3VUaGf48fLJspIH8gqkRJRVcpdWqc=; h=From:To:Subject:Autocrypt:Date:From; b=qnoz0GAWQ/xfysv4UQtGBqw1K+yS8mtkbBhQyeg1tDk/6bwUbE8bR7br/5q16/gKk rIUZhLZuuN/xjNGxTcmSby4DD9PpFIX5X4JsLSwSobSPg3fBgVZ10B7tGZhRqyt04g 37WLcP7D9LuXfuxi2HqmIgvuZGWJb8qtyVutiko/Uu8kEowxcasEIr7GW4FEUg2WP9 FD3Gv7AMsA7mBUluJZLU4CgDm7+NyRn+YY39oYtI97WDpz/vxszLftioffjGoTa8mm z6tGVa+TDAt3cSTNyXIw+nlniiOUAi5mb3tAjOYLf7A9tJY7cFhsgf/l1554hNXAqQ ta0C53ufSqRew== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Mkfrw3qwNz9rxH for ; Fri, 7 Oct 2022 22:23:28 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:244848 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-new-function-file-name-parent-p.patch >From 87ca79778f3220c80826257d2b67e405940a9b11 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-=--