aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2019-12-29 15:44:08 +0300
committerDmitry Gutov2019-12-29 15:46:44 +0300
commit65af18d86eed140100c98c1bf3076f805f2bcc06 (patch)
tree7cc2026b60ed7b848e0584c043fed0d101ccd1ba
parent98788bf9768fec915c745aae8c9196636ffeaecc (diff)
downloademacs-65af18d86eed140100c98c1bf3076f805f2bcc06.tar.gz
emacs-65af18d86eed140100c98c1bf3076f805f2bcc06.zip
Rename xref-collect-references and xref-collect-matches
* lisp/progmodes/xref.el (xref-references-in-directory): Rename from xref-collect-references. Update the sole caller. (xref-matches-in-directory): Rename from xref-collect-matches. Update all callers (all of them are in the /tests/ dir). * test/lisp/progmodes/xref-tests.el (xref-tests-data-dir): Don't use the EMACS_TEST_DIRECTORY env var. It doesn't work when running interactively.
-rw-r--r--lisp/progmodes/xref.el16
-rw-r--r--test/lisp/progmodes/xref-tests.el27
2 files changed, 27 insertions, 16 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index a9d41258471..9f010eb83bf 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -261,7 +261,7 @@ find a search tool; by default, this uses \"find | grep\" in the
261`project-current' roots." 261`project-current' roots."
262 (cl-mapcan 262 (cl-mapcan
263 (lambda (dir) 263 (lambda (dir)
264 (xref-collect-references identifier dir)) 264 (xref-references-in-directory identifier dir))
265 (let ((pr (project-current t))) 265 (let ((pr (project-current t)))
266 (append 266 (append
267 (project-roots pr) 267 (project-roots pr)
@@ -1129,7 +1129,7 @@ and just use etags."
1129(declare-function grep-expand-template "grep") 1129(declare-function grep-expand-template "grep")
1130(defvar ede-minor-mode) ;; ede.el 1130(defvar ede-minor-mode) ;; ede.el
1131 1131
1132(defun xref-collect-references (symbol dir) 1132(defun xref-references-in-directory (symbol dir)
1133 "Find all references to SYMBOL in directory DIR. 1133 "Find all references to SYMBOL in directory DIR.
1134Return a list of xref values. 1134Return a list of xref values.
1135 1135
@@ -1160,8 +1160,13 @@ and when."
1160 (xref--convert-hits (semantic-symref-perform-search inst) 1160 (xref--convert-hits (semantic-symref-perform-search inst)
1161 (format "\\_<%s\\_>" (regexp-quote symbol))))) 1161 (format "\\_<%s\\_>" (regexp-quote symbol)))))
1162 1162
1163(define-obsolete-function-alias
1164 'xref-collect-references
1165 #'xref-references-in-directory
1166 "27.1")
1167
1163;;;###autoload 1168;;;###autoload
1164(defun xref-collect-matches (regexp files dir ignores) 1169(defun xref-matches-in-directory (regexp files dir ignores)
1165 "Find all matches for REGEXP in directory DIR. 1170 "Find all matches for REGEXP in directory DIR.
1166Return a list of xref values. 1171Return a list of xref values.
1167Only files matching some of FILES and none of IGNORES are searched. 1172Only files matching some of FILES and none of IGNORES are searched.
@@ -1207,6 +1212,11 @@ IGNORES is a list of glob patterns for files to ignore."
1207 hits))) 1212 hits)))
1208 (xref--convert-hits (nreverse hits) regexp))) 1213 (xref--convert-hits (nreverse hits) regexp)))
1209 1214
1215(define-obsolete-function-alias
1216 'xref-collect-matches
1217 #'xref-matches-in-directory
1218 "27.1")
1219
1210(defun xref--rgrep-command (regexp files dir ignores) 1220(defun xref--rgrep-command (regexp files dir ignores)
1211 (require 'find-dired) ; for `find-name-arg' 1221 (require 'find-dired) ; for `find-name-arg'
1212 (defvar grep-find-template) 1222 (defvar grep-find-template)
diff --git a/test/lisp/progmodes/xref-tests.el b/test/lisp/progmodes/xref-tests.el
index 31f455023f3..3fe3a658286 100644
--- a/test/lisp/progmodes/xref-tests.el
+++ b/test/lisp/progmodes/xref-tests.el
@@ -27,14 +27,15 @@
27(require 'cl-lib) 27(require 'cl-lib)
28 28
29(defvar xref-tests-data-dir 29(defvar xref-tests-data-dir
30 (expand-file-name "data/xref/" 30 (expand-file-name "../../../data/xref/"
31 (getenv "EMACS_TEST_DIRECTORY"))) 31 (or load-file-name
32 buffer-file-name)))
32 33
33(ert-deftest xref-collect-matches-finds-none-for-some-regexp () 34(ert-deftest xref-matches-in-directory-finds-none-for-some-regexp ()
34 (should (null (xref-collect-matches "zzz" "*" xref-tests-data-dir nil)))) 35 (should (null (xref-matches-in-directory "zzz" "*" xref-tests-data-dir nil))))
35 36
36(ert-deftest xref-collect-matches-finds-some-for-bar () 37(ert-deftest xref-matches-in-directory-finds-some-for-bar ()
37 (let* ((matches (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) 38 (let* ((matches (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
38 (locs (cl-sort (mapcar #'xref-item-location matches) 39 (locs (cl-sort (mapcar #'xref-item-location matches)
39 #'string< 40 #'string<
40 :key #'xref-location-group))) 41 :key #'xref-location-group)))
@@ -42,8 +43,8 @@
42 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs)))) 43 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
43 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 1 locs)))))) 44 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 1 locs))))))
44 45
45(ert-deftest xref-collect-matches-finds-two-matches-on-the-same-line () 46(ert-deftest xref-matches-in-directory-finds-two-matches-on-the-same-line ()
46 (let* ((matches (xref-collect-matches "foo" "*" xref-tests-data-dir nil)) 47 (let* ((matches (xref-matches-in-directory "foo" "*" xref-tests-data-dir nil))
47 (locs (mapcar #'xref-item-location matches))) 48 (locs (mapcar #'xref-item-location matches)))
48 (should (= 2 (length matches))) 49 (should (= 2 (length matches)))
49 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs)))) 50 (should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 0 locs))))
@@ -53,8 +54,8 @@
53 (should (equal 0 (xref-file-location-column (nth 0 locs)))) 54 (should (equal 0 (xref-file-location-column (nth 0 locs))))
54 (should (equal 4 (xref-file-location-column (nth 1 locs)))))) 55 (should (equal 4 (xref-file-location-column (nth 1 locs))))))
55 56
56(ert-deftest xref-collect-matches-finds-an-empty-line-regexp-match () 57(ert-deftest xref-matches-in-directory-finds-an-empty-line-regexp-match ()
57 (let* ((matches (xref-collect-matches "^$" "*" xref-tests-data-dir nil)) 58 (let* ((matches (xref-matches-in-directory "^$" "*" xref-tests-data-dir nil))
58 (locs (mapcar #'xref-item-location matches))) 59 (locs (mapcar #'xref-item-location matches)))
59 (should (= 1 (length matches))) 60 (should (= 1 (length matches)))
60 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs)))) 61 (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs))))
@@ -62,7 +63,7 @@
62 (should (equal 0 (xref-file-location-column (nth 0 locs)))))) 63 (should (equal 0 (xref-file-location-column (nth 0 locs))))))
63 64
64(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 () 65(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 ()
65 (let* ((xrefs (xref-collect-matches "foo" "*" xref-tests-data-dir nil)) 66 (let* ((xrefs (xref-matches-in-directory "foo" "*" xref-tests-data-dir nil))
66 (iter (xref--buf-pairs-iterator xrefs)) 67 (iter (xref--buf-pairs-iterator xrefs))
67 (cons (funcall iter :next))) 68 (cons (funcall iter :next)))
68 (should (null (funcall iter :next))) 69 (should (null (funcall iter :next)))
@@ -70,7 +71,7 @@
70 (should (= 2 (length (cdr cons)))))) 71 (should (= 2 (length (cdr cons))))))
71 72
72(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-2 () 73(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-2 ()
73 (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) 74 (let* ((xrefs (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
74 (iter (xref--buf-pairs-iterator xrefs)) 75 (iter (xref--buf-pairs-iterator xrefs))
75 (cons1 (funcall iter :next)) 76 (cons1 (funcall iter :next))
76 (cons2 (funcall iter :next))) 77 (cons2 (funcall iter :next)))
@@ -80,7 +81,7 @@
80 (should (= 1 (length (cdr cons2)))))) 81 (should (= 1 (length (cdr cons2))))))
81 82
82(ert-deftest xref--buf-pairs-iterator-cleans-up-markers () 83(ert-deftest xref--buf-pairs-iterator-cleans-up-markers ()
83 (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) 84 (let* ((xrefs (xref-matches-in-directory "bar" "*" xref-tests-data-dir nil))
84 (iter (xref--buf-pairs-iterator xrefs)) 85 (iter (xref--buf-pairs-iterator xrefs))
85 (cons1 (funcall iter :next)) 86 (cons1 (funcall iter :next))
86 (cons2 (funcall iter :next))) 87 (cons2 (funcall iter :next)))