diff options
| author | Dmitry Gutov | 2015-11-06 05:08:51 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-11-08 03:07:09 +0200 |
| commit | 3a37d99e974b89de91e07ce5c7955f4fd1d731ca (patch) | |
| tree | 37511f2c79918c76fc5570a12bbee6bc6aa2bf8d | |
| parent | 55ad7fce86b9a12f222587978ec0892d23273387 (diff) | |
| download | emacs-3a37d99e974b89de91e07ce5c7955f4fd1d731ca.tar.gz emacs-3a37d99e974b89de91e07ce5c7955f4fd1d731ca.zip | |
Move and rename xref-find-regexp to the project package
* lisp/progmodes/project.el (project-find-regexp)
(project--read-regexp)
(project--find-regexp-in): New functions.
* lisp/progmodes/xref.el (xref--find-xrefs): Extract from
xref--show-xrefs. Use in existing callers in place of that
function.
(xref--show-xrefs): Only do the "show" part.
(xref-find-regexp): Rename, more or less, to
project-or-libraries-find-regexp.
| -rw-r--r-- | lisp/progmodes/project.el | 49 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 64 |
2 files changed, 69 insertions, 44 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index ba831204bf2..f67a584f808 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el | |||
| @@ -199,5 +199,54 @@ DIRS must contain directory names." | |||
| 199 | (hack-dir-local-variables-non-file-buffer) | 199 | (hack-dir-local-variables-non-file-buffer) |
| 200 | (symbol-value var))) | 200 | (symbol-value var))) |
| 201 | 201 | ||
| 202 | (declare-function grep-read-files "grep") | ||
| 203 | (declare-function xref-collect-matches "xref") | ||
| 204 | (declare-function xref--show-xrefs "xref") | ||
| 205 | |||
| 206 | ;;;###autoload | ||
| 207 | (defun project-find-regexp (regexp) | ||
| 208 | "Find all matches for REGEXP in the current project. | ||
| 209 | With \\[universal-argument] prefix, you can specify the directory | ||
| 210 | to search in, and the file name pattern to search for." | ||
| 211 | (interactive (list (project--read-regexp))) | ||
| 212 | (let* ((pr (project-current)) | ||
| 213 | (dirs (if current-prefix-arg | ||
| 214 | (list (read-directory-name "Base directory: " | ||
| 215 | nil default-directory t)) | ||
| 216 | (project-roots pr)))) | ||
| 217 | (project--find-regexp-in dirs regexp pr))) | ||
| 218 | |||
| 219 | ;;;###autoload | ||
| 220 | (defun project-or-libraries-find-regexp (regexp) | ||
| 221 | "Find all matches for REGEXP in the current project or libraries. | ||
| 222 | With \\[universal-argument] prefix, you can specify the file name | ||
| 223 | pattern to search for." | ||
| 224 | (interactive (list (project--read-regexp))) | ||
| 225 | (let* ((pr (project-current)) | ||
| 226 | (dirs (append | ||
| 227 | (project-roots pr) | ||
| 228 | (project-library-roots pr)))) | ||
| 229 | (project--find-regexp-in dirs regexp pr))) | ||
| 230 | |||
| 231 | (defun project--read-regexp () | ||
| 232 | (defvar xref-identifier-at-point-function) | ||
| 233 | (require 'xref) | ||
| 234 | (read-regexp "Find regexp" | ||
| 235 | (funcall xref-identifier-at-point-function))) | ||
| 236 | |||
| 237 | (defun project--find-regexp-in (dirs regexp project) | ||
| 238 | (require 'grep) | ||
| 239 | (let* ((files (if current-prefix-arg | ||
| 240 | (grep-read-files regexp) | ||
| 241 | "*")) | ||
| 242 | (xrefs (cl-mapcan | ||
| 243 | (lambda (dir) | ||
| 244 | (xref-collect-matches regexp files dir | ||
| 245 | (project-ignores project dir))) | ||
| 246 | dirs))) | ||
| 247 | (unless xrefs | ||
| 248 | (user-error "No matches for: %s" regexp)) | ||
| 249 | (xref--show-xrefs xrefs nil))) | ||
| 250 | |||
| 202 | (provide 'project) | 251 | (provide 'project) |
| 203 | ;;; project.el ends here | 252 | ;;; project.el ends here |
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 3aa85cb900d..89a06046ca2 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -664,6 +664,8 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 664 | 664 | ||
| 665 | ;; This part of the UI seems fairly uncontroversial: it reads the | 665 | ;; This part of the UI seems fairly uncontroversial: it reads the |
| 666 | ;; identifier and deals with the single definition case. | 666 | ;; identifier and deals with the single definition case. |
| 667 | ;; (FIXME: do we really want this case to be handled like that in | ||
| 668 | ;; "find references" and "find regexp searches"?) | ||
| 667 | ;; | 669 | ;; |
| 668 | ;; The controversial multiple definitions case is handed off to | 670 | ;; The controversial multiple definitions case is handed off to |
| 669 | ;; xref-show-xrefs-function. | 671 | ;; xref-show-xrefs-function. |
| @@ -675,18 +677,15 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 675 | 677 | ||
| 676 | (defvar xref--read-pattern-history nil) | 678 | (defvar xref--read-pattern-history nil) |
| 677 | 679 | ||
| 678 | (defun xref--show-xrefs (input kind arg window) | 680 | (defun xref--show-xrefs (xrefs window) |
| 679 | (let* ((xrefs (funcall xref-find-function kind arg))) | 681 | (cond |
| 680 | (cond | 682 | ((not (cdr xrefs)) |
| 681 | ((null xrefs) | 683 | (xref-push-marker-stack) |
| 682 | (user-error "No %s found for: %s" (symbol-name kind) input)) | 684 | (xref--pop-to-location (car xrefs) window)) |
| 683 | ((not (cdr xrefs)) | 685 | (t |
| 684 | (xref-push-marker-stack) | 686 | (xref-push-marker-stack) |
| 685 | (xref--pop-to-location (car xrefs) window)) | 687 | (funcall xref-show-xrefs-function xrefs |
| 686 | (t | 688 | `((window . ,window)))))) |
| 687 | (xref-push-marker-stack) | ||
| 688 | (funcall xref-show-xrefs-function xrefs | ||
| 689 | `((window . ,window))))))) | ||
| 690 | 689 | ||
| 691 | (defun xref--prompt-p (command) | 690 | (defun xref--prompt-p (command) |
| 692 | (or (eq xref-prompt-for-identifier t) | 691 | (or (eq xref-prompt-for-identifier t) |
| @@ -714,8 +713,14 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 714 | 713 | ||
| 715 | ;;; Commands | 714 | ;;; Commands |
| 716 | 715 | ||
| 716 | (defun xref--find-xrefs (input kind arg window) | ||
| 717 | (let ((xrefs (funcall xref-find-function kind arg))) | ||
| 718 | (unless xrefs | ||
| 719 | (user-error "No %s found for: %s" (symbol-name kind) input)) | ||
| 720 | (xref--show-xrefs xrefs window))) | ||
| 721 | |||
| 717 | (defun xref--find-definitions (id window) | 722 | (defun xref--find-definitions (id window) |
| 718 | (xref--show-xrefs id 'definitions id window)) | 723 | (xref--find-xrefs id 'definitions id window)) |
| 719 | 724 | ||
| 720 | ;;;###autoload | 725 | ;;;###autoload |
| 721 | (defun xref-find-definitions (identifier) | 726 | (defun xref-find-definitions (identifier) |
| @@ -749,35 +754,7 @@ display the list in a buffer." | |||
| 749 | "Find references to the identifier at point. | 754 | "Find references to the identifier at point. |
| 750 | With prefix argument, prompt for the identifier." | 755 | With prefix argument, prompt for the identifier." |
| 751 | (interactive (list (xref--read-identifier "Find references of: "))) | 756 | (interactive (list (xref--read-identifier "Find references of: "))) |
| 752 | (xref--show-xrefs identifier 'references identifier nil)) | 757 | (xref--find-xrefs identifier 'references identifier nil)) |
| 753 | |||
| 754 | ;; TODO: Rename and move to project-find-regexp, as soon as idiomatic | ||
| 755 | ;; usage of xref from other packages has stabilized. | ||
| 756 | ;;;###autoload | ||
| 757 | (defun xref-find-regexp (regexp) | ||
| 758 | "Find all matches for REGEXP. | ||
| 759 | With \\[universal-argument] prefix, you can specify the directory | ||
| 760 | to search in, and the file name pattern to search for." | ||
| 761 | (interactive (list (xref--read-identifier "Find regexp: "))) | ||
| 762 | (require 'grep) | ||
| 763 | (let* ((proj (project-current)) | ||
| 764 | (files (if current-prefix-arg | ||
| 765 | (grep-read-files regexp) | ||
| 766 | "*")) | ||
| 767 | (dirs (if current-prefix-arg | ||
| 768 | (list (read-directory-name "Base directory: " | ||
| 769 | nil default-directory t)) | ||
| 770 | (append | ||
| 771 | (project-roots proj) | ||
| 772 | (project-library-roots proj)))) | ||
| 773 | (xref-find-function | ||
| 774 | (lambda (_kind regexp) | ||
| 775 | (cl-mapcan | ||
| 776 | (lambda (dir) | ||
| 777 | (xref-collect-matches regexp files dir | ||
| 778 | (project-ignores proj dir))) | ||
| 779 | dirs)))) | ||
| 780 | (xref--show-xrefs regexp 'matches regexp nil))) | ||
| 781 | 758 | ||
| 782 | (declare-function apropos-parse-pattern "apropos" (pattern)) | 759 | (declare-function apropos-parse-pattern "apropos" (pattern)) |
| 783 | 760 | ||
| @@ -789,7 +766,7 @@ The argument has the same meaning as in `apropos'." | |||
| 789 | "Search for pattern (word list or regexp): " | 766 | "Search for pattern (word list or regexp): " |
| 790 | nil 'xref--read-pattern-history))) | 767 | nil 'xref--read-pattern-history))) |
| 791 | (require 'apropos) | 768 | (require 'apropos) |
| 792 | (xref--show-xrefs pattern 'apropos | 769 | (xref--find-xrefs pattern 'apropos |
| 793 | (apropos-parse-pattern | 770 | (apropos-parse-pattern |
| 794 | (if (string-equal (regexp-quote pattern) pattern) | 771 | (if (string-equal (regexp-quote pattern) pattern) |
| 795 | ;; Split into words | 772 | ;; Split into words |
| @@ -833,7 +810,6 @@ and just use etags." | |||
| 833 | 810 | ||
| 834 | (declare-function semantic-symref-find-references-by-name "semantic/symref") | 811 | (declare-function semantic-symref-find-references-by-name "semantic/symref") |
| 835 | (declare-function semantic-find-file-noselect "semantic/fw") | 812 | (declare-function semantic-find-file-noselect "semantic/fw") |
| 836 | (declare-function grep-read-files "grep") | ||
| 837 | (declare-function grep-expand-template "grep") | 813 | (declare-function grep-expand-template "grep") |
| 838 | 814 | ||
| 839 | (defun xref-collect-references (symbol dir) | 815 | (defun xref-collect-references (symbol dir) |