Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a73ef8

Browse files
committed
(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.
1 parent 24611f8 commit 7a73ef8

1 file changed

Lines changed: 41 additions & 36 deletions

File tree

Misc/python-mode.el

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -932,42 +932,47 @@ See the `\\[py-shell]' docs for additional warnings."
932932
;; read_process_output has update_mode_lines++ for a similar
933933
;; reason? beats me ...
934934

935-
;; BAW - we want to check to see if this still applies
936-
(if (eq curbuf pbuf) ; mysterious ugly hack
937-
(set-buffer (get-buffer-create "*scratch*")))
938-
939-
(set-buffer pbuf)
940-
(let* ((start (point))
941-
(goback (< start pmark))
942-
(goend (and (not goback) (= start (point-max))))
943-
(buffer-read-only nil))
944-
(goto-char pmark)
945-
(insert string)
946-
(move-marker pmark (point))
947-
(setq file-finished
948-
(and py-file-queue
949-
(equal ">>> "
950-
(buffer-substring
951-
(prog2 (beginning-of-line) (point)
952-
(goto-char pmark))
953-
(point)))))
954-
(if goback (goto-char start)
955-
;; else
956-
(if py-scroll-process-buffer
957-
(let* ((pop-up-windows t)
958-
(pwin (display-buffer pbuf)))
959-
(set-window-point pwin (point)))))
960-
(set-buffer curbuf)
961-
(if file-finished
962-
(progn
963-
(py-delete-file-silently (car py-file-queue))
964-
(setq py-file-queue (cdr py-file-queue))
965-
(if py-file-queue
966-
(py-execute-file pyproc (car py-file-queue)))))
967-
(and goend
968-
(progn (set-buffer pbuf)
969-
(goto-char (point-max))))
970-
)))
935+
(unwind-protect
936+
;; make sure current buffer is restored
937+
;; BAW - we want to check to see if this still applies
938+
(progn
939+
;; mysterious ugly hack
940+
(if (eq curbuf pbuf)
941+
(set-buffer (get-buffer-create "*scratch*")))
942+
943+
(set-buffer pbuf)
944+
(let* ((start (point))
945+
(goback (< start pmark))
946+
(goend (and (not goback) (= start (point-max))))
947+
(buffer-read-only nil))
948+
(goto-char pmark)
949+
(insert string)
950+
(move-marker pmark (point))
951+
(setq file-finished
952+
(and py-file-queue
953+
(equal ">>> "
954+
(buffer-substring
955+
(prog2 (beginning-of-line) (point)
956+
(goto-char pmark))
957+
(point)))))
958+
(if goback (goto-char start)
959+
;; else
960+
(if py-scroll-process-buffer
961+
(let* ((pop-up-windows t)
962+
(pwin (display-buffer pbuf)))
963+
(set-window-point pwin (point)))))
964+
(set-buffer curbuf)
965+
(if file-finished
966+
(progn
967+
(py-delete-file-silently (car py-file-queue))
968+
(setq py-file-queue (cdr py-file-queue))
969+
(if py-file-queue
970+
(py-execute-file pyproc (car py-file-queue)))))
971+
(and goend
972+
(progn (set-buffer pbuf)
973+
(goto-char (point-max))))
974+
))
975+
(set-buffer curbuf))))
971976

972977
(defun py-execute-buffer ()
973978
"Send the contents of the buffer to a Python interpreter.

0 commit comments

Comments
 (0)