>From f97a27dcd06bafcb3ec6beaaf0f4d3b044f9fa64 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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