我有以下代码来运行将输入作为范围的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)已添加
肖恩帮我找到了这个问题的答案
(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)发布于 2010-08-26 03:35:37
如下所示:
(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和e。
你也可以这样做:
(require 'cl)
(defun* figlet-region (&optional (b (point-min)) (e (point-max)))
# your original function body here
)编辑:
所以我猜你的意思是,即使区域处于非活动状态,你也希望能够以交互方式运行该命令?那么这可能会对你起作用:
(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 ...
))发布于 2010-08-26 03:34:39
试一试
(unless b (setq b (point-min)))
(unless e (setq e (point-max)))https://stackoverflow.com/questions/3569501
复制相似问题