首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Emacs 如何实现lisp“shell---on-zone”?

Emacs 如何实现lisp“shell---on-zone”?
EN

Stack Overflow用户
提问于 2018-01-31 06:02:14
回答 2查看 0关注 0票数 0

在GNU Emacs中,我想在当前选定的文本上运行一个程序,如图。

我已经知道如何使用标准的Emacs命令来实现它:

  • 用C标记-<space>在单词的开头
  • 将光标移到单词的末尾
  • c-u-m-x shell-命令-on-Region ret figlet RET
  • M-x注释-区域RET

然而,我没有想出如何编写EmacsLISP程序来完成所有这些工作。以下是我的尝试:

代码语言:txt
复制
(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-region产生垃圾:

代码语言:txt
复制
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

回答

代码语言:txt
复制
(defun figlet-region (&optional b e) 
  (interactive "r")
  (shell-command-on-region b e "figlet" (current-buffer) t)
  (comment-region (mark) (point)))

示例(Lisp交互模式)

代码语言:txt
复制
;;  _   _                 _        
;; | |_| |__   __ _ _ __ | | _____ 
;; | __| '_ \ / _` | '_ \| |/ / __|
;; | |_| | | | (_| | | | |   <\__ \
;;  \__|_| |_|\__,_|_| |_|_|\_\___/

示例(CPerl模式)

代码语言:txt
复制
#  _   _                 _        
# | |_| |__   __ _ _ __ | | _____ 
# | __| '_ \ / _` | '_ \| |/ / __|
# | |_| | | | (_| | | | |   <\__ \
#  \__|_| |_|\__,_|_| |_|_|\_\___/
EN

回答 2

Stack Overflow用户

发布于 2018-01-31 14:21:25

代码语言:txt
复制
(defun figlet-region (&optional b e) 
  (interactive "r")
  (shell-command-on-region b e "figlet")
  (comment-region b e))

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

票数 0
EN

Stack Overflow用户

发布于 2018-01-31 15:09:11

使用这样的交互式命令不是一个好主意shell-command-on-region在LISP程序中。你应该用call-process-region

代码语言:txt
复制
(defun figlet-region (&optional b e) 
  (interactive "r")
  (call-process-region b e "figlet" t t)
  (comment-region (mark) (point)))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100007273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档