GNU bug report logs - #23590
25.0.94; Errors in default lgrep command

Previous Next

Package: emacs;

Reported by: Alex <agrambot <at> gmail.com>

Date: Sat, 21 May 2016 00:12:01 UTC

Severity: normal

Tags: fixed, patch

Found in version 25.0.94

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #62 received at 23590 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: john.b.mastro <at> gmail.com, Eli Zaretskii <eliz <at> gnu.org>,
 23590 <at> debbugs.gnu.org, agrambot <at> gmail.com
Subject: Re: bug#23590: 25.0.94; Errors in default lgrep command
Date: Tue, 13 Oct 2020 23:09:22 +0300
[Message part 1 (text/plain, inline)]
>> The original bug report was about "M-x lgrep".  Can we make this
>> change affect only that command?
>>
>> In any case, this is a user-visible change, so it should be called out
>> in NEWS.
>
> Yup, and yup.

The latest fix has two problems:

1. it runs grep-probe every time lgrep is used;
2. it adds --directories=skip to the end of the command after regexp and file names

This patch improves both:

[grep-use-directories-skip.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index f028a4279d..9b1dc337e8 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -959,10 +959,10 @@ grep-expand-keywords
 these include `opts', `dir', `files', `null-device', `excl' and
 `regexp'.")
 
-(defun grep-expand-template (template &optional regexp files dir excl)
+(defun grep-expand-template (template &optional regexp files dir excl more-opts)
   "Expand grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
   (let* ((command template)
-         (env `((opts . ,(let (opts)
+         (env `((opts . ,(let ((opts more-opts))
                            (when (and case-fold-search
                                       (isearch-no-upper-case-p regexp t))
                              (push "-i" opts))
@@ -1058,6 +1058,8 @@ grep-read-files
 	 (or (cdr (assoc files grep-files-aliases))
 	     files))))
 
+(defvar grep-use-directories-skip 'auto-detect)
+
 ;;;###autoload
 (defun lgrep (regexp &optional files dir confirm)
   "Run grep, searching for REGEXP in FILES in directory DIR.
@@ -1103,6 +1105,12 @@ lgrep
 	  (if (string= command grep-command)
 	      (setq command nil))
 	(setq dir (file-name-as-directory (expand-file-name dir)))
+	(unless (or (not grep-use-directories-skip) (eq grep-use-directories-skip t))
+	  (setq grep-use-directories-skip
+		(grep-probe grep-program
+			  `(nil nil nil "--directories=skip" "foo"
+				,null-device)
+			  nil 1)))
 	(setq command (grep-expand-template
 		       grep-template
 		       regexp
@@ -1119,13 +1127,10 @@ lgrep
 						     (shell-quote-argument
 						      (cdr ignore))))))
 				     grep-find-ignored-files
-				     " --exclude=")))))
+				     " --exclude=")))
+		       (and grep-use-directories-skip
+			    '("--directories=skip"))))
 	(when command
-          (when (grep-probe grep-program
-                            `(nil nil nil "--directories=skip" "foo"
-                                  ,null-device)
-                            nil 1)
-            (setq command (concat command " --directories=skip")))
 	  (if confirm
 	      (setq command
 		    (read-from-minibuffer "Confirm: "

This bug report was last modified 4 years and 299 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.