如何使用emacs / elisp获取当前缓冲区信息的开始/结束? [英] How to get the start/end of the current buffer info with emacs/elisp?

查看:211
本文介绍了如何使用emacs / elisp获取当前缓冲区信息的开始/结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它将输入作为范围运行figlet。
如何修改此代码以检查是否未指定b或e,将b设置为当前缓冲区的开头,e结束当前缓冲区?




(shell-command-on-region be/ opt /本地/ bin / figlet(当前缓冲区)t)
(注释区域(标记)(点)))
(全局设置密钥(kbdCc Cx)' )



ADDED



肖恩帮助我得到这个问题的答案

 (defun figlet-region(& optional be)
(interactive)
(let((b(if mark-active(min(point)(mark))(point-min)))
(e(if mark-active(max(point)(mark)) -max))))
(shell-command-on-region为/ opt / local / bin / figlet(current-buffer)t)
(注释区域(标记) ))
(global-set-key(kbdCc Cx)'figlet-region)


解决方案

喜欢th是:

 (defun figlet-region(& optional be)
(interactiver)
(shell-command-on-region
(或b(point-min))
(或e(point-max))
/ opt / local / bin / figlet当前缓冲区)t)
(注释区域(标记)(点)))

但请注意,当此命令以交互方式运行时,始终设置 b e



您还可以这样做:

 (require'cl)

(defun * figlet-region(& optional(b(point-min))(e(point-max)))
#你的原始功能体在这里

编辑:



所以我想你的意思是想要能够即使区域不活动,也可以交互地运行命令?那么也许这将适用于你:

 (defun figlet-region()
(interactive)
(如果标记有效(最小(点)(标记))(点最小)))
(e(如果标记有效(最大(点)(标记)) ))))
#...您的原始功能体的其余部分...
))


I have the following code that runs figlet that has input as a range. How can I modify this code to check if b or e is not specified, make b to the start of the current buffer, and e end of the current buffer?

(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

Sean helped me to get an answer to this question

(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)

解决方案

Like this:

(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)))

But note that b and e will always be set when this command is run interactively.

You could also do this:

(require 'cl)

(defun* figlet-region (&optional (b (point-min)) (e (point-max)))
  # your original function body here
    )

EDIT:

So I guess you mean you want to be able to run the command interactively even if the region is not active? Then maybe this will work for you:

(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 ...
      ))

这篇关于如何使用emacs / elisp获取当前缓冲区信息的开始/结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆