branch: elpa/anzu
commit b9bac0e2f84ae9b71f7c1a4a7f163d9580a8a10c
Merge: c4a440af86 53db7f64b7
Author: Syohei YOSHIDA <[email protected]>
Commit: Syohei YOSHIDA <[email protected]>
Merge pull request #43 from syohex/fix-compile-regexp-error-case
Fix case if s-expression cannot be compiled.
---
anzu.el | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/anzu.el b/anzu.el
index 08d6e0801b..a552421625 100644
--- a/anzu.el
+++ b/anzu.el
@@ -438,27 +438,31 @@
from)))
(defun anzu--compile-replace-text (str)
- (let ((compiled (query-replace-compile-replacement str t)))
- (cond ((stringp compiled) compiled)
- ((and (consp compiled) (functionp (car compiled)))
- compiled)
- ((and (consp compiled) (stringp (car compiled)))
- (car compiled)))))
+ (let ((compiled (ignore-errors
+ (query-replace-compile-replacement str t))))
+ (when compiled
+ (cond ((stringp compiled) compiled)
+ ((and (consp compiled) (functionp (car compiled)))
+ compiled)
+ ((and (consp compiled) (stringp (car compiled)))
+ (car compiled))))))
(defun anzu--evaluate-occurrence (ov to-regexp replacements fixed-case
from-regexp)
(let ((from-string (overlay-get ov 'from-string))
(compiled (anzu--compile-replace-text to-regexp)))
- (with-temp-buffer
- (insert from-string)
- (goto-char (point-min))
- (when (re-search-forward from-regexp nil t)
- (or (ignore-errors
- (if (consp compiled)
- (replace-match (funcall (car compiled) (cdr compiled)
- replacements) fixed-case)
- (replace-match compiled fixed-case))
- (buffer-substring (point-min) (point-max)))
- "")))))
+ (if (not compiled)
+ ""
+ (with-temp-buffer
+ (insert from-string)
+ (goto-char (point-min))
+ (when (re-search-forward from-regexp nil t)
+ (or (ignore-errors
+ (if (consp compiled)
+ (replace-match (funcall (car compiled) (cdr compiled)
+ replacements) fixed-case)
+ (replace-match compiled fixed-case))
+ (buffer-substring (point-min) (point-max)))
+ ""))))))
(defun anzu--overlay-sort (a b)
(< (overlay-start a) (overlay-start b)))