emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/anzu b9bac0e2f8 178/288: Merge pull request #43 from syohe


From: ELPA Syncer
Subject: [nongnu] elpa/anzu b9bac0e2f8 178/288: Merge pull request #43 from syohex/fix-compile-regexp-error-case
Date: Thu, 6 Jan 2022 03:58:50 -0500 (EST)

branch: elpa/anzu
commit b9bac0e2f84ae9b71f7c1a4a7f163d9580a8a10c
Merge: c4a440af86 53db7f64b7
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>

    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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]