emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b2401cdfd2 2/2: Print "decrypted" rot13 text is buffer is read-on


From: Philip Kaludercic
Subject: master b2401cdfd2 2/2: Print "decrypted" rot13 text is buffer is read-only
Date: Fri, 4 Nov 2022 19:07:21 -0400 (EDT)

branch: master
commit b2401cdfd21f6b23fbed57ffceec488ed4700de6
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    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.
---
 doc/emacs/rmail.texi |  8 ++++++++
 lisp/rot13.el        | 11 +++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/rmail.texi b/doc/emacs/rmail.texi
index e38bde036a..7414cdb079 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 c063725de8..5d1c46e483 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 ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]