Print "decrypted" rot13 text is buffer is read-only

* lisp/rot13.el (rot13-region): Add fallback if buffer is read-only
* doc/emacs/rmail.texi (Rmail Rot13): Document new behaviour.
This commit is contained in:
Philip Kaludercic 2022-10-28 19:44:47 +02:00
parent f3c138bb1a
commit b2401cdfd2
2 changed files with 17 additions and 2 deletions

View file

@ -1409,6 +1409,14 @@ might use rot13 to hide important plot points.
rot13-other-window}. This displays the current buffer in another window
which applies the code when displaying the text.
@findex rot13-region
If you are only interested in a region, the command @kbd{M-x
rot13-region} might be preferable. This will encrypt/decrypt the
active region in-place. If the buffer is read-only, it will attempt
to display the plain text in the echo area. If the text is too long
for the echo area, the command will pop up a temporary buffer with the
encrypted/decrypted text.
@node Movemail
@section @command{movemail} program
@cindex @command{movemail} program

View file

@ -85,9 +85,16 @@ and END, and return the encrypted string."
;;;###autoload
(defun rot13-region (start end)
"ROT13 encrypt the region between START and END in current buffer."
"ROT13 encrypt the region between START and END in current buffer.
If invoked interactively and the buffer is read-only, a message
will be printed instead."
(interactive "r")
(translate-region start end rot13-translate-table))
(condition-case nil
(translate-region start end rot13-translate-table)
(buffer-read-only
(when (called-interactively-p 'interactive)
(let ((dec (rot13-string (buffer-substring start end))))
(message "Buffer is read-only:\n%s" (string-trim dec)))))))
;;;###autoload
(defun rot13-other-window ()