diff options
| author | Philip Kaludercic | 2022-10-28 19:44:47 +0200 |
|---|---|---|
| committer | Philip Kaludercic | 2022-11-05 00:07:07 +0100 |
| commit | b2401cdfd21f6b23fbed57ffceec488ed4700de6 (patch) | |
| tree | 41e322aa3b208cc729ab7d800bc9fead789d9840 | |
| parent | f3c138bb1abd1d31bdb794d80eb6ea84d674ed00 (diff) | |
| download | emacs-b2401cdfd21f6b23fbed57ffceec488ed4700de6.tar.gz emacs-b2401cdfd21f6b23fbed57ffceec488ed4700de6.zip | |
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.
| -rw-r--r-- | doc/emacs/rmail.texi | 8 | ||||
| -rw-r--r-- | lisp/rot13.el | 11 |
2 files changed, 17 insertions, 2 deletions
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. | |||
| 1409 | rot13-other-window}. This displays the current buffer in another window | 1409 | rot13-other-window}. This displays the current buffer in another window |
| 1410 | which applies the code when displaying the text. | 1410 | which applies the code when displaying the text. |
| 1411 | 1411 | ||
| 1412 | @findex rot13-region | ||
| 1413 | If you are only interested in a region, the command @kbd{M-x | ||
| 1414 | rot13-region} might be preferable. This will encrypt/decrypt the | ||
| 1415 | active region in-place. If the buffer is read-only, it will attempt | ||
| 1416 | to display the plain text in the echo area. If the text is too long | ||
| 1417 | for the echo area, the command will pop up a temporary buffer with the | ||
| 1418 | encrypted/decrypted text. | ||
| 1419 | |||
| 1412 | @node Movemail | 1420 | @node Movemail |
| 1413 | @section @command{movemail} program | 1421 | @section @command{movemail} program |
| 1414 | @cindex @command{movemail} program | 1422 | @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." | |||
| 85 | 85 | ||
| 86 | ;;;###autoload | 86 | ;;;###autoload |
| 87 | (defun rot13-region (start end) | 87 | (defun rot13-region (start end) |
| 88 | "ROT13 encrypt the region between START and END in current buffer." | 88 | "ROT13 encrypt the region between START and END in current buffer. |
| 89 | If invoked interactively and the buffer is read-only, a message | ||
| 90 | will be printed instead." | ||
| 89 | (interactive "r") | 91 | (interactive "r") |
| 90 | (translate-region start end rot13-translate-table)) | 92 | (condition-case nil |
| 93 | (translate-region start end rot13-translate-table) | ||
| 94 | (buffer-read-only | ||
| 95 | (when (called-interactively-p 'interactive) | ||
| 96 | (let ((dec (rot13-string (buffer-substring start end)))) | ||
| 97 | (message "Buffer is read-only:\n%s" (string-trim dec))))))) | ||
| 91 | 98 | ||
| 92 | ;;;###autoload | 99 | ;;;###autoload |
| 93 | (defun rot13-other-window () | 100 | (defun rot13-other-window () |