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)
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)
A buffer visiting a write-protected file is normally read-only. Here, the purpose is to inform the user that editing the buffer with the aim of saving it in the file may be futile or undesirable. The user who wants to change the buffer text despite this can do so after clearing the read-only flag with C-x C-q .
To change the read-only status of a buffer, use C-x C-q (toggle read-only-mode ). To change file permissions, you can run dired on the file's directory ( C-x d ), search for the file by C-s and use M to change its mode.
Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.
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 ...
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With