diff options
author | Marko Bencun <marko.bencun@monetas.net> | 2016-10-18 02:13:30 +0200 |
---|---|---|
committer | Marko Bencun <marko.bencun@monetas.net> | 2016-10-18 02:13:30 +0200 |
commit | 4ab9426a831cf0620f49ba227fd10b9c71672274 (patch) | |
tree | 9350df289c4183dc81b1c906fd7220dd3f967cfe /visual-regexp.el | |
parent | dfdf63ac1ae4c271e730c14d65b53523494daad4 (diff) |
ignore nil pairs in match-data
If a subgroup does not match anything, (match-data) contains nils. Those
led to errors.
Issue #43.
Diffstat (limited to 'visual-regexp.el')
-rw-r--r-- | visual-regexp.el | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/visual-regexp.el b/visual-regexp.el index 04a224e..9cee41a 100644 --- a/visual-regexp.el +++ b/visual-regexp.el @@ -565,6 +565,9 @@ visible all the time in the minibuffer." (propertize replacement 'face current-face))) (overlay-put overlay 'priority (+ vr--overlay-priority 0)))))))) +(defun vr--mapcar-nonnil (rep list) + (mapcar (lambda (it) (when it (funcall rep it))) list)) + (defun vr--get-replacements (feedback feedback-limit) "Get replacements using emacs-style regexp." (setq vr--limit-reached nil) @@ -594,7 +597,7 @@ visible all the time in the minibuffer." (progn (if (or (not feedback) (not feedback-limit) (< i feedback-limit)) (setq replacements (cons - (let ((match-data (mapcar 'marker-position (match-data)))) + (let ((match-data (vr--mapcar-nonnil 'marker-position (match-data)))) (list (query-replace-compile-replacement replace-string t) match-data i)) replacements)) (setq vr--limit-reached t)) @@ -658,7 +661,7 @@ visible all the time in the minibuffer." (unless (or silent (string= "" message-line)) (vr--minibuffer-message message-line)) ;; needed to correctly position the mark after query replace (finished with 'automatic ('!')) - (set-match-data (mapcar (lambda (el) (+ cumulative-offset el)) last-match-data)) + (set-match-data (vr--mapcar-nonnil (lambda (el) (+ cumulative-offset el)) last-match-data)) replace-count))) (defun vr--set-target-buffer-start-end () @@ -903,7 +906,7 @@ E [not supported in visual-regexp]" (while (and keep-going vr--query-replacements) ;; Advance replacement list (cl-multiple-value-bind (replacement match-data i) (car vr--query-replacements) - (setq match-data (mapcar (lambda (el) (+ cumulative-offset el)) match-data)) + (setq match-data (vr--mapcar-nonnil (lambda (el) (+ cumulative-offset el)) match-data)) (let ((begin (cl-first match-data)) (end (cl-second match-data)) (next-replacement-orig replacement)) |