【发布时间】:2017-07-20 16:06:36
【问题描述】:
我想动态地将一个命令重定向到另一个命令 使用周围建议的某些功能,如下所示:
(defun f1 (arg)
(interactive (list (read-from-minibuffer "F1: ")))
(message "f1: %S" arg)
arg)
(defun f2 (arg)
(interactive (list (read-from-minibuffer "F2: ")))
(message "f2: %S" arg)
arg)
;; Function that invokes the f1 command
(defun myfunc ()
(call-interactively 'f1))
;; I want myfunc to invoke f2 instead whenever it would invoke f1
(defadvice myfunc (around f1-to-f2 activate)
(flet ((f1 (&rest args) (interactive) (call-interactively 'f2)))
ad-do-it))
(myfunc)
但是,这会产生错误(wrong-type-argument commandp f1),
表示当flet重新定义f1函数时,它没有
处理交互式表单并将其视为命令,因此它不能
由call-interactively 调用。
是否有flet 的变体可以以这种方式用于命令?
(这是我想要做的实际重新定义:)
(defadvice org-metaleft (around osx-command activate)
(flet ((backward-word (&rest args)
(interactive)
(call-interactively #'move-beginning-of-line)))
ad-do-it))
(defadvice org-metaright (around osx-command activate)
(flet ((forward-word (&rest args)
(interactive)
(call-interactively #'move-end-of-line)))
ad-do-it))
【问题讨论】: