From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#58843: Print "decrypted" rot13 text is buffer is read-only Date: Sat, 29 Oct 2022 15:32:10 +0000 Message-ID: <87zgdeprwl.fsf@posteo.net> References: <877d0j3ix1.fsf@posteo.net> <838rkzkb99.fsf@gnu.org> <87zgdf20zr.fsf@posteo.net> <835yg3jhxm.fsf@gnu.org> <87k04j16uc.fsf@posteo.net> <83o7tvhzu7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10741"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58843@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 29 17:33:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oonpu-0002X8-NM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 29 Oct 2022 17:33:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oonpd-0000De-19; Sat, 29 Oct 2022 11:33:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oonpX-00008V-Be for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 11:33:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oonpW-0000pa-Dh for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 11:33:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oonpW-0004DU-7D for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 11:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Oct 2022 15:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58843 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 58843-submit@debbugs.gnu.org id=B58843.166705754116159 (code B ref 58843); Sat, 29 Oct 2022 15:33:02 +0000 Original-Received: (at 58843) by debbugs.gnu.org; 29 Oct 2022 15:32:21 +0000 Original-Received: from localhost ([127.0.0.1]:36369 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oonor-0004CZ-AF for submit@debbugs.gnu.org; Sat, 29 Oct 2022 11:32:21 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:46707) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oonoo-0004CI-HE for 58843@debbugs.gnu.org; Sat, 29 Oct 2022 11:32:19 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 86A15240026 for <58843@debbugs.gnu.org>; Sat, 29 Oct 2022 17:32:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1667057532; bh=mrHgtvrY6sagUeyzy2zU5CdnILQ6TL+SdZ6R9pT7MXk=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=kQ0o30GaCNXcEBbmvLb1lC1HdS4uPhjzDre9il2Oa3piDT1xbpb8HpaOAs8ATmCTc oJCef8V2qy/gATjYXyesG4iG5ZW3tCsgwPGpVXkcZ9N+9fd8stNjiAVyZPJF60aC5+ GtkYY7Ls75OMHdTzEaL//9ukyC6ycHzt6PTFxNt8dXT7/Z7CpP4VH+WcFjnzgPBlhF hZspLN07a75u+vEQRWZR6befLpebwAScU/CpcPCPAzq8J9kjJwrnKCx/HI9hfwes+H YaOuJj+sh3a1QQDEobMKXGY27iPEM+hOUz9UCn/qvK5FIlrva/Nbg8mwJ83sj50ERX Z1Zaju7/z5V+A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N03Lg498Tz9rxG; Sat, 29 Oct 2022 17:32:10 +0200 (CEST) In-Reply-To: <83o7tvhzu7.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 29 Oct 2022 10:08:00 +0300") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246541 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: 58843@debbugs.gnu.org >> Date: Sat, 29 Oct 2022 06:28:43 +0000 >> >> Eli Zaretskii 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: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Have-rot13-region-gracefully-handle-read-only-buffer.patch >From db7c83f864971ce457ac8319d02c4579f3b76e0a Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-=--