call-interactively和funcall-interactively的区别是什么?

请问elisp里的call-interactively和funcall-interactively的区别什么?

funcall-interactively 只是标记目标函数是 “interactively” 运行,它并不会运行目标函数里的 (interactive ...) 语句,所以参数要你自己传。

call-interactively 就和你自己 interactively 运行目标函数一样,先运行 “(interactive …)”,所以自己不用传参数。

例子:

(defun foo (beg end)
  (interactive "r")
  (message "begin:%d and end:%d" beg end))

(funcall-interactively 'foo (point-min) (point-max))
(call-interactively 'foo)  ;;和M-x foo RET 结果一样。

6 个赞