Define an emacs command that calls another emacs command (preserving interactive stuff)

一世执手 提交于 2019-12-04 15:28:47

Use call-interactively:


(defun alt-query-replace ()
  (interactive)
  (let ((case-fold-search (not case-fold-search)))
    (call-interactively 'query-replace)))

You may advise the original function, if you want to modify its behavior instead of calling a separate function.

From chapter 17.3 Around-Advice of the GNU Emacs Lisp Reference Manual:

Around-advice lets you “wrap” a Lisp expression “around” the original function definition.

 (defadvice foo (around foo-around)
   "Ignore case in `foo'."
   (let ((case-fold-search t))
     ad-do-it))

In your case, you can write:

(defadvice query-replace (around alt-query-replace (from-string to-string &optional delimited start end))
    (let ((case-fold-search (not case-fold-search)))
      ad-do-it))
(ad-activate 'query-replace)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!