From: Philip Kaludercic Date: Fri, 28 Oct 2022 17:44:47 +0000 (+0200) Subject: Print "decrypted" rot13 text is buffer is read-only X-Git-Tag: emacs-29.0.90~1616^2~299 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b2401cdfd21f6b23fbed57ffceec488ed4700de6;p=emacs.git 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. --- diff --git a/doc/emacs/rmail.texi b/doc/emacs/rmail.texi index e38bde036ad..7414cdb0799 100644 --- a/doc/emacs/rmail.texi +++ b/doc/emacs/rmail.texi @@ -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 diff --git a/lisp/rot13.el b/lisp/rot13.el index c063725de85..5d1c46e4830 100644 --- a/lisp/rot13.el +++ b/lisp/rot13.el @@ -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 ()