How to get the start/end of the current buffer info with emacs/elisp?

我的未来我决定 提交于 2019-12-04 06:02:52

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

Try

(unless b (setq b (point-min)))
(unless e (setq e (point-max)))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!