]> code.delx.au - gnu-emacs/commitdiff
When called with prefix argument, ask for file patterns to search as well
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 12 Jul 2015 15:35:08 +0000 (18:35 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 12 Jul 2015 15:35:08 +0000 (18:35 +0300)
* lisp/progmodes/xref.el (xref-find-regexp): When called with
prefix argument, ask for file patterns to search as well.  When
prompting for the directory, require an existing one.
(xref-collect-matches): Add a new argument, FILES.  Use it in the
above function.

lisp/progmodes/xref.el

index cc475e6e7e4f4d5630b1d48b8ad2707ca48d3109..214503efc5ee161b92914d13f939bef834f53e5d 100644 (file)
@@ -661,11 +661,15 @@ With prefix argument, prompt for the identifier."
 (defun xref-find-regexp (regexp)
   "Find all matches for REGEXP.
 With \\[universal-argument] prefix, you can specify the directory
-to search in."
+to search in, and the file name pattern to search for."
   (interactive (list (xref--read-identifier "Find regexp: ")))
   (let* ((proj (project-current))
+         (files (if current-prefix-arg
+                    (grep-read-files regexp)
+                  "*.*"))
          (dirs (if current-prefix-arg
-                   (list (read-directory-name "In directory: "))
+                   (list (read-directory-name "Base directory: "
+                                              nil default-directory t))
                  (project--prune-directories
                   (nconc
                    (project-directories proj)
@@ -674,7 +678,7 @@ to search in."
           (lambda (_kind regexp)
             (cl-mapcan
              (lambda (dir)
-               (xref-collect-matches regexp dir (project-ignores proj)))
+               (xref-collect-matches regexp files dir (project-ignores proj)))
              dirs))))
     (xref--show-xrefs regexp 'matches regexp nil)))
 
@@ -755,8 +759,10 @@ tools are used, and when."
       (mapc #'kill-buffer
             (cl-set-difference (buffer-list) orig-buffers)))))
 
-(defun xref-collect-matches (regexp dir ignores)
-  "Collect matches for REGEXP inside DIR using rgrep."
+(defun xref-collect-matches (regexp files dir ignores)
+  "Collect matches for REGEXP inside FILES in DIR.
+FILES is a string with glob patterns separated by spaces.
+IGNORES is a list of glob patterns."
   (cl-assert (directory-name-p dir))
   (require 'semantic/fw)
   (grep-compute-defaults)
@@ -766,7 +772,7 @@ tools are used, and when."
                                                        grep-find-template t t))
          (grep-highlight-matches nil)
          (command (xref--rgrep-command (xref--regexp-to-extended regexp)
-                                       "*.*" dir ignores))
+                                       files dir ignores))
          (orig-buffers (buffer-list))
          (buf (get-buffer-create " *xref-grep*"))
          (grep-re (caar grep-regexp-alist))