]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/grep.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / progmodes / grep.el
index e20e5bd4c40c3bc18e7a6fe41f45071e4418bd09..f04a7226d1865d0ca569453b0379c5cec5abf287 100644 (file)
@@ -1,6 +1,6 @@
 ;;; grep.el --- run `grep' and display the results  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1985-1987, 1993-1999, 2001-2015 Free Software
+;; Copyright (C) 1985-1987, 1993-1999, 2001-2016 Free Software
 ;; Foundation, Inc.
 
 ;; Author: Roland McGrath <roland@gnu.org>
@@ -189,7 +189,7 @@ Customize or call the function `grep-apply-setting'."
   :group 'grep)
 
 (defcustom grep-files-aliases
-  '(("all" .   "* .*")
+  '(("all" .   "* .[!.]* ..?*") ;; Don't match `..'. See bug#22577
     ("el" .    "*.el")
     ("ch" .    "*.[ch]")
     ("c" .     "*.c")
@@ -579,7 +579,7 @@ This function is called from `compilation-filter-hook'."
                         " -e"))))
        (unless grep-command
          (setq grep-command
-               (format "%s %s %s " grep-program grep-options
+               (format "%s %s %s " grep-program
                         (or
                          (and grep-highlight-matches
                               (grep-probe grep-program
@@ -587,7 +587,8 @@ This function is called from `compilation-filter-hook'."
                                           nil 1)
                               (if (eq grep-highlight-matches 'always)
                                   "--color=always" "--color"))
-                         ""))))
+                         "")
+                         grep-options)))
        (unless grep-template
          (setq grep-template
                (format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
@@ -730,21 +731,24 @@ This function is called from `compilation-filter-hook'."
 
 ;;;###autoload
 (defun grep (command-args)
-  "Run grep, with user-specified args, and collect output in a buffer.
-While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
+  "Run Grep with user-specified COMMAND-ARGS, collect output in a buffer.
+While Grep runs asynchronously, you can use \\[next-error] (M-x next-error),
 or \\<grep-mode-map>\\[compile-goto-error] in the *grep* \
-buffer, to go to the lines where grep found
-matches.  To kill the grep job before it finishes, type \\[kill-compilation].
+buffer, to go to the lines where Grep found
+matches.  To kill the Grep job before it finishes, type \\[kill-compilation].
+
+Noninteractively, COMMAND-ARGS should specify the Grep command-line
+arguments.
 
 For doing a recursive `grep', see the `rgrep' command.  For running
-`grep' in a specific directory, see `lgrep'.
+Grep in a specific directory, see `lgrep'.
 
 This command uses a special history list for its COMMAND-ARGS, so you
 can easily repeat a grep command.
 
-A prefix argument says to default the argument based upon the current
-tag the cursor is over, substituting it into the last grep command
-in the grep command history (or into `grep-command' if that history
+A prefix argument says to default the COMMAND-ARGS based on the current
+tag the cursor is over, substituting it into the last Grep command
+in the Grep command history (or into `grep-command' if that history
 list is empty)."
   (interactive
    (progn
@@ -1038,16 +1042,18 @@ to specify a command to run."
                  ;; we should use shell-quote-argument here
                  " -path "
                  (mapconcat
-                  #'(lambda (ignore)
-                      (cond ((stringp ignore)
-                             (shell-quote-argument
-                              (concat "*/" ignore)))
-                            ((consp ignore)
-                             (and (funcall (car ignore) dir)
-                                  (shell-quote-argument
-                                   (concat "*/"
-                                           (cdr ignore)))))))
-                  grep-find-ignored-directories
+                  'identity
+                  (delq nil (mapcar
+                             #'(lambda (ignore)
+                                 (cond ((stringp ignore)
+                                        (shell-quote-argument
+                                         (concat "*/" ignore)))
+                                       ((consp ignore)
+                                        (and (funcall (car ignore) dir)
+                                             (shell-quote-argument
+                                              (concat "*/"
+                                                      (cdr ignore)))))))
+                             grep-find-ignored-directories))
                   " -o -path ")
                  " "
                  (shell-quote-argument ")")
@@ -1088,9 +1094,6 @@ file name to `*.gz', and sets `grep-highlight-matches' to `always'."
           (grep-find-template nil)
           (grep-find-command nil)
           (grep-host-defaults-alist nil)
-          ;; Set `grep-highlight-matches' to `always'
-          ;; since `zgrep' puts filters in the grep output.
-          (grep-highlight-matches 'always)
           ;; Use for `grep-read-files'
           (grep-files-aliases '(("all" . "* .*")
                                 ("gz"  . "*.gz"))))
@@ -1108,7 +1111,10 @@ file name to `*.gz', and sets `grep-highlight-matches' to `always'."
                                            nil default-directory t))
                  (confirm (equal current-prefix-arg '(4))))
             (list regexp files dir confirm grep-find-template)))))))
-  (let ((grep-find-template template))
+  (let ((grep-find-template template)
+        ;; Set `grep-highlight-matches' to `always'
+        ;; since `zgrep' puts filters in the grep output.
+        (grep-highlight-matches 'always))
     (rgrep regexp files dir confirm)))
 
 ;;;###autoload