emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/lisp/progmodes grep.el


From: Juri Linkov
Subject: [Emacs-diffs] emacs/lisp/progmodes grep.el
Date: Thu, 10 Sep 2009 00:57:45 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Juri Linkov <jurta>     09/09/10 00:57:45

Modified files:
        lisp/progmodes : grep.el 

Log message:
        (grep-template): Add "<X>" to docstring.
        (grep-files-aliases): Add "all".  Move "el" and "ch" to the top of
        the list.  Move "asm" to the bottom.
        (grep-find-ignored-directories): Add `choice' with nil value
        to empty the list easily.
        (grep-find-ignored-files): New option.
        (grep-files-history): Set to nil by default instead of '("ch" "el").
        (grep-compute-defaults): Add "<X>" to `grep-template'.
        (grep-read-files): Bind new local variables `default-alias' and
        `default-extension'.  Use a list of default values for the file prompt.
        (lgrep): Add `--exclude=' command line options composed from
        `grep-find-ignored-files'.
        (rgrep): Add `-name' command line options composed from
        `grep-find-ignored-files'.  (Bug#4301)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/progmodes/grep.el?cvsroot=emacs&r1=1.106&r2=1.107

Patches:
Index: grep.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -b -r1.106 -r1.107
--- grep.el     30 Aug 2009 23:46:09 -0000      1.106
+++ grep.el     10 Sep 2009 00:57:44 -0000      1.107
@@ -120,6 +120,7 @@
 The following place holders should be present in the string:
  <C> - place to put -i if case insensitive grep.
  <F> - file names and wildcards to search.
+ <X> - file names and wildcards to exclude.
  <R> - the regular expression searched for.
  <N> - place to insert null-device.
 
@@ -176,18 +177,19 @@
   :group 'grep)
 
 (defcustom grep-files-aliases
-  '(("asm" .    "*.[sS]")
+  '(("all" .   "* .*")
+    ("el" .    "*.el")
+    ("ch" .    "*.[ch]")
     ("c" .     "*.c")
     ("cc" .    "*.cc *.cxx *.cpp *.C *.CC *.c++")
     ("cchh" .    "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++")
     ("hh" .    "*.hxx *.hpp *.[Hh] *.HH *.h++")
-    ("ch" .    "*.[ch]")
-    ("el" .    "*.el")
     ("h" .     "*.h")
     ("l" .      "[Cc]hange[Ll]og*")
     ("m" .     "[Mm]akefile*")
     ("tex" .    "*.tex")
-    ("texi" .   "*.texi"))
+    ("texi" .  "*.texi")
+    ("asm" .   "*.[sS]"))
   "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'."
   :type 'alist
   :group 'grep)
@@ -197,7 +199,20 @@
   "*List of names of sub-directories which `rgrep' shall not recurse into.
 If an element is a cons cell, the car is called on the search directory
 to determine whether cdr should not be recursed into."
-  :type '(repeat string)
+  :type '(choice (repeat :tag "Ignored directories" string)
+                (const :tag "No ignored directories" nil))
+  :group 'grep)
+
+(defcustom grep-find-ignored-files
+  (cons ".#*" (delq nil (mapcar (lambda (s)
+                                 (unless (string-match-p "/\\'" s)
+                                   (concat "*" s)))
+                               completion-ignored-extensions)))
+  "*List of file names which `rgrep' and `lgrep' shall exclude.
+If an element is a cons cell, the car is called on the search directory
+to determine whether cdr should not be excluded."
+  :type '(choice (repeat :tag "Ignored file" string)
+                (const :tag "No ignored files" nil))
   :group 'grep)
 
 (defcustom grep-error-screen-columns nil
@@ -421,7 +436,7 @@
 
 ;; History of lgrep and rgrep regexp and files args.
 (defvar grep-regexp-history nil)
-(defvar grep-files-history '("ch" "el"))
+(defvar grep-files-history nil)
 
 ;;;###autoload
 (defun grep-process-setup ()
@@ -524,7 +539,7 @@
                (format "%s %s " grep-program grep-options)))
        (unless grep-template
          (setq grep-template
-               (format "%s <C> %s <R> <F>" grep-program grep-options)))
+               (format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
        (unless grep-find-use-xargs
          (setq grep-find-use-xargs
                (cond
@@ -753,8 +768,8 @@
         (fn (and bn
                  (stringp bn)
                  (file-name-nondirectory bn)))
-        (default
-          (or (and fn
+        (default-alias
+          (and fn
                    (let ((aliases grep-files-aliases)
                          alias)
                      (while aliases
@@ -763,10 +778,14 @@
                        (if (string-match (wildcard-to-regexp (cdr alias)) fn)
                            (setq aliases nil)
                          (setq alias nil)))
-                     (cdr alias)))
+                 (cdr alias))))
+        (default-extension
               (and fn
                    (let ((ext (file-name-extension fn)))
-                     (and ext (concat "*." ext))))
+                 (and ext (concat "*." ext)))))
+        (default
+          (or default-alias
+              default-extension
               (car grep-files-history)
               (car (car grep-files-aliases))))
         (files (read-string
@@ -774,7 +793,10 @@
                         "\" in files"
                         (if default (concat " (default " default ")"))
                         ": ")
-                nil 'grep-files-history default)))
+                nil 'grep-files-history
+                (delete-dups
+                 (delq nil (append (list default default-alias 
default-extension)
+                                   (mapcar 'car grep-files-aliases)))))))
     (and files
         (or (cdr (assoc files grep-files-aliases))
             files))))
@@ -822,7 +844,20 @@
        (setq command (grep-expand-template
                       grep-template
                       regexp
-                      files))
+                      files
+                      nil
+                      (and grep-find-ignored-files
+                           (concat " --exclude="
+                                   (mapconcat
+                                    #'(lambda (ignore)
+                                        (cond ((stringp ignore)
+                                               (shell-quote-argument ignore))
+                                              ((consp ignore)
+                                               (and (funcall (car ignore) dir)
+                                                    (shell-quote-argument
+                                                     (cdr ignore))))))
+                                    grep-find-ignored-files
+                                    " --exclude=")))))
        (when command
          (if confirm
              (setq command
@@ -893,6 +928,7 @@
                              " "
                              (shell-quote-argument ")"))
                       dir
+                     (concat
                       (and grep-find-ignored-directories
                            (concat (shell-quote-argument "(")
                                    ;; we should use shell-quote-argument here
@@ -911,7 +947,24 @@
                                      " -o -path ")
                                    " "
                                    (shell-quote-argument ")")
-                                   " -prune -o ")))))
+                                   " -prune -o "))
+                      (and grep-find-ignored-files
+                           (concat (shell-quote-argument "(")
+                                   ;; we should use shell-quote-argument here
+                                   " -name "
+                                   (mapconcat
+                                    #'(lambda (ignore)
+                                        (cond ((stringp ignore)
+                                               (shell-quote-argument ignore))
+                                              ((consp ignore)
+                                               (and (funcall (car ignore) dir)
+                                                    (shell-quote-argument
+                                                     (cdr ignore))))))
+                                    grep-find-ignored-files
+                                    " -o -name ")
+                                   " "
+                                   (shell-quote-argument ")")
+                                   " -prune -o "))))))
        (when command
          (if confirm
              (setq command




reply via email to

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