From 13d914ed50eeef89288f143dc2b7a084dbfd9079 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:02:56 -0300 Subject: [PATCH] Fixed shell region sending --- lisp/progmodes/python.el | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index ad2d47b2b24..737730d7823 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1018,11 +1018,12 @@ commands.)" dedicated-proc-buffer-name global-proc-buffer-name)))) -(defun python-shell-send-string (string) +(defun python-shell-send-string (string &optional process) "Send STRING to inferior Python process." (interactive "sPython command: ") - (let ((process (python-shell-get-or-create-process))) - (message (format "Sent: %s..." string)) + (let ((process (or process (python-shell-get-or-create-process)))) + (when (called-interactively-p) + (message (format "Sent: %s..." string))) (comint-send-string process string) (when (or (not (string-match "\n$" string)) (string-match "\n[ \t].*\n?$" string)) @@ -1073,17 +1074,11 @@ When argument ARG is non-nil sends the innermost defun." (interactive "fFile to send: ") (let ((process (or process (python-shell-get-or-create-process))) (full-file-name (expand-file-name file-name))) - (accept-process-output process) - (with-current-buffer (process-buffer process) - (delete-region (save-excursion - (move-to-column 0) - (point-marker)) - (line-end-position))) - (comint-send-string - process + (python-shell-send-string (format - "with open('%s') as __pyfile: exec(compile(__pyfile.read(), '%s', 'exec'))\n\n" - full-file-name full-file-name)))) + "__pyfile = open('%s'); exec(compile(__pyfile.read(), '%s', 'exec')); __pyfile.close()" + full-file-name full-file-name) + process))) (defun python-shell-switch-to-shell () "Switch to inferior Python process buffer." -- 2.39.2