使用绑定到它的键调用 Emacs 命令:如何指定可选参数?

Invoking Emacs command using key bound to it: How can I specify the optional parameter?

我一直在尝试调用绑定到 M-| 的交互式 lisp 函数 shell-command-on-region。我想知道如果我想重定向命令的输出,我应该如何指定名为 OUTPUT-BUFFER 的第 4 个参数?

我的环境:'Emacs25.2 + spacemacs' MS Windows.

试试这个。我所做的只是从 shell-command-on-region 复制 interactive 规范,并将参数 OUTPUT-BUFFER 的前缀 arg 替换为您输入的缓冲区名称。

(defun foo (start end command
            &optional output-buffer replace error-buffer display-error-buffer)
  (interactive
   (let (string buffer)
     (unless (mark)
       (error "The mark is not set now, so there is no region"))
     (setq string  (read-shell-command "Shell command on region: ")
           buffer  (read-buffer "Output buffer: "))
     (list (region-beginning) (region-end) string buffer
           current-prefix-arg shell-command-default-error-buffer t)))
  (shell-command-on-region start end command output-buffer
                           replace error-buffer display-error-buffer))