From 3b93549597f187989e5508b638f297d0244e5cc6 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 9 Jun 2020 02:34:53 +0300 Subject: [PATCH] * lisp/simple.el (shell-command-on-region): Handle nil replace on rectangles. When 'region-noncontiguous-p' is non-nil (rectangular region) but 'replace' is nil, pop up the shell output buffer (bug#41440). When 'replace' is non-nil, trim the trailing newline. --- lisp/simple.el | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 247769e7ab2..0fe8a1025ce 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3978,7 +3978,7 @@ interactively, this is t." exit-status) ;; Unless a single contiguous chunk is selected, operate on multiple chunks. (if region-noncontiguous-p - (let ((input (concat (funcall region-extract-function 'delete) "\n")) + (let ((input (concat (funcall region-extract-function (when replace 'delete)) "\n")) output) (with-temp-buffer (insert input) @@ -3986,9 +3986,24 @@ interactively, this is t." shell-file-name t t nil shell-command-switch command) - (setq output (split-string (buffer-string) "\n"))) - (goto-char start) - (funcall region-insert-function output)) + (setq output (split-string (buffer-substring + (point-min) + ;; Trim the trailing newline. + (if (eq (char-before (point-max)) ?\n) + (1- (point-max)) + (point-max))) + "\n"))) + (cond + (replace + (goto-char start) + (funcall region-insert-function output)) + (t + (let ((buffer (get-buffer-create + (or output-buffer "*Shell Command Output*")))) + (with-current-buffer buffer + (erase-buffer) + (funcall region-insert-function output)) + (display-message-or-buffer buffer))))) (if (or replace (and output-buffer (not (or (bufferp output-buffer) (stringp output-buffer))))) -- 2.39.5