diff options
| author | Dmitry Gutov | 2015-11-15 05:59:34 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-11-15 06:32:13 +0200 |
| commit | bc2cec6b205da46492736e079321f4f4ed41a782 (patch) | |
| tree | edc1d77909592089a830e96d884561fdaf3e377f | |
| parent | d24e7833e56eb9ce8731975518da0c7fda3d00f2 (diff) | |
| download | emacs-bc2cec6b205da46492736e079321f4f4ed41a782.tar.gz emacs-bc2cec6b205da46492736e079321f4f4ed41a782.zip | |
Fix replacing a match with a shorter string
In effect, partially reverting fe973fc.
* lisp/progmodes/xref.el (xref-query-replace): Store the end
of each match as a marker again, instead of length.
(xref--query-replace-1): Update accordingly.
| -rw-r--r-- | lisp/progmodes/xref.el | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 1962614f16d..7e3b5600f1a 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -498,7 +498,9 @@ WINDOW controls how the buffer is displayed: | |||
| 498 | (save-excursion | 498 | (save-excursion |
| 499 | (let* ((loc (xref-item-location item)) | 499 | (let* ((loc (xref-item-location item)) |
| 500 | (beg (xref-location-marker loc)) | 500 | (beg (xref-location-marker loc)) |
| 501 | (len (xref-match-length item))) | 501 | (end (move-marker (make-marker) |
| 502 | (+ beg (xref-match-length item)) | ||
| 503 | (marker-buffer beg)))) | ||
| 502 | ;; Perform sanity check first. | 504 | ;; Perform sanity check first. |
| 503 | (xref--goto-location loc) | 505 | (xref--goto-location loc) |
| 504 | ;; FIXME: The check should probably be a generic | 506 | ;; FIXME: The check should probably be a generic |
| @@ -510,17 +512,18 @@ WINDOW controls how the buffer is displayed: | |||
| 510 | (line-end-position)) | 512 | (line-end-position)) |
| 511 | (xref-item-summary item)) | 513 | (xref-item-summary item)) |
| 512 | (user-error "Search results out of date")) | 514 | (user-error "Search results out of date")) |
| 513 | (push (cons beg len) pairs))))) | 515 | (push (cons beg end) pairs))))) |
| 514 | (setq pairs (nreverse pairs))) | 516 | (setq pairs (nreverse pairs))) |
| 515 | (unless pairs (user-error "No suitable matches here")) | 517 | (unless pairs (user-error "No suitable matches here")) |
| 516 | (xref--query-replace-1 from to pairs)) | 518 | (xref--query-replace-1 from to pairs)) |
| 517 | (dolist (pair pairs) | 519 | (dolist (pair pairs) |
| 518 | (move-marker (car pair) nil))))) | 520 | (move-marker (car pair) nil) |
| 521 | (move-marker (cdr pair) nil))))) | ||
| 519 | 522 | ||
| 520 | ;; FIXME: Write a nicer UI. | 523 | ;; FIXME: Write a nicer UI. |
| 521 | (defun xref--query-replace-1 (from to pairs) | 524 | (defun xref--query-replace-1 (from to pairs) |
| 522 | (let* ((query-replace-lazy-highlight nil) | 525 | (let* ((query-replace-lazy-highlight nil) |
| 523 | current-beg current-len current-buf | 526 | current-beg current-end current-buf |
| 524 | ;; Counteract the "do the next match now" hack in | 527 | ;; Counteract the "do the next match now" hack in |
| 525 | ;; `perform-replace'. And still, it'll report that those | 528 | ;; `perform-replace'. And still, it'll report that those |
| 526 | ;; matches were "filtered out" at the end. | 529 | ;; matches were "filtered out" at the end. |
| @@ -529,18 +532,18 @@ WINDOW controls how the buffer is displayed: | |||
| 529 | (and current-beg | 532 | (and current-beg |
| 530 | (eq (current-buffer) current-buf) | 533 | (eq (current-buffer) current-buf) |
| 531 | (>= beg current-beg) | 534 | (>= beg current-beg) |
| 532 | (<= end (+ current-beg current-len))))) | 535 | (<= end current-end)))) |
| 533 | (replace-re-search-function | 536 | (replace-re-search-function |
| 534 | (lambda (from &optional _bound noerror) | 537 | (lambda (from &optional _bound noerror) |
| 535 | (let (found pair) | 538 | (let (found pair) |
| 536 | (while (and (not found) pairs) | 539 | (while (and (not found) pairs) |
| 537 | (setq pair (pop pairs) | 540 | (setq pair (pop pairs) |
| 538 | current-beg (car pair) | 541 | current-beg (car pair) |
| 539 | current-len (cdr pair) | 542 | current-end (cdr pair) |
| 540 | current-buf (marker-buffer current-beg)) | 543 | current-buf (marker-buffer current-beg)) |
| 541 | (pop-to-buffer current-buf) | 544 | (pop-to-buffer current-buf) |
| 542 | (goto-char current-beg) | 545 | (goto-char current-beg) |
| 543 | (when (re-search-forward from (+ current-beg current-len) noerror) | 546 | (when (re-search-forward from current-end noerror) |
| 544 | (setq found t))) | 547 | (setq found t))) |
| 545 | found)))) | 548 | found)))) |
| 546 | ;; FIXME: Despite this being a multi-buffer replacement, `N' | 549 | ;; FIXME: Despite this being a multi-buffer replacement, `N' |