all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: dalanicolai <dalanicolai@gmail.com>
To: 66542@debbugs.gnu.org
Subject: bug#66542: Fix: locate-dominating-file predicate should receive dir not file
Date: Sat, 14 Oct 2023 17:11:18 +0200	[thread overview]
Message-ID: <CACJP=3=OVLMxY0YKceXD+yNb36dJt7hr6kOA9YquHGFvt8e8Vw@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1153 bytes --]

Tags: patch

Tags: patch

The docstring of 'locate-dominating-file' mentions that its NAME argument
should be a dir, but currently it simply receives the FILE
argument. Therefore, using the function e.g. with the following predicate
for NAME

(lambda (dir)
(seq-filter (apply-partially #'string-match-p "paint")
(directory-files
dir)))

to check if a directory contains a file regexp-matching 'paint', throws
an error:

(file-error "Opening directory" "Not a directory" "/home/...")

This patch simply wraps the FILE argument in the (funcall NAME FILE) with
a 'file-name-directory' thereby fixing the function.

The commit log entry could read:
FIX: ensure that locate-dominating-file predicate recives dir


In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38,
 cairo version 1.17.8) of 2023-08-09 built on
 2a02-a45d-af56-1-666c-72af-583a-b92d.fixed6.kpn.net
Repository revision: 31cef9a4eac01fff5ff4fcb89d7e2b7815e93bad
Repository branch: HEAD
System Description: Fedora Linux 38 (Workstation Edition)

Configured using:
 'configure --with-tree-sitter --with-modules --with-cairo
 --with-native-compilation --with-json --with-pgtk'

[-- Attachment #1.2: Type: text/html, Size: 1506 bytes --]

[-- Attachment #2: locate-dominating-file-patch --]
[-- Type: application/octet-stream, Size: 590 bytes --]

diff --git a/lisp/files.el b/lisp/files.el
index e1421b403bf..19c88e5bc8a 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1138,7 +1138,7 @@ locate-dominating-file
       (setq try (if (stringp name)
                     (and (file-directory-p file)
                          (file-exists-p (expand-file-name name file)))
-                  (funcall name file)))
+                  (funcall name (file-name-directory file))))
       (cond (try (setq root file))
             ((equal file (setq file (file-name-directory
                                      (directory-file-name file))))

             reply	other threads:[~2023-10-14 15:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-14 15:11 dalanicolai [this message]
2023-10-14 15:46 ` bug#66542: Fix: locate-dominating-file predicate should receive dir not file Eli Zaretskii
2023-10-21 15:39   ` dalanicolai
2023-10-25 13:15     ` Eli Zaretskii
2023-10-26 13:27       ` dalanicolai

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACJP=3=OVLMxY0YKceXD+yNb36dJt7hr6kOA9YquHGFvt8e8Vw@mail.gmail.com' \
    --to=dalanicolai@gmail.com \
    --cc=66542@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 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.