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

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

[nongnu] elpa/anzu e782725f80 162/288: Support case sensitive highlighti


From: ELPA Syncer
Subject: [nongnu] elpa/anzu e782725f80 162/288: Support case sensitive highlighting
Date: Thu, 6 Jan 2022 03:58:49 -0500 (EST)

branch: elpa/anzu
commit e782725f80c79778690d5a0f4ba9ed0afff13e27
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>

    Support case sensitive highlighting
---
 anzu.el | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/anzu.el b/anzu.el
index 8b078e5dd9..de77b864fa 100644
--- a/anzu.el
+++ b/anzu.el
@@ -308,9 +308,8 @@
     (set-marker m beg buf)
     (push m anzu--replaced-markers)))
 
-(defun anzu--add-overlay (regexp beg end)
+(defun anzu--add-overlay (beg end)
   (let ((ov (make-overlay beg end)))
-    (overlay-put ov 'from-regexp regexp)
     (overlay-put ov 'from-string (buffer-substring-no-properties beg end))
     (overlay-put ov 'face 'anzu-replace-highlight)
     (overlay-put ov 'anzu-replace t)))
@@ -349,7 +348,7 @@
                 (when (and (>= beg overlay-beg) (<= end overlay-end) (not 
finish))
                   (cl-incf overlayed)
                   (anzu--set-marker beg buf)
-                  (anzu--add-overlay str beg end))))
+                  (anzu--add-overlay beg end))))
             (setq anzu--cached-count count)
             overlayed))))))
 
@@ -443,9 +442,8 @@
           ((and (consp compiled) (stringp (car compiled)))
            (car compiled)))))
 
-(defun anzu--evaluate-occurrence (ov to-regexp replacements)
-  (let ((from-regexp (overlay-get ov 'from-regexp))
-        (from-string (overlay-get ov 'from-string))
+(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)
@@ -454,8 +452,8 @@
         (or (ignore-errors
               (if (consp compiled)
                   (replace-match (funcall (car compiled) (cdr compiled)
-                                          replacements) t)
-                (replace-match compiled t))
+                                          replacements) fixed-case)
+                (replace-match compiled fixed-case))
               (buffer-substring (point-min) (point-max)))
             "")))))
 
@@ -472,19 +470,27 @@
   (let ((separator (or anzu-replace-to-string-separator "")))
     (propertize (concat separator str) 'face 'anzu-replace-to)))
 
-(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit)
+(defsubst anzu--replaced-literal-string (ov replaced from)
+  (let ((str (buffer-substring-no-properties
+              (overlay-start ov) (overlay-end ov))))
+    (when (string-match str from)
+      (replace-match replaced (not case-fold-search) nil str))))
+
+(defun anzu--append-replaced-string (buf beg end use-regexp overlay-limit from)
   (let ((content (minibuffer-contents))
         (replacements 0))
     (unless (string= content anzu--last-replace-input)
       (setq anzu--last-replace-input content)
       (with-current-buffer buf
-        (dolist (ov (anzu--overlays-in-range beg (min end overlay-limit)))
-          (let ((replace-evaled (and use-regexp (anzu--evaluate-occurrence
-                                                 ov content replacements))))
-            (if replace-evaled
-                (cl-incf replacements)
-              (setq replace-evaled content))
-            (overlay-put ov 'after-string (anzu--propertize-to-string 
replace-evaled))))))))
+        (let ((case-fold-search (anzu--case-fold-search from)))
+          (dolist (ov (anzu--overlays-in-range beg (min end overlay-limit)))
+            (let ((replace-evaled
+                   (if (not use-regexp)
+                       (anzu--replaced-literal-string ov content from)
+                     (prog1 (anzu--evaluate-occurrence ov content replacements
+                                                       (not case-fold-search) 
from)
+                       (cl-incf replacements)))))
+              (overlay-put ov 'after-string (anzu--propertize-to-string 
replace-evaled)))))))))
 
 (defsubst anzu--outside-overlay-limit (orig-beg orig-limit)
   (save-excursion
@@ -512,7 +518,7 @@
                                (with-selected-window (or 
(active-minibuffer-window)
                                                          (minibuffer-window))
                                  (anzu--append-replaced-string
-                                  curbuf beg end use-regexp overlay-limit))))))
+                                  curbuf beg end use-regexp overlay-limit 
from))))))
           (prog1 (read-from-minibuffer to-prompt
                                        nil nil nil
                                        query-replace-from-history-variable nil 
t)



reply via email to

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