diff options
| author | Stefan Monnier | 2004-11-22 05:52:39 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-11-22 05:52:39 +0000 |
| commit | abe0aa3e2a84edd77b72dac37f9ffae9901a7ae8 (patch) | |
| tree | cdc341a88dad7a00b26c50a136c2677903bb0157 /lisp/progmodes/python.el | |
| parent | 8dd989f6fca2586d024f9821225734008f4ced55 (diff) | |
| download | emacs-abe0aa3e2a84edd77b72dac37f9ffae9901a7ae8.tar.gz emacs-abe0aa3e2a84edd77b72dac37f9ffae9901a7ae8.zip | |
(run-python): Don't hard code *Python*. Don't modify process-environment.
(python-send-region, python-load-file): Don't assume that
python-buffer == (process-buffer (python-proc)).
(python-switch-to-python): Simplify.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 27126937c2e..835d633f292 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; python.el --- silly walks for Python | 1 | ;;; python.el --- silly walks for Python |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2003, 04 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Dave Love <fx@gnu.org> | 5 | ;; Author: Dave Love <fx@gnu.org> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -1127,7 +1127,7 @@ CMD is the Python command to run. NOSHOW non-nil means don't show the | |||
| 1127 | buffer automatically. | 1127 | buffer automatically. |
| 1128 | If there is a process already running in `*Python*', switch to | 1128 | If there is a process already running in `*Python*', switch to |
| 1129 | that buffer. Interactively, a prefix arg allows you to edit the initial | 1129 | that buffer. Interactively, a prefix arg allows you to edit the initial |
| 1130 | command line (default is `python-command'); `-i' etc. args will be added | 1130 | command line (default is `python-command'); `-i' etc. args will be added |
| 1131 | to this as appropriate. Runs the hook `inferior-python-mode-hook' | 1131 | to this as appropriate. Runs the hook `inferior-python-mode-hook' |
| 1132 | \(after the `comint-mode-hook' is run). | 1132 | \(after the `comint-mode-hook' is run). |
| 1133 | \(Type \\[describe-mode] in the process buffer for a list of commands.)" | 1133 | \(Type \\[describe-mode] in the process buffer for a list of commands.)" |
| @@ -1143,12 +1143,12 @@ to this as appropriate. Runs the hook `inferior-python-mode-hook' | |||
| 1143 | (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) | 1143 | (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) |
| 1144 | (path (getenv "PYTHONPATH")) | 1144 | (path (getenv "PYTHONPATH")) |
| 1145 | (process-environment ; to import emacs.py | 1145 | (process-environment ; to import emacs.py |
| 1146 | (push (concat "PYTHONPATH=" data-directory | 1146 | (cons (concat "PYTHONPATH=" data-directory |
| 1147 | (if path (concat ":" path))) | 1147 | (if path (concat ":" path))) |
| 1148 | process-environment))) | 1148 | process-environment))) |
| 1149 | (set-buffer (apply 'make-comint "Python" (car cmdlist) nil | 1149 | (set-buffer (apply 'make-comint "Python" (car cmdlist) nil |
| 1150 | (cdr cmdlist))) | 1150 | (cdr cmdlist))) |
| 1151 | (setq python-buffer "*Python*")) | 1151 | (setq python-buffer (buffer-name))) |
| 1152 | (inferior-python-mode) | 1152 | (inferior-python-mode) |
| 1153 | ;; Load function defintions we need. | 1153 | ;; Load function defintions we need. |
| 1154 | ;; Before the preoutput function was used, this was done via -c in | 1154 | ;; Before the preoutput function was used, this was done via -c in |
| @@ -1204,13 +1204,12 @@ to this as appropriate. Runs the hook `inferior-python-mode-hook' | |||
| 1204 | (set-marker orig-start (line-beginning-position 0))) | 1204 | (set-marker orig-start (line-beginning-position 0))) |
| 1205 | (write-region "if True:\n" nil f nil 'nomsg)) | 1205 | (write-region "if True:\n" nil f nil 'nomsg)) |
| 1206 | (write-region start end f t 'nomsg) | 1206 | (write-region start end f t 'nomsg) |
| 1207 | (let ((proc (python-proc))) ;Make sure we're running a process. | 1207 | (with-current-buffer (process-buffer (python-proc)) ;Runs python if needed. |
| 1208 | (with-current-buffer python-buffer | 1208 | (python-send-command command) |
| 1209 | (python-send-command command) | 1209 | ;; Tell compile.el to redirect error locations in file `f' to |
| 1210 | ;; Tell compile.el to redirect error locations in file `f' to | 1210 | ;; positions past marker `orig-start'. It has to be done *after* |
| 1211 | ;; positions past marker `orig-start'. It has to be done *after* | 1211 | ;; python-send-command's call to compilation-forget-errors. |
| 1212 | ;; python-send-command's call to compilation-forget-errors. | 1212 | (compilation-fake-loc orig-start f)))) |
| 1213 | (compilation-fake-loc orig-start f))))) | ||
| 1214 | 1213 | ||
| 1215 | (defun python-send-string (string) | 1214 | (defun python-send-string (string) |
| 1216 | "Evaluate STRING in inferior Python process." | 1215 | "Evaluate STRING in inferior Python process." |
| @@ -1235,13 +1234,7 @@ to this as appropriate. Runs the hook `inferior-python-mode-hook' | |||
| 1235 | "Switch to the Python process buffer. | 1234 | "Switch to the Python process buffer. |
| 1236 | With prefix arg, position cursor at end of buffer." | 1235 | With prefix arg, position cursor at end of buffer." |
| 1237 | (interactive "P") | 1236 | (interactive "P") |
| 1238 | ;; Start python unless we have a buffer. | 1237 | (pop-to-buffer (process-buffer (python-proc))) ;Runs python if needed. |
| 1239 | (unless (and python-buffer | ||
| 1240 | (get-buffer python-buffer)) | ||
| 1241 | (run-python nil t)) | ||
| 1242 | (pop-to-buffer python-buffer) | ||
| 1243 | ;; Make extra sure python is running in this buffer. | ||
| 1244 | (python-proc) | ||
| 1245 | (when eob-p | 1238 | (when eob-p |
| 1246 | (push-mark) | 1239 | (push-mark) |
| 1247 | (goto-char (point-max)))) | 1240 | (goto-char (point-max)))) |
| @@ -1277,17 +1270,16 @@ module-qualified names." | |||
| 1277 | (comint-check-source file-name) ; Check to see if buffer needs saving. | 1270 | (comint-check-source file-name) ; Check to see if buffer needs saving. |
| 1278 | (setq python-prev-dir/file (cons (file-name-directory file-name) | 1271 | (setq python-prev-dir/file (cons (file-name-directory file-name) |
| 1279 | (file-name-nondirectory file-name))) | 1272 | (file-name-nondirectory file-name))) |
| 1280 | (let ((proc (python-proc))) ;Make sure we have a process. | 1273 | (with-current-buffer (process-buffer (python-proc)) ;Runs python if needed. |
| 1281 | (with-current-buffer python-buffer | 1274 | ;; Fixme: I'm not convinced by this logic from python-mode.el. |
| 1282 | ;; Fixme: I'm not convinced by this logic from python-mode.el. | 1275 | (python-send-command |
| 1283 | (python-send-command | 1276 | (if (string-match "\\.py\\'" file-name) |
| 1284 | (if (string-match "\\.py\\'" file-name) | 1277 | (let ((module (file-name-sans-extension |
| 1285 | (let ((module (file-name-sans-extension | 1278 | (file-name-nondirectory file-name)))) |
| 1286 | (file-name-nondirectory file-name)))) | 1279 | (format "emacs.eimport(%S,%S)" |
| 1287 | (format "emacs.eimport(%S,%S)" | 1280 | module (file-name-directory file-name))) |
| 1288 | module (file-name-directory file-name))) | 1281 | (format "execfile(%S)" file-name))) |
| 1289 | (format "execfile(%S)" file-name))) | 1282 | (message "%s loaded" file-name))) |
| 1290 | (message "%s loaded" file-name)))) | ||
| 1291 | 1283 | ||
| 1292 | ;; Fixme: If we need to start the process, wait until we've got the OK | 1284 | ;; Fixme: If we need to start the process, wait until we've got the OK |
| 1293 | ;; from the startup. | 1285 | ;; from the startup. |