emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3b93549: * lisp/simple.el (shell-command-on-region): Handle nil r


From: Juri Linkov
Subject: master 3b93549: * lisp/simple.el (shell-command-on-region): Handle nil replace on rectangles.
Date: Mon, 8 Jun 2020 19:35:01 -0400 (EDT)

branch: master
commit 3b93549597f187989e5508b638f297d0244e5cc6
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * 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 247769e..0fe8a10 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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]