Be more careful about order of events in M-x shell-command-on-region
authorChris Hanson <org/chris-hanson/cph>
Fri, 11 Oct 1991 03:58:56 +0000 (03:58 +0000)
committerChris Hanson <org/chris-hanson/cph>
Fri, 11 Oct 1991 03:58:56 +0000 (03:58 +0000)
when the prefix arg is given.  Make sure that the output replaces the
input atomically.

v7/src/edwin/process.scm

index 7b61031bd6e66325c31c1685f7604042952a32a7..f8b636f7d9d941995a92757160de510b79e379c0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; -*-Scheme-*-
 ;;;
-;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/process.scm,v 1.9 1991/10/11 03:34:46 cph Exp $
+;;;    $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/process.scm,v 1.10 1991/10/11 03:58:56 cph Exp $
 ;;;
 ;;;    Copyright (c) 1991 Massachusetts Institute of Technology
 ;;;
@@ -610,16 +610,24 @@ Prefix arg means replace the region with it."
        (let ((point (current-point))
              (mark (current-mark)))
          (let ((swap? (mark< point mark))
-               (temp (temporary-buffer " *shell-input*")))
-           (let ((st (buffer-start temp)))
-             (if swap?
-                 (insert-region point mark st)
-                 (insert-region mark point st))
-             (delete-string point mark)
-             (shell-command-region command
-                                   point
-                                   (make-region st (buffer-end temp))))
-           (kill-buffer temp)
+               (temp))
+           (dynamic-wind
+            (lambda () unspecific)
+            (lambda ()
+              (set! temp (temporary-buffer " *shell-output*"))
+              (shell-command-region command
+                                    (buffer-start temp)
+                                    (make-region point mark))
+              (without-interrupts
+                (lambda ()
+                  (delete-string point mark)
+                  (insert-region (buffer-start temp)
+                                 (buffer-end temp)
+                                 (current-point)))))
+            (lambda ()
+              (kill-buffer temp)
+              (set! temp)
+              unspecific))
            (if swap? ((ref-command exchange-point-and-mark)))))
        (shell-command-pop-up-output
         (lambda (output-mark)