diff options
| author | Dmitry Gutov | 2016-05-05 02:52:34 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2016-05-05 03:26:04 +0300 |
| commit | 922c7a3e48e649ad67bd12b1f83343b730dd1bc4 (patch) | |
| tree | 551beacca9963c49e4d3a8e14be27b80e4728b83 /test | |
| parent | 3fe351072841becbb1902c19f784890949f41c1d (diff) | |
| download | emacs-922c7a3e48e649ad67bd12b1f83343b730dd1bc4.tar.gz emacs-922c7a3e48e649ad67bd12b1f83343b730dd1bc4.zip | |
Rework xref-query-replace-in-results
* lisp/progmodes/xref.el (xref-query-replace-in-results): Collect
all xrefs from the buffer first, then delegate most of the
processing to the value returned by xref--buf-pairs-iterator.
(xref--buf-pairs-iterator): New function. Return an "iterator"
which partitions returned markers into buffers, and only processes
markers from one buffer at a time. When an xref is out of date,
skip it with a message instead of signaling error (bug#23284).
(xref--outdated-p): Extract from xref--buf-pairs-iterator. Trim
CR from both strings before comparing.
(xref--query-replace-1): Remove the variable current-buf, no need
to track it anymore. Simplify the filter-predicate and search
functions accordingly. Iterate over buffer-markers pairs returned
by the iterator, and call `perform-replace' for each of them. Use
multi-query-replace-map (bug#23284). Use `switch-to-buffer' every
time after the first, in order not to jump between windows.
* test/automated/xref-tests.el
(xref--buf-pairs-iterator-groups-markers-by-buffers-1)
(xref--buf-pairs-iterator-groups-markers-by-buffers-2)
(xref--buf-pairs-iterator-cleans-up-markers): New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/automated/xref-tests.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/automated/xref-tests.el b/test/automated/xref-tests.el index b288e2d7584..079b196aa8b 100644 --- a/test/automated/xref-tests.el +++ b/test/automated/xref-tests.el | |||
| @@ -60,3 +60,32 @@ | |||
| 60 | (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs)))) | 60 | (should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs)))) |
| 61 | (should (equal 1 (xref-location-line (nth 0 locs)))) | 61 | (should (equal 1 (xref-location-line (nth 0 locs)))) |
| 62 | (should (equal 0 (xref-file-location-column (nth 0 locs)))))) | 62 | (should (equal 0 (xref-file-location-column (nth 0 locs)))))) |
| 63 | |||
| 64 | (ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 () | ||
| 65 | (let* ((xrefs (xref-collect-matches "foo" "*" xref-tests-data-dir nil)) | ||
| 66 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 67 | (cons (funcall iter :next))) | ||
| 68 | (should (null (funcall iter :next))) | ||
| 69 | (should (string-match "file1\\.txt\\'" (buffer-file-name (car cons)))) | ||
| 70 | (should (= 2 (length (cdr cons)))))) | ||
| 71 | |||
| 72 | (ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-2 () | ||
| 73 | (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) | ||
| 74 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 75 | (cons1 (funcall iter :next)) | ||
| 76 | (cons2 (funcall iter :next))) | ||
| 77 | (should (null (funcall iter :next))) | ||
| 78 | (should-not (equal (car cons1) (car cons2))) | ||
| 79 | (should (= 1 (length (cdr cons1)))) | ||
| 80 | (should (= 1 (length (cdr cons2)))))) | ||
| 81 | |||
| 82 | (ert-deftest xref--buf-pairs-iterator-cleans-up-markers () | ||
| 83 | (let* ((xrefs (xref-collect-matches "bar" "*" xref-tests-data-dir nil)) | ||
| 84 | (iter (xref--buf-pairs-iterator xrefs)) | ||
| 85 | (cons1 (funcall iter :next)) | ||
| 86 | (cons2 (funcall iter :next))) | ||
| 87 | (funcall iter :cleanup) | ||
| 88 | (should (null (marker-position (car (nth 0 (cdr cons1)))))) | ||
| 89 | (should (null (marker-position (cdr (nth 0 (cdr cons1)))))) | ||
| 90 | (should (null (marker-position (car (nth 0 (cdr cons2)))))) | ||
| 91 | (should (null (marker-position (cdr (nth 0 (cdr cons2)))))))) | ||