Emacs区分大小写替换字符串

Ala*_*ing 11 emacs replace case-sensitive dot-emacs

我刚刚问了一个相关的问题(setq问题),但它有明显的不同,所以我决定分开这个问题.

在我的.emacs文件中,我定义了一个绑定到该replace-string命令的键:

(define-key global-map "\C-r" 'replace-string)
Run Code Online (Sandbox Code Playgroud)

replace-string做基本的搜索和替换.假设搜索字符串的第一个字母是小写,如果case-fold-search是,nil则进行replace-string区分大小写的搜索,否则它会进行不区分大小写的搜索.

问题是case-fold-search控制"搜索"(如search-forward命令)和"搜索和替换"(如replace-string命令)的"区分大小写" .

现在的问题是如何让我JUSTreplace-string命令(或任何C-r必然)区分大小写,留下search-forward不区分大小写的,因为它是在默认情况下.

也许我需要设置case-fold-searchnil只为replace-string命令,但我不知道该怎么做.

dfa*_*fan 10

把它放在你的.emacs中:

(defadvice replace-string (around turn-off-case-fold-search)
  (let ((case-fold-search nil))
    ad-do-it))

(ad-activate 'replace-string)
Run Code Online (Sandbox Code Playgroud)

这确实你说什么,设定case-fold-searchnil只为replace-string.

实际上,这几乎就是Emacs Lisp参考手册中的示例.


jlf*_*jlf 6

试试这个方法,不需要建议:

(global-set-key (kbd "C-r") 
    (lambda () 
      (interactive) 
      (let ((case-fold-search nil)) 
        (call-interactively 'replace-string))))
Run Code Online (Sandbox Code Playgroud)