Emacs lisp“shell-command-on-region”

在GNU Emacs中,我想在当前选定的文本上运行一个程序,figlet。然后我想评论所生产的地区。

我已经弄清楚如何使用标准的Emacs命令:

>使用C-< space>设置标记在这个词的开始
>移动光标到单词的末尾
> C-u M-x区域命令RET图形RET
> M-x注释区域RET

但是,我没有想出如何编写一个Emacs Lisp程序来做这些。这是我的尝试:

(defun figlet-region () 
  (interactive)
  (push-mark)
  (shell-command-on-region "figlet")
  (comment-region (mark) (point))
  (pop-mark)
)

(global-set-key "\C-c\C-f" 'figlet-region)

然后C-< space>; M-x figlet地区生产垃圾

figlet-region: Wrong number of arguments: #[(start end command &optional output-buffer replace error-buffer display-error-buffer) "ÆÇÈ  
\"!É
'jÊ!j;j
0Wb
?Ë`Ì\"Í ÎQÎDRÎÉ!\"&
ffÏ )ãÐqÑ!#Ò#p=¬É$]d|e^|Íed ÎÎD¡ÎÉ!\"&â%qÉ$Á&%Ó *Í ÉØ#DÚ#É!\"&*#Ô!#ÕÖ×!8WrÐ!qd`Z'o   ØcÙÉ\"d'Zb)(Úp!)Û!*" [error-buffer small-temporary-file-directory temporary-file-directory exit-status error-file replace make-temp-file expand-file-name "scor" nil ...] 9 1945557 (let (string) (unless (mark) (error "The mark is not set Now,so there is no region")) (setq string (read-from-minibuffer "Shell command on region: " nil nil nil (quote shell-command-history))) (list (region-beginning) (region-end) string current-prefix-arg current-prefix-arg shell-command-default-error-buffer t))],1

回答

(defun figlet-region (&optional b e) 
  (interactive "r")
  (shell-command-on-region b e "figlet" (current-buffer) t)
  (comment-region (mark) (point)))

(这是基于Trey Jackson的答案。)

示例(Lisp交互模式)

;;  _   _                 _        
;; | |_| |__   __ _ _ __ | | _____ 
;; | __| '_ \ / _` | '_ \| |/ / __|
;; | |_| | | | (_| | | | |   <\__ \
;;  \__|_| |_|\__,_|_| |_|_|\_\___/

示例(CPerl模式)

#  _   _                 _        
# | |_| |__   __ _ _ __ | | _____ 
# | __| '_ \ / _` | '_ \| |/ / __|
# | |_| | | | (_| | | | |   <\__ \
#  \__|_| |_|\__,_|_| |_|_|\_\___/
我不确定您正在尝试通过推出和弹出标记来完成什么,我相信通过这样做可以获得相同的功能
(defun figlet-region (&optional b e) 
  (interactive "r")
  (shell-command-on-region b e "figlet")
  (comment-region b e))

交互的参数告诉Emacs将区域(点和标记)作为命令的前两个参数传递。

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...