unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 58843@debbugs.gnu.org
Subject: bug#58843: Print "decrypted" rot13 text is buffer is read-only
Date: Fri, 28 Oct 2022 19:37:28 +0000	[thread overview]
Message-ID: <87zgdf20zr.fsf@posteo.net> (raw)
In-Reply-To: <838rkzkb99.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 28 Oct 2022 22:18:26 +0300")

[-- Attachment #1: Type: text/plain, Size: 553 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Fri, 28 Oct 2022 18:24:58 +0000
>> 
>> Tags: patch
>> 
>> 
>> When someone sends you rot13'ed text but the buffer is read-only, it
>> seems the next best thing one can do is to print the decrypted text.  I
>> don't think it makes sense in general for `translate-region' to do the
>> same, so I just modified the code in rot13.el.
>
> Thanks, but I see no patch in your message.  I see a complete rot13.el
> file.

Oops, I must have selected the wrong file.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-rot13.el-rot13-region-Add-fallback-if-buffer-is.patch --]
[-- Type: text/x-patch, Size: 1187 bytes --]

From f97a27dcd06bafcb3ec6beaaf0f4d3b044f9fa64 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Fri, 28 Oct 2022 19:44:47 +0200
Subject: [PATCH] * lisp/rot13.el (rot13-region): Add fallback if buffer is
 read-only

---
 lisp/rot13.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

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 @@ rot13-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 ()
-- 
2.37.3


  reply	other threads:[~2022-10-28 19:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 18:24 bug#58843: Print "decrypted" rot13 text is buffer is read-only Philip Kaludercic
2022-10-28 19:18 ` Eli Zaretskii
2022-10-28 19:37   ` Philip Kaludercic [this message]
2022-10-29  5:51     ` Eli Zaretskii
2022-10-29  6:28       ` Philip Kaludercic
2022-10-29  7:08         ` Eli Zaretskii
2022-10-29 15:32           ` Philip Kaludercic
2022-10-29 15:50             ` Eli Zaretskii
2022-10-29 16:03               ` Philip Kaludercic
2022-10-29 16:12                 ` Eli Zaretskii
2022-10-29 16:25                   ` Philip Kaludercic
2022-10-29 16:45                     ` Eli Zaretskii
2022-10-30 14:17                       ` Philip Kaludercic
2022-11-04 23:09                         ` Philip Kaludercic
2022-10-30 14:44                     ` Stefan Kangas
2022-10-30 14:52                       ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zgdf20zr.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=58843@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).