(py-process-filter): Make sure current-buffer is restored, even in the

event of error.  Can't use new Emacs primitive save-current-buffer, so
use unwind-protect instead.
This commit is contained in:
Barry Warsaw 1996-09-30 23:00:40 +00:00
parent 24611f80e8
commit 7a73ef852f

View file

@ -932,42 +932,47 @@ See the `\\[py-shell]' docs for additional warnings."
;; read_process_output has update_mode_lines++ for a similar ;; read_process_output has update_mode_lines++ for a similar
;; reason? beats me ... ;; reason? beats me ...
;; BAW - we want to check to see if this still applies (unwind-protect
(if (eq curbuf pbuf) ; mysterious ugly hack ;; make sure current buffer is restored
(set-buffer (get-buffer-create "*scratch*"))) ;; BAW - we want to check to see if this still applies
(progn
;; mysterious ugly hack
(if (eq curbuf pbuf)
(set-buffer (get-buffer-create "*scratch*")))
(set-buffer pbuf) (set-buffer pbuf)
(let* ((start (point)) (let* ((start (point))
(goback (< start pmark)) (goback (< start pmark))
(goend (and (not goback) (= start (point-max)))) (goend (and (not goback) (= start (point-max))))
(buffer-read-only nil)) (buffer-read-only nil))
(goto-char pmark) (goto-char pmark)
(insert string) (insert string)
(move-marker pmark (point)) (move-marker pmark (point))
(setq file-finished (setq file-finished
(and py-file-queue (and py-file-queue
(equal ">>> " (equal ">>> "
(buffer-substring (buffer-substring
(prog2 (beginning-of-line) (point) (prog2 (beginning-of-line) (point)
(goto-char pmark)) (goto-char pmark))
(point))))) (point)))))
(if goback (goto-char start) (if goback (goto-char start)
;; else ;; else
(if py-scroll-process-buffer (if py-scroll-process-buffer
(let* ((pop-up-windows t) (let* ((pop-up-windows t)
(pwin (display-buffer pbuf))) (pwin (display-buffer pbuf)))
(set-window-point pwin (point))))) (set-window-point pwin (point)))))
(set-buffer curbuf) (set-buffer curbuf)
(if file-finished (if file-finished
(progn (progn
(py-delete-file-silently (car py-file-queue)) (py-delete-file-silently (car py-file-queue))
(setq py-file-queue (cdr py-file-queue)) (setq py-file-queue (cdr py-file-queue))
(if py-file-queue (if py-file-queue
(py-execute-file pyproc (car py-file-queue))))) (py-execute-file pyproc (car py-file-queue)))))
(and goend (and goend
(progn (set-buffer pbuf) (progn (set-buffer pbuf)
(goto-char (point-max)))) (goto-char (point-max))))
))) ))
(set-buffer curbuf))))
(defun py-execute-buffer () (defun py-execute-buffer ()
"Send the contents of the buffer to a Python interpreter. "Send the contents of the buffer to a Python interpreter.