]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/simple.el (shell-command-on-region): Handle nil replace on rectangles.
authorJuri Linkov <juri@linkov.net>
Mon, 8 Jun 2020 23:34:53 +0000 (02:34 +0300)
committerJuri Linkov <juri@linkov.net>
Mon, 8 Jun 2020 23:34:53 +0000 (02:34 +0300)
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

index 247769e7ab26354b815637c7ecf7fee871b1dc0a..0fe8a1025cebcc5c0604d11461376ae9d96f27d2 100644 (file)
@@ -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)))))