我有以下代码运行以范围输入的Figlet。
如何修改此代码以检查 b 或 e 是否未指定,使 b 位于当前缓冲区的开头,e 位于当前缓冲区的结尾?
(defun figlet-region (&optional b e)
(interactive "r")
(shell-command-on-region b e "/opt/local/bin/figlet" (current-buffer) t)
(comment-region (mark) (point)))
(global-set-key (kbd "C-c C-x") 'figlet-region)
ADDED
肖恩帮助我找到了这个问题的答案
(defun figlet-region (&optional b e)
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e "/opt/local/bin/figlet" (current-buffer) t)
(comment-region (mark) (point))))
(global-set-key (kbd "C-c C-x") 'figlet-region)
像这样:
(defun figlet-region (&optional b e)
(interactive "r")
(shell-command-on-region
(or b (point-min))
(or e (point-max))
"/opt/local/bin/figlet" (current-buffer) t)
(comment-region (mark) (point)))
但请注意b
and e
当此命令交互运行时将始终被设置。
你也可以这样做:
(require 'cl)
(defun* figlet-region (&optional (b (point-min)) (e (point-max)))
# your original function body here
)
EDIT:
所以我猜您的意思是即使该区域未处于活动状态,您也希望能够以交互方式运行该命令?那么也许这对你有用:
(defun figlet-region ()
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
# ... rest of your original function body ...
))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)