Emacs lisp“shell-command-on-region”

前端之家收集整理的这篇文章主要介绍了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将区域(点和标记)作为命令的前两个参数传递。

原文链接:https://www.f2er.com/bash/387494.html

猜你在找的Bash相关文章