emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b13e0c1: * lisp/progmodes/grep.el: More fixes for 'lgrep' (bug#23


From: Juri Linkov
Subject: master b13e0c1: * lisp/progmodes/grep.el: More fixes for 'lgrep' (bug#23590)
Date: Wed, 14 Oct 2020 04:45:40 -0400 (EDT)

branch: master
commit b13e0c1501a21e942692718194c634e01a13928a
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/progmodes/grep.el: More fixes for 'lgrep' (bug#23590)
    
    * lisp/progmodes/grep.el (grep-expand-template): Add new arg 'more-opts'.
    (grep-use-directories-skip): New variable.
    (lgrep): Set 'grep-use-directories-skip' to the result of 'grep-probe'.
    Use "--directories=skip" when 'grep-use-directories-skip' is t.
---
 lisp/progmodes/grep.el | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index f028a42..9683826 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -959,10 +959,10 @@ The substitution is based on variables bound dynamically, 
and
 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 @@ REGEXP is used as a string in the prompt."
         (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 @@ command before it's run."
          (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 @@ command before it's run."
                                                     (shell-quote-argument
                                                      (cdr ignore))))))
                                     grep-find-ignored-files
-                                    " --exclude=")))))
+                                    " --exclude=")))
+                      (and (eq grep-use-directories-skip t)
+                           '("--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: "



reply via email to

[Prev in Thread] Current Thread [Next in Thread]