From 3fc922255b1a71eeb1cc99ded000b493ee587a06 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 27 Aug 2021 20:16:25 +0200 Subject: [PATCH] Honor case-replace and case-fold-search If you try to replace "Data" to "test_data" with phi-replace things can get quite frustrating, because phi-replace will only replace it to "Test_Data" even if case-replace is nil. This patch lets the user replace Data to test_data by setting case-replace to nil. --- phi-replace.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phi-replace.el b/phi-replace.el index 5c389f6..d5d1c89 100644 --- a/phi-replace.el +++ b/phi-replace.el @@ -108,6 +108,9 @@ (defvar phi-replace--mode-line-format '(" *phi-replace*" (:eval (format " [ %d ]" (length phi-search--overlays))))) +(defun phi-replace--fixed-case () + (not (and case-replace case-fold-search))) + (defun phi-replace--update-visual-preview (query replac) (save-excursion (dolist (ov phi-search--overlays) @@ -117,7 +120,7 @@ ov 'after-string (ignore-errors (propertize - (concat "=>" (match-substitute-replacement replac)) + (concat "=>" (match-substitute-replacement replac (phi-replace--fixed-case))) 'face 'phi-replace-preview-face)))))) (defun phi-replace--complete-function () @@ -149,14 +152,14 @@ (if (and phi-replace--query-mode (let ((ch (read-char-choice (format "replace with %s (y, n or !) ? " - (match-substitute-replacement str)) + (match-substitute-replacement str (phi-replace--fixed-case))) '(?y ?n ?!)))) (if (= ch ?!) (setq phi-replace--query-mode nil) (= ch ?n)))) (overlay-put ov 'face 'defualt) (set-match-data match-data) - (replace-match str)) + (replace-match str (phi-replace--fixed-case))) (overlay-put ov 'after-string nil)) (when (and (not phi-replace--query-mode) phi-replace-weight) (sit-for phi-replace-weight)))