Skip to content

Commit a163850

Browse files
committed
Allow \l, \U, etc. override case-replace in substitution replacements
1 parent 30ebe6d commit a163850

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

evil-commands.el

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,6 +3939,10 @@ replacements made or found."
39393939
nreplaced
39403940
(if (/= nreplaced 1) "s" ""))))))
39413941

3942+
(defvar evil--substitute-fixed-case (not case-replace)
3943+
"Whether the replacement for a substitution respects case.
3944+
By default, the oposite of `case-replace', but can be overridden by flags.")
3945+
39423946
(evil-define-operator evil-ex-substitute
39433947
(beg end pattern replacement flags)
39443948
"The Ex substitute command.
@@ -4014,7 +4018,8 @@ replacements made or found."
40144018
(when (member response '(?y ?a ?l))
40154019
(unless count-only
40164020
(set-match-data match-data)
4017-
(replace-match next-replacement (not case-replace)))
4021+
(replace-match next-replacement evil--substitute-fixed-case)
4022+
(setq evil--substitute-fixed-case (not case-replace)))
40184023
(cl-incf nreplaced)
40194024
(evil-ex-hl-set-region
40204025
'evil-ex-substitute
@@ -4032,7 +4037,8 @@ replacements made or found."
40324037
(if (stringp replacement) replacement
40334038
(funcall (car replacement) (cdr replacement) nreplaced))))
40344039
(set-match-data match-data)
4035-
(replace-match next-replacement (not case-replace))))
4040+
(replace-match next-replacement evil--substitute-fixed-case)
4041+
(setq evil--substitute-fixed-case (not case-replace))))
40364042
(cl-incf nreplaced))
40374043
(setq last-point (point))
40384044
(cond ((>= (point) end-marker)

evil-common.el

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,7 @@ transformations, usually `regexp-quote' or `replace-quote'."
35243524
(evil-magic evil-magic)
35253525
(quote (or quote #'identity))
35263526
result stop)
3527+
(setq evil--substitute-fixed-case (not case-replace))
35273528
(while (and (not stop) str (string-match regexp str))
35283529
(unless (zerop (match-beginning 1))
35293530
(push (substring str 0 (match-beginning 1)) result))
@@ -3687,10 +3688,12 @@ REST is the unparsed remainder of TO."
36873688
(?u . evil-upcase-first)
36883689
(?U . upcase))))))
36893690
(list `(,func
3690-
(replace-quote
3691-
(evil-match-substitute-replacement
3692-
,(car result)
3693-
(not case-replace))))
3691+
(progn
3692+
(setq evil--substitute-fixed-case t)
3693+
(replace-quote
3694+
(evil-match-substitute-replacement
3695+
,(car result)
3696+
nil))))
36943697
(cdr result))))
36953698
((eq char ?=)
36963699
(when (or (zerop (length rest))
@@ -3733,7 +3736,7 @@ REST is the unparsed remainder of TO."
37333736
Return a list suitable for `perform-replace' if necessary, the
37343737
original string if not. Currently the following magic characters
37353738
in replacements are supported: 0-9&#lLuUrnbt,
3736-
The magic character , (comma) start an Emacs-lisp expression."
3739+
The magic character , (comma) starts an Emacs-lisp expression."
37373740
(when (stringp to)
37383741
(save-match-data
37393742
(cons 'replace-eval-replacement
@@ -3749,7 +3752,9 @@ replacement text first."
37493752
(funcall (car replacement)
37503753
(cdr replacement)
37513754
0))
3752-
fixedcase nil string))
3755+
(or evil--substitute-fixed-case fixedcase)
3756+
nil
3757+
string))
37533758

37543759
;;; Alignment
37553760

0 commit comments

Comments
 (0)