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

时间:2017-08-17 01:25:25

标签: emacs spacemacs

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

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

1 个答案:

答案 0 :(得分:0)

试试这个。我所做的就是从interactive复制shell-command-on-region规范,并将参数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))