C-h f perform-replace
說:
Don't use this in your own program unless you want to query and set the mark
just as `query-replace' does. Instead, write a simple loop like this:
(while (re-search-forward "foo[ \t]+bar" nil t)
(replace-match "foobar"))
現在"<\\,(downcase \1)>"
需要通過建立正確的琴絃的elisp的表達式來代替,如(format "<%s>" (downcase (match-string 1)))
。
如果您確實需要查詢和內容,那麼您可能想嘗試:C-M-% f\(o\)o RET bar \,(downcase \1) baz RET
然後C-x RET RET
以查看在交互式調用期間構建了哪些參數。
你會看到發現(甚至更好,如果你在C-h f perform-replace
點擊replace.el
看到函數的源代碼),該replacements
參數可以採取的形式(FUNCTION。參數)。更具體地說,代碼包括一個評論給出的一些細節:
;; REPLACEMENTS is either a string, a list of strings, or a cons cell
;; containing a function and its first argument. The function is
;; called to generate each replacement like this:
;; (funcall (car replacements) (cdr replacements) replace-count)
;; It must return a string.
;; REPLACEMENTS is either a string, a list of strings, or a cons cell
;; containing a function and its first argument. The function is
;; called to generate each replacement like this:
;; (funcall (car replacements) (cdr replacements) replace-count)
;; It must return a string.
nop,我需要查詢(y/n /!等),並突出執行替換的能力(我不希望重新實現它用y或np + highlight-regexp或類似的) –
你可能想要編輯你的問題來反映這個約束。無論如何,我提出了一個基於'perform-replace'的解決方案,它可以滿足您的要求。 – Francesco