]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/semantic/symref/grep.el
Merge branch 'seq-let'
[gnu-emacs] / lisp / cedet / semantic / symref / grep.el
index ce5c80526a87daab90c3847b07a3f93502652f66..d57b50fb98f153b469afd21f5c6ffe9be5189d9c 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/symref/grep.el --- Symref implementation using find/grep
 
-;; Copyright (C) 2008-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
 
@@ -105,23 +105,32 @@ GREPPATTERN is the pattern used by grep."
   ;; We have grep-compute-defaults.  Let's use it.
   (grep-compute-defaults)
   (let* ((grep-expand-keywords semantic-symref-grep-expand-keywords)
-        (cmd (grep-expand-template grep-find-template
-                                   greppattern
-                                   filepattern
-                                   rootdir)))
+        (cmd (grep-expand-template
+               (if (memq system-type '(windows-nt ms-dos))
+                   ;; grep-find uses '--color=always' on MS-Windows
+                   ;; because it wants the colorized output, to show
+                   ;; it to the user.  By contrast, here we don't show
+                   ;; the output, and the SGR escapes get in the way
+                   ;; of parsing the output.
+                   (replace-regexp-in-string "--color=always" ""
+                                             grep-find-template t t)
+                 grep-find-template)
+               greppattern
+               filepattern
+               rootdir)))
     ;; For some reason, my default has no <D> in it.
     (when (string-match "find \\(\\.\\)" cmd)
       (setq cmd (replace-match rootdir t t cmd 1)))
     ;;(message "New command: %s" cmd)
     cmd))
 
-(defcustom semantic-symref-grep-shell "sh"
+(defcustom semantic-symref-grep-shell shell-file-name
   "The shell command to use for executing find/grep.
 This shell should support pipe redirect syntax."
   :group 'semantic
   :type 'string)
 
-(defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep))
+(cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-grep))
   "Perform a search with Grep."
   ;; Grep doesn't support some types of searches.
   (let ((st (oref tool :searchtype)))
@@ -140,7 +149,8 @@ This shell should support pipe redirect syntax."
         (greppat (cond ((eq (oref tool :searchtype) 'regexp)
                         (oref tool searchfor))
                        (t
-                        (concat "'\\<" (oref tool searchfor) "\\>'"))))
+                        (shell-quote-argument
+                          (concat "\\<" (oref tool searchfor) "\\>")))))
         ;; Misc
         (b (get-buffer-create "*Semantic SymRef*"))
         (ans nil)
@@ -158,16 +168,18 @@ This shell should support pipe redirect syntax."
          (let ((cmd (concat "find " default-directory " -type f " filepattern " -print0 "
                             "| xargs -0 grep -H " grepflags "-e " greppat)))
            ;;(message "Old command: %s" cmd)
-           (call-process semantic-symref-grep-shell nil b nil "-c" cmd)
+           (call-process semantic-symref-grep-shell nil b nil
+                          shell-command-switch cmd)
            )
        (let ((cmd (semantic-symref-grep-use-template rootdir filepattern grepflags greppat)))
-         (call-process semantic-symref-grep-shell nil b nil "-c" cmd))
+         (call-process semantic-symref-grep-shell nil b nil
+                        shell-command-switch cmd))
        ))
     (setq ans (semantic-symref-parse-tool-output tool b))
     ;; Return the answer
     ans))
 
-(defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-grep))
+(cl-defmethod semantic-symref-parse-tool-output-one-line ((tool semantic-symref-tool-grep))
   "Parse one line of grep output, and return it as a match list.
 Moves cursor to end of the match."
   (cond ((eq (oref tool :resulttype) 'file)