aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorStefan Monnier2004-04-29 20:34:11 +0000
committerStefan Monnier2004-04-29 20:34:11 +0000
commit56e6d6feccdaeed52524238d2e159a3a26ac9ce6 (patch)
tree9cf0b93b1b4d9d10475d4151a7dadeb4015cb5b3 /lisp/progmodes/python.el
parent7d5f942b02c4806e4d68c3764dbfd6d04c7c1624 (diff)
downloademacs-56e6d6feccdaeed52524238d2e159a3a26ac9ce6.tar.gz
emacs-56e6d6feccdaeed52524238d2e159a3a26ac9ce6.zip
(python-send-command): New fun.
(python-send-region, python-load-file): Use it.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el45
1 files changed, 21 insertions, 24 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index a85cd2296ae..9eaba9027b8 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1141,6 +1141,14 @@ def _emacs_args (name): # get arglist of name for eldoc &c
1141print '_emacs_ok'")) 1141print '_emacs_ok'"))
1142 (unless noshow (pop-to-buffer (setq python-buffer "*Python*")))) 1142 (unless noshow (pop-to-buffer (setq python-buffer "*Python*"))))
1143 1143
1144(defun python-send-command (command)
1145 "Like `python-send-string' but resets `compilation-minor-mode'."
1146 (let ((end (marker-position (process-mark (python-proc)))))
1147 (compilation-forget-errors)
1148 (python-send-string command)
1149 (set-marker compilation-parsing-end end)
1150 (setq compilation-last-buffer (current-buffer))))
1151
1144(defun python-send-region (start end) 1152(defun python-send-region (start end)
1145 "Send the region to the inferior Python process." 1153 "Send the region to the inferior Python process."
1146 ;; The region is evaluated from a temporary file. This avoids 1154 ;; The region is evaluated from a temporary file. This avoids
@@ -1170,14 +1178,11 @@ print '_emacs_ok'"))
1170 (write-region start end f t 'nomsg) 1178 (write-region start end f t 'nomsg)
1171 (when python-buffer 1179 (when python-buffer
1172 (with-current-buffer python-buffer 1180 (with-current-buffer python-buffer
1173 (let ((end (marker-position (process-mark (python-proc))))) 1181 (set (make-local-variable 'python-orig-start) orig-start)
1174 (set (make-local-variable 'python-orig-start) orig-start) 1182 (let ((comint-input-filter-functions
1175 (set (make-local-variable 'compilation-error-list) nil) 1183 ;; Don't reset python-orig-start.
1176 (let ((comint-input-filter-functions 1184 (remq 'python-input-filter comint-input-filter-functions)))
1177 (delete 'python-input-filter comint-input-filter-functions))) 1185 (python-send-command command))))))
1178 (python-send-string command))
1179 (set-marker compilation-parsing-end end)
1180 (setq compilation-last-buffer (current-buffer)))))))
1181 1186
1182(defun python-send-string (string) 1187(defun python-send-string (string)
1183 "Evaluate STRING in inferior Python process." 1188 "Evaluate STRING in inferior Python process."
@@ -1242,25 +1247,17 @@ module-qualified names."
1242 (file-name-nondirectory file-name))) 1247 (file-name-nondirectory file-name)))
1243 (when python-buffer 1248 (when python-buffer
1244 (with-current-buffer python-buffer 1249 (with-current-buffer python-buffer
1245 (let ((end (marker-position (process-mark (python-proc))))) 1250 ;; Fixme: I'm not convinced by this logic from python-mode.el.
1246 (set (make-local-variable 'compilation-error-list) nil) 1251 (python-send-command
1247 ;; (set (make-local-variable 'compilation-old-error-list) nil) 1252 (if (string-match "\\.py\\'" file-name)
1248 (let ((comint-input-filter-functions 1253 ;; Fixme: make sure the directory is in the path list
1249 (delete 'python-input-filter comint-input-filter-functions))) 1254 (let ((module (file-name-sans-extension
1250 (set (make-local-variable 'python-orig-start) nil) 1255 (file-name-nondirectory file-name))))
1251 ;; Fixme: I'm not convinced by this logic from python-mode.el. 1256 (format "\
1252 (python-send-string
1253 (if (string-match "\\.py\\'" file-name)
1254 ;; Fixme: make sure the directory is in the path list
1255 (let ((module (file-name-sans-extension
1256 (file-name-nondirectory file-name))))
1257 (format "\
1258if globals().has_key(%S): reload(%s) 1257if globals().has_key(%S): reload(%s)
1259else: import %s 1258else: import %s
1260" module module module)) 1259" module module module))
1261 (format "execfile('%s')" file-name)))) 1260 (format "execfile('%s')" file-name))))))
1262 (set-marker compilation-parsing-end end)
1263 (setq compilation-last-buffer (current-buffer))))))
1264 1261
1265;; Fixme: Should this start a process if there isn't one? (Unlike cmuscheme.) 1262;; Fixme: Should this start a process if there isn't one? (Unlike cmuscheme.)
1266(defun python-proc () 1263(defun python-proc ()