summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-04-09 14:19:23 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2023-04-09 14:19:23 +0200
commitc88e1ee3026af6d1734c0e171555c1ae9152f07a (patch)
tree16f569819ae8d75deded1a7987642b7f088ad0ad
parentf374f5284ecc5abd5d776ced111c2122a4c51a37 (diff)
Improve cape--case-replace
-rw-r--r--cape.el8
1 files changed, 6 insertions, 2 deletions
diff --git a/cape.el b/cape.el
index ec9cbba..0d570ab 100644
--- a/cape.el
+++ b/cape.el
@@ -132,16 +132,20 @@ The buffers are scanned for completion candidates by `cape-line'."
(defun cape--case-replace-list (flag input strs)
"Replace case of STRS depending on INPUT and FLAG."
(if (and (if (eq flag 'case-replace) case-replace flag)
- (not (equal input "")))
+ (string-match-p "\\`[[:upper:]]" input))
(mapcar (apply-partially #'cape--case-replace flag input) strs)
strs))
(defun cape--case-replace (flag input str)
"Replace case of STR depending on INPUT and FLAG."
(or (and (if (eq flag 'case-replace) case-replace flag)
- (not (equal input ""))
(string-prefix-p input str t)
+ (string-match-p "\\`[[:upper:]]" input)
(save-match-data
+ ;; Ensure that single character uppercase input does not lead to an
+ ;; all uppercase result.
+ (when (and (= (length input) 1) (> (length str) 1))
+ (setq input (concat input (substring str 1 2))))
(and (string-match input input)
(replace-match str nil nil input))))
str))