From debbugs-submit-bounces@debbugs.gnu.org Wed May 22 08:29:10 2024 Received: (at submit) by debbugs.gnu.org; 22 May 2024 12:29:10 +0000 Received: from localhost ([127.0.0.1]:55647 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9l5h-00028O-MG for submit@debbugs.gnu.org; Wed, 22 May 2024 08:29:10 -0400 Received: from lists.gnu.org ([209.51.188.17]:50832) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9l5d-00028I-Ry for submit@debbugs.gnu.org; Wed, 22 May 2024 08:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9l5X-0004LA-O9 for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 08:28:59 -0400 Received: from mxout6.mail.janestreet.com ([64.215.233.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9l5T-0005Ee-St for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 08:28:59 -0400 From: Spencer Baugh To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix usage of cons cells in grep-find-ignored-files Date: Wed, 22 May 2024 08:28:53 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1716380933; bh=QMyY33hVQu2KSuLxtkUXwimWYqrsyGlR8PSP9wNzNJo=; h=From:To:Cc:Subject:Date; b=PBUjf9ZTspjfqm3OubvQ5DTGoHlCHnJBLQctIiemS6/EaZ/r07g7GwstO/QwoDW4M e/ZE/CNAEmXvsMOyY3xwcIfEYZJxG+x0r28t9Ai14dts7iLM12fKC6G659hd7pAmko RtJtCd9YAfrVtkm7ZztGTxuzohmJPv13Hb3BhvV0xadHMcr801lHgsl9OAMvCVzZfG 2TIvQFal69zAfR1OPIM2nDXBAYHRbxa3HcS8RX/xdRp+HX37OUGKIXc+V4AgTaBktF /pwXMcpncjDOVgp53z9S8bB8sd02kDRKdHD0krQZcnszalqhNxBk0AYo+xXwyaR4YB aX1JnhEzGLKqA== Received-SPF: pass client-ip=64.215.233.21; envelope-from=sbaugh@janestreet.com; helo=mxout6.mail.janestreet.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: dmitry@gutov.dev X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch grep-find-ignored-files is documented to also include cons cells, not just globs, but there were two places outside grep.el where we were using it as if it was only a string list. To fix this, add a helper function named grep-find-ignored-files which handles grep-find-ignored-files properly and returns the list of globs, and use it everywhere. * lisp/dired-aux.el (dired-do-find-regexp): Use grep-find-ignored-files function. * lisp/progmodes/grep.el (grep--filter-list-by-dir) (grep-find-ignored-files): Add. (rgrep-find-ignored-directories): Use grep--filter-list-by-dir. (lgrep, rgrep-default-command): Use grep-find-ignored-files function. * lisp/progmodes/project.el (project-ignores): Use grep-find-ignored-files function. In GNU Emacs 29.2.50 (build 11, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-05-15 built on igm-qws-u22796a Repository revision: 734740051bd377d24899d08d00ec8e1bb8e00e00 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.9 (Green Obsidian) Configured using: 'configure -C --with-x-toolkit=lucid --with-gif=ifavailable' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Fix-usage-of-cons-cells-in-grep-find-ignored-files.patch >From e0e969bf6b558be705c4a1962055a757881af074 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 22 May 2024 08:28:07 -0400 Subject: [PATCH] Fix usage of cons cells in grep-find-ignored-files grep-find-ignored-files is documented to also include cons cells, not just globs, but there were two places outside grep.el where we were using it as if it was only a string list. To fix this, add a helper function named grep-find-ignored-files which handles grep-find-ignored-files properly and returns the list of globs, and use it everywhere. * lisp/dired-aux.el (dired-do-find-regexp): Use grep-find-ignored-files function. * lisp/progmodes/grep.el (grep--filter-list-by-dir) (grep-find-ignored-files): Add. (rgrep-find-ignored-directories): Use grep--filter-list-by-dir. (lgrep, rgrep-default-command): Use grep-find-ignored-files function. * lisp/progmodes/project.el (project-ignores): Use grep-find-ignored-files function. --- lisp/dired-aux.el | 4 +- lisp/progmodes/grep.el | 99 +++++++++++++++++++-------------------- lisp/progmodes/project.el | 6 +-- 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index a2ce3083cfe..813c14a8661 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -3797,13 +3797,13 @@ dired-do-find-regexp (interactive "sSearch marked files (regexp): " dired-mode) (require 'grep) (require 'xref) - (defvar grep-find-ignored-files) (declare-function rgrep-find-ignored-directories "grep" (dir)) + (declare-function grep-find-ignored-files "grep" (dir)) (let* ((marks (dired-get-marked-files nil nil nil nil t)) (ignores (nconc (mapcar #'file-name-as-directory (rgrep-find-ignored-directories default-directory)) - grep-find-ignored-files)) + (grep-find-ignored-files default-directory))) (fetcher (lambda () (let (files xrefs) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 04056e13685..0003a6a395c 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -1176,6 +1176,19 @@ grep-read-files (defvar grep-use-directories-skip 'auto-detect) +(defun grep--filter-list-by-dir (list dir) + "Include elements of LIST which are applicable to DIR." + (delq nil (mapcar + (lambda (ignore) + (cond ((stringp ignore) ignore) + ((consp ignore) + (and (funcall (car ignore) dir) (cdr ignore))))) + list))) + +(defun grep-find-ignored-files (dir) + "Return the list of ignored files applicable to DIR." + (grep--filter-list-by-dir grep-find-ignored-files dir)) + ;;;###autoload (defun lgrep (regexp &optional files dir confirm) "Run grep, searching for REGEXP in FILES in directory DIR. @@ -1236,20 +1249,13 @@ lgrep regexp files nil - (and grep-find-ignored-files - (concat " --exclude=" - (mapconcat - (lambda (ignore) - (cond ((stringp ignore) - (shell-quote-argument - ignore grep-quoting-style)) - ((consp ignore) - (and (funcall (car ignore) dir) - (shell-quote-argument - (cdr ignore) - grep-quoting-style))))) - grep-find-ignored-files - " --exclude="))) + (when-let ((ignores (grep-find-ignored-files dir))) + (concat " --exclude=" + (mapconcat + (lambda (ignore) + (shell-quote-argument ignore grep-quoting-style)) + ignores + " --exclude="))) (and (eq grep-use-directories-skip t) '("--directories=skip")))) (when command @@ -1353,13 +1359,8 @@ rgrep (setq default-directory dir))))))) (defun rgrep-find-ignored-directories (dir) - "Return the list of ignored directories applicable to `dir'." - (delq nil (mapcar - (lambda (ignore) - (cond ((stringp ignore) ignore) - ((consp ignore) - (and (funcall (car ignore) dir) (cdr ignore))))) - grep-find-ignored-directories))) + "Return the list of ignored directories applicable to DIR." + (grep--filter-list-by-dir grep-find-ignored-directories dir)) (defun rgrep-default-command (regexp files dir) "Compute the command for \\[rgrep] to use by default." @@ -1377,37 +1378,31 @@ rgrep-default-command (shell-quote-argument ")" grep-quoting-style)) dir (concat - (and grep-find-ignored-directories - (concat "-type d " - (shell-quote-argument "(" grep-quoting-style) - ;; we should use shell-quote-argument here - " -path " - (mapconcat - (lambda (d) - (shell-quote-argument (concat "*/" d) grep-quoting-style)) - (rgrep-find-ignored-directories dir) - " -o -path ") - " " - (shell-quote-argument ")" grep-quoting-style) - " -prune -o ")) - (and grep-find-ignored-files - (concat (shell-quote-argument "!" grep-quoting-style) " -type d " - (shell-quote-argument "(" grep-quoting-style) - ;; we should use shell-quote-argument here - " -name " - (mapconcat - (lambda (ignore) - (cond ((stringp ignore) - (shell-quote-argument ignore grep-quoting-style)) - ((consp ignore) - (and (funcall (car ignore) dir) - (shell-quote-argument - (cdr ignore) grep-quoting-style))))) - grep-find-ignored-files - " -o -name ") - " " - (shell-quote-argument ")" grep-quoting-style) - " -prune -o "))))) + (when-let ((ignored-dirs (rgrep-find-ignored-directories dir))) + (concat "-type d " + (shell-quote-argument "(" grep-quoting-style) + ;; we should use shell-quote-argument here + " -path " + (mapconcat + (lambda (d) + (shell-quote-argument (concat "*/" d) grep-quoting-style)) + ignored-dirs + " -o -path ") + " " + (shell-quote-argument ")" grep-quoting-style) + " -prune -o ")) + (when-let ((ignored-files (grep-find-ignored-files dir))) + (concat (shell-quote-argument "!" grep-quoting-style) " -type d " + (shell-quote-argument "(" grep-quoting-style) + ;; we should use shell-quote-argument here + " -name " + (mapconcat + (lambda (ignore) (shell-quote-argument ignore grep-quoting-style)) + ignored-files + " -o -name ") + " " + (shell-quote-argument ")" grep-quoting-style) + " -prune -o "))))) (defun grep-find-toggle-abbreviation () "Toggle showing the hidden part of rgrep/lgrep/zrgrep command line." diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index abb11a1f2c5..18cf886c2fc 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -295,7 +295,7 @@ project-name Nominally unique, but not enforced." (file-name-nondirectory (directory-file-name (project-root project)))) -(cl-defgeneric project-ignores (_project _dir) +(cl-defgeneric project-ignores (_project dir) "Return the list of glob patterns to ignore inside DIR. Patterns can match both regular files and directories. To root an entry, start it with `./'. To match directories only, @@ -304,13 +304,13 @@ project-ignores ;; TODO: Document and support regexp ignores as used by Hg. ;; TODO: Support whitelist entries. (require 'grep) - (defvar grep-find-ignored-files) + (declare-function grep-find-ignored-files "grep" (dir)) (nconc (mapcar (lambda (dir) (concat dir "/")) vc-directory-exclusion-list) - grep-find-ignored-files)) + (grep-find-ignored-files dir))) (defun project--file-completion-table (all-files) (lambda (string pred action) -- 2.39.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed May 22 14:03:56 2024 Received: (at 71115) by debbugs.gnu.org; 22 May 2024 18:03:56 +0000 Received: from localhost ([127.0.0.1]:57362 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9qJg-0005oZ-EA for submit@debbugs.gnu.org; Wed, 22 May 2024 14:03:56 -0400 Received: from wfout6-smtp.messagingengine.com ([64.147.123.149]:60323) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9qJc-0005oT-VN for 71115@debbugs.gnu.org; Wed, 22 May 2024 14:03:54 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 997651C000ED; Wed, 22 May 2024 14:03:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 22 May 2024 14:03:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716401020; x=1716487420; bh=HiM0+V+39405fy45nZjdjp9jpKOxSHsXmdPXlyNCPYs=; b= hNopaPfoN7ViHWBXq85kMr1jjVGgPSDnCrsKcGLXb5ru6t7rCwpKQC+Kz5GkrXn2 Z4FlhmWLJHmVgSPlkq2lnkIdxSiwP4iR1SWXtJJasxX+2aySzwsXTfGHwP4sjk+J FYkfH61RLPAQRFMaZuFAKcrRj283/UEODsVvrFn+6QA81lOv5WxTtv6hSdSCAQ2W VR7u0eTcPa4y7M7toMOSO4MUuWTwnyqoMhw44PYRgjHno4ziPQdAQ4FD/dYt8J3C HtVYlBtSRI4vkMyfLwFqAgAGojc1VmL4XlboHuJ9fnaoVdusFm4xeQ3KrWgtRD+R QYaUK7QPCbDiQ1+4wOyiVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716401020; x= 1716487420; bh=HiM0+V+39405fy45nZjdjp9jpKOxSHsXmdPXlyNCPYs=; b=L NE/u3Ez++7NfG/7TOZYn34nzoQItpvtrjA2j1q0RQAUv+nR7HHS7Qf7VBMMMjoI0 eA1PFzLX+B9gaVkaP5WgkejRetkijNCp2iqKLgkKn3v1+oQRSJ+nDqkelSHa7wX3 DZYG1fRQ7OSMaXG4USTefoc2LheUNo6C+r9tH5sylRcX4KHqBfqHvN7mxVQWf4tx hItTeNUxROzf2T1OwbnF0w0+iQ02VtievXxYNESvV/txQa2qqHa0v7Zer49xymr2 kTUIVissTwLjSM9NNDglBdZ5J1JhMpYFEgVOLJAy2a+C8zuwO7cOk6D6ByNM1xhF 08TOtUgT3RBV11mPGXbyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeigedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthejredttddvjeenucfhrhhomhepffhmihht rhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrghtth gvrhhnpedthfeuvddtveelgeeuleevvdejveehffevveehvdeuffdtfefhvdeugefgtefg tdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumh hithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 May 2024 14:03:39 -0400 (EDT) Message-ID: <2cfe6519-6091-4d5f-a0f3-7ad14146851d@gutov.dev> Date: Wed, 22 May 2024 21:03:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#71115: [PATCH] Fix usage of cons cells in grep-find-ignored-files To: Spencer Baugh , 71115@debbugs.gnu.org References: Content-Language: en-US From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 71115 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Spencer, Thanks a lot. On 22/05/2024 15:28, Spencer Baugh wrote: > --- a/lisp/progmodes/project.el > +++ b/lisp/progmodes/project.el > @@ -295,7 +295,7 @@ project-name > Nominally unique, but not enforced." > (file-name-nondirectory (directory-file-name (project-root project)))) > > -(cl-defgeneric project-ignores (_project _dir) > +(cl-defgeneric project-ignores (_project dir) > "Return the list of glob patterns to ignore inside DIR. > Patterns can match both regular files and directories. > To root an entry, start it with `./'. To match directories only, > @@ -304,13 +304,13 @@ project-ignores > ;; TODO: Document and support regexp ignores as used by Hg. > ;; TODO: Support whitelist entries. > (require 'grep) > - (defvar grep-find-ignored-files) > + (declare-function grep-find-ignored-files "grep" (dir)) > (nconc > (mapcar > (lambda (dir) > (concat dir "/")) > vc-directory-exclusion-list) > - grep-find-ignored-files)) > + (grep-find-ignored-files dir))) There is just one problem that project.el is supposed to be usable in Emacs 26+. I suppose that a little fboundp check will get us around the problem. From debbugs-submit-bounces@debbugs.gnu.org Thu May 23 11:04:55 2024 Received: (at 71115) by debbugs.gnu.org; 23 May 2024 15:04:55 +0000 Received: from localhost ([127.0.0.1]:59454 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sA9zy-0003kW-Ok for submit@debbugs.gnu.org; Thu, 23 May 2024 11:04:55 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:59979) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sA9zv-0003kO-9H for 71115@debbugs.gnu.org; Thu, 23 May 2024 11:04:53 -0400 From: Spencer Baugh To: Dmitry Gutov Subject: Re: bug#71115: [PATCH] Fix usage of cons cells in grep-find-ignored-files In-Reply-To: <2cfe6519-6091-4d5f-a0f3-7ad14146851d@gutov.dev> (Dmitry Gutov's message of "Wed, 22 May 2024 21:03:37 +0300") References: <2cfe6519-6091-4d5f-a0f3-7ad14146851d@gutov.dev> Date: Thu, 23 May 2024 11:04:39 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1716476679; bh=G3rIt729w//iNP0+O6xx+7L58osIpzjNGZAnzNzNo2o=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=h0jbEpv56zgkAIYmiDWLkmvWqSPHGfkuMXqbikxhvP48+W4ynFDZYZdpHPUQQW3zi ZhNyrsYRXMIDddK1HSJunFdBmJ8LK3Dxj2yOprt4WWeyx4y7Bwx5JZg4OAKfoVWQ++ +83p8R8eNk4YVUo7jp26QsLlPQ1hSg1YQuZxXE3zBSKonFkN0hs9ydbIHQe1HAII3E UjiWG2unJEqwBp/DdRNAUNpO6uQAYxrR9FtVPLZh9BEDHecCdEQeUw+BVoH1/d+b+a iGATduR1XKxeL2RrnA7lEXKrKujGYlbz7f/uhhJJG3itA4ZuE00JXp3s+M3R6K8oV4 Mx9z+wu0IYDHw== X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 71115 Cc: 71115@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) --=-=-= Content-Type: text/plain Dmitry Gutov writes: > Hi Spencer, > > Thanks a lot. > > On 22/05/2024 15:28, Spencer Baugh wrote: >> --- a/lisp/progmodes/project.el >> +++ b/lisp/progmodes/project.el >> @@ -295,7 +295,7 @@ project-name >> Nominally unique, but not enforced." >> (file-name-nondirectory (directory-file-name (project-root project)))) >> -(cl-defgeneric project-ignores (_project _dir) >> +(cl-defgeneric project-ignores (_project dir) >> "Return the list of glob patterns to ignore inside DIR. >> Patterns can match both regular files and directories. >> To root an entry, start it with `./'. To match directories only, >> @@ -304,13 +304,13 @@ project-ignores >> ;; TODO: Document and support regexp ignores as used by Hg. >> ;; TODO: Support whitelist entries. >> (require 'grep) >> - (defvar grep-find-ignored-files) >> + (declare-function grep-find-ignored-files "grep" (dir)) >> (nconc >> (mapcar >> (lambda (dir) >> (concat dir "/")) >> vc-directory-exclusion-list) >> - grep-find-ignored-files)) >> + (grep-find-ignored-files dir))) > > There is just one problem that project.el is supposed to be usable in > Emacs 26+. > > I suppose that a little fboundp check will get us around the problem. Fixed: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-usage-of-cons-cells-in-grep-find-ignored-files.patch >From 5c9312f47e5a4286c84d01e30133edecb5e8a648 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 22 May 2024 08:28:07 -0400 Subject: [PATCH] Fix usage of cons cells in grep-find-ignored-files grep-find-ignored-files is documented to also include cons cells, not just globs, but there were two places outside grep.el where we were using it as if it was only a string list. To fix this, add a helper function named grep-find-ignored-files which handles grep-find-ignored-files properly and returns the list of globs, and use it everywhere. * lisp/progmodes/grep.el (grep--filter-list-by-dir) (grep-find-ignored-files): Add. (rgrep-find-ignored-directories): Use grep--filter-list-by-dir. (lgrep, rgrep-default-command): Use grep-find-ignored-files function. * lisp/dired-aux.el (dired-do-find-regexp): Use grep-find-ignored-files function. * lisp/progmodes/project.el (project-ignores): Use grep-find-ignored-files function, if bound. (bug#71115) --- lisp/dired-aux.el | 4 +- lisp/progmodes/grep.el | 99 +++++++++++++++++++-------------------- lisp/progmodes/project.el | 8 +++- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index a2ce3083cfe..813c14a8661 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -3797,13 +3797,13 @@ dired-do-find-regexp (interactive "sSearch marked files (regexp): " dired-mode) (require 'grep) (require 'xref) - (defvar grep-find-ignored-files) (declare-function rgrep-find-ignored-directories "grep" (dir)) + (declare-function grep-find-ignored-files "grep" (dir)) (let* ((marks (dired-get-marked-files nil nil nil nil t)) (ignores (nconc (mapcar #'file-name-as-directory (rgrep-find-ignored-directories default-directory)) - grep-find-ignored-files)) + (grep-find-ignored-files default-directory))) (fetcher (lambda () (let (files xrefs) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 657349cbdff..0a9de04fce1 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -1176,6 +1176,19 @@ grep-read-files (defvar grep-use-directories-skip 'auto-detect) +(defun grep--filter-list-by-dir (list dir) + "Include elements of LIST which are applicable to DIR." + (delq nil (mapcar + (lambda (ignore) + (cond ((stringp ignore) ignore) + ((consp ignore) + (and (funcall (car ignore) dir) (cdr ignore))))) + list))) + +(defun grep-find-ignored-files (dir) + "Return the list of ignored files applicable to DIR." + (grep--filter-list-by-dir grep-find-ignored-files dir)) + ;;;###autoload (defun lgrep (regexp &optional files dir confirm) "Run grep, searching for REGEXP in FILES in directory DIR. @@ -1236,20 +1249,13 @@ lgrep regexp files nil - (and grep-find-ignored-files - (concat " --exclude=" - (mapconcat - (lambda (ignore) - (cond ((stringp ignore) - (shell-quote-argument - ignore grep-quoting-style)) - ((consp ignore) - (and (funcall (car ignore) dir) - (shell-quote-argument - (cdr ignore) - grep-quoting-style))))) - grep-find-ignored-files - " --exclude="))) + (when-let ((ignores (grep-find-ignored-files dir))) + (concat " --exclude=" + (mapconcat + (lambda (ignore) + (shell-quote-argument ignore grep-quoting-style)) + ignores + " --exclude="))) (and (eq grep-use-directories-skip t) '("--directories=skip")))) (when command @@ -1353,13 +1359,8 @@ rgrep (setq default-directory dir))))))) (defun rgrep-find-ignored-directories (dir) - "Return the list of ignored directories applicable to `dir'." - (delq nil (mapcar - (lambda (ignore) - (cond ((stringp ignore) ignore) - ((consp ignore) - (and (funcall (car ignore) dir) (cdr ignore))))) - grep-find-ignored-directories))) + "Return the list of ignored directories applicable to DIR." + (grep--filter-list-by-dir grep-find-ignored-directories dir)) (defun rgrep-default-command (regexp files dir) "Compute the command for \\[rgrep] to use by default." @@ -1377,37 +1378,31 @@ rgrep-default-command (shell-quote-argument ")" grep-quoting-style)) dir (concat - (and grep-find-ignored-directories - (concat "-type d " - (shell-quote-argument "(" grep-quoting-style) - ;; we should use shell-quote-argument here - " -path " - (mapconcat - (lambda (d) - (shell-quote-argument (concat "*/" d) grep-quoting-style)) - (rgrep-find-ignored-directories dir) - " -o -path ") - " " - (shell-quote-argument ")" grep-quoting-style) - " -prune -o ")) - (and grep-find-ignored-files - (concat (shell-quote-argument "!" grep-quoting-style) " -type d " - (shell-quote-argument "(" grep-quoting-style) - ;; we should use shell-quote-argument here - " -name " - (mapconcat - (lambda (ignore) - (cond ((stringp ignore) - (shell-quote-argument ignore grep-quoting-style)) - ((consp ignore) - (and (funcall (car ignore) dir) - (shell-quote-argument - (cdr ignore) grep-quoting-style))))) - grep-find-ignored-files - " -o -name ") - " " - (shell-quote-argument ")" grep-quoting-style) - " -prune -o "))))) + (when-let ((ignored-dirs (rgrep-find-ignored-directories dir))) + (concat "-type d " + (shell-quote-argument "(" grep-quoting-style) + ;; we should use shell-quote-argument here + " -path " + (mapconcat + (lambda (d) + (shell-quote-argument (concat "*/" d) grep-quoting-style)) + ignored-dirs + " -o -path ") + " " + (shell-quote-argument ")" grep-quoting-style) + " -prune -o ")) + (when-let ((ignored-files (grep-find-ignored-files dir))) + (concat (shell-quote-argument "!" grep-quoting-style) " -type d " + (shell-quote-argument "(" grep-quoting-style) + ;; we should use shell-quote-argument here + " -name " + (mapconcat + (lambda (ignore) (shell-quote-argument ignore grep-quoting-style)) + ignored-files + " -o -name ") + " " + (shell-quote-argument ")" grep-quoting-style) + " -prune -o "))))) (defun grep-find-toggle-abbreviation () "Toggle showing the hidden part of rgrep/lgrep/zrgrep command line." diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index abb11a1f2c5..294938c42ca 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -295,7 +295,7 @@ project-name Nominally unique, but not enforced." (file-name-nondirectory (directory-file-name (project-root project)))) -(cl-defgeneric project-ignores (_project _dir) +(cl-defgeneric project-ignores (_project dir) "Return the list of glob patterns to ignore inside DIR. Patterns can match both regular files and directories. To root an entry, start it with `./'. To match directories only, @@ -305,12 +305,16 @@ project-ignores ;; TODO: Support whitelist entries. (require 'grep) (defvar grep-find-ignored-files) + (declare-function grep-find-ignored-files "grep" (dir)) + (debug) (nconc (mapcar (lambda (dir) (concat dir "/")) vc-directory-exclusion-list) - grep-find-ignored-files)) + (if (fboundp 'grep-find-ignored-files) + (grep-find-ignored-files dir) + grep-find-ignored-files))) (defun project--file-completion-table (all-files) (lambda (string pred action) -- 2.39.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri May 24 16:06:23 2024 Received: (at 71115-done) by debbugs.gnu.org; 24 May 2024 20:06:23 +0000 Received: from localhost ([127.0.0.1]:38926 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAbBG-0006Bj-Li for submit@debbugs.gnu.org; Fri, 24 May 2024 16:06:23 -0400 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]:48959) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAbAz-0006BK-W8 for 71115-done@debbugs.gnu.org; Fri, 24 May 2024 16:06:21 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 12F711140157; Fri, 24 May 2024 16:05:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 24 May 2024 16:05:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1716581153; x=1716667553; bh=kAftJr3X19QUuWCzOh5dRmAx9JKIZo3uH8SwtY+342U=; b= ZBuDjGv1whYJsQQlzuLRkHRgY1uxI/uyZYMHEC9UZjQvTHJzV3919XaG6fMDp6gj sYDH5mJQtheFtqY0JW/Jrd65LdJBNcj8ZXTv6hhPm46MC5UECF1t2oujt2itv2P3 9CimC/g4cIgX6f1XlvWu6Z0rnfmE0w5rzwznECXJeAHeszNlOCD+U/JYQiwFmERM sOvLcWgLlTP+k+gdApwotkZyAcK+0CmleJmWxHY1JhwJrdcGlGKKxgbn4d1EK+xz eL5j+Eg1JL4g5+Ofv8KA11s+7lOLGoN7tSasY9SqXf/zolXlMYz5t5Yl942JWAfV iCcXt0SIFBgbr32Eu2NzSw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716581153; x= 1716667553; bh=kAftJr3X19QUuWCzOh5dRmAx9JKIZo3uH8SwtY+342U=; b=M CsZiqmR4lpHoojLlMQ35iFiPECAhEnneL9gasOMw9IWy/N/35KY8v7V42pXQzb/G oWc6w+UEPFUxylb44yeyTGzUGHnKjJuaeM46m8e11jdR7bK/HVlZjxqkMrT8nxG2 GQqeVrqF5j3dH9FpANET+8OspX3YLgUWYA/97SZNvm85SKmmsznwYTgc3adipbaU jTyzhI36pIWhoBSa8vGNxKu+JZD4NK+nllkkC99D1DX0j4RQGSmTAXRRzez9MQbP zc7deJ72VK3fmodSSSgL1S+7F9EjTbmwvv7IrrPooYVvzwbf4j/JCyGCN2dUvIN8 nHBEvEnsxn89ZErUusG0w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeikedgudegvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepffhm ihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrg htthgvrhhnpeetudeljeegheetgfehgeejkeeuhedvveeikeeufedtvddtveefhfdvveeg udejheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gumhhithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 May 2024 16:05:51 -0400 (EDT) Message-ID: <5223dad4-8caa-4839-a8d0-ad02dc087366@gutov.dev> Date: Fri, 24 May 2024 23:05:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#71115: [PATCH] Fix usage of cons cells in grep-find-ignored-files To: Spencer Baugh References: <2cfe6519-6091-4d5f-a0f3-7ad14146851d@gutov.dev> Content-Language: en-US From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 71115-done Cc: 71115-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) On 23/05/2024 18:04, Spencer Baugh wrote: >> There is just one problem that project.el is supposed to be usable in >> Emacs 26+. >> >> I suppose that a little fboundp check will get us around the problem. > Fixed: Thanks, pushed to master as commit c812c935486. (Sans the little (debug) Easter egg ;-) From unknown Sat Jun 21 10:25:14 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 22 Jun 2024 11:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator