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: Sat, 29 Oct 2022 15:32:10 +0000	[thread overview]
Message-ID: <87zgdeprwl.fsf@posteo.net> (raw)
In-Reply-To: <83o7tvhzu7.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 29 Oct 2022 10:08:00 +0300")

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> Cc: 58843@debbugs.gnu.org
>> Date: Sat, 29 Oct 2022 06:28:43 +0000
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > Showing the result in the echo-area is a good idea, but echo-area is
>> > not really suitable for displaying arbitrarily long text.  How about
>> > popping a window with a temporary buffer instead?
>> 
>> Is there a way to re-use shell-command's behaviour of displaying short
>> messages in the echo area and longer messages in a separate buffer?
>
> It's a few lines in shell-command, so you could reuse them, or make a
> utility function out of them.

Turns out there was a function that does just this,
`display-message-or-buffer'.

>> Popping up a buffer just for one or two lines can be annoying,
>> especially if the information is not something you want to keep around.
>
> Sure, that would be even better.  Although in that case we'd need to
> change what the manual says about the command, because it explicitly
> says we show the encoded text in another window.

How is this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Have-rot13-region-gracefully-handle-read-only-buffer.patch --]
[-- Type: text/x-patch, Size: 1964 bytes --]

From db7c83f864971ce457ac8319d02c4579f3b76e0a Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Sat, 29 Oct 2022 17:30:13 +0200
Subject: [PATCH] Have 'rot13-region' gracefully handle read-only buffers

* etc/NEWS: Mention new behaviour.
* lisp/rot13.el (rot13-region): Use 'display-message-or-buffer'
---
 etc/NEWS      |  4 ++++
 lisp/rot13.el | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 19c9014116..750d9c76ba 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -828,6 +828,10 @@ wheel reports.  Unlike 'pixel-scroll-mode', this mode scrolls the
 display pixel-by-pixel, as opposed to only animating line-by-line
 scrolls.
 
+** 'rot13-region' handles read-only text
+If a buffer is read-only, 'rot13-region' will display the "decrypted"
+text in the echo area, or if necessary in a separate buffer.
+
 ** Terminal Emacs
 
 ---
diff --git a/lisp/rot13.el b/lisp/rot13.el
index c063725de8..ba27a3a074 100644
--- a/lisp/rot13.el
+++ b/lisp/rot13.el
@@ -85,9 +85,19 @@ 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, the buffer
+is either displayed in a the echo area if the text is short
+enough (as determined by `resize-mini-windows' and
+`max-mini-window-height'), or in a separate buffer."
   (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* ((encrypted (buffer-substring-no-properties start end))
+              (decrypted (rot13-string encrypted)))
+         (display-message-or-buffer decrypted "*Rot 13*"))))))
 
 ;;;###autoload
 (defun rot13-other-window ()
-- 
2.38.0


  reply	other threads:[~2022-10-29 15:32 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
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 [this message]
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=87zgdeprwl.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).