Mercurial > emacs
comparison lisp/progmodes/python.el @ 72567:b562a18db094
(python-send-command): Simplify.
(run-python): Don't generate a new buffer unless `new' was specified.
Make sure we send `import emacs' to the proper process.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Mon, 28 Aug 2006 21:58:27 +0000 |
| parents | 41f22ed02e75 |
| children | a9874901ba07 |
comparison
equal
deleted
inserted
replaced
| 72566:41f22ed02e75 | 72567:b562a18db094 |
|---|---|
| 1328 (setq python-command cmd) | 1328 (setq python-command cmd) |
| 1329 ;; Fixme: Consider making `python-buffer' buffer-local as a buffer | 1329 ;; Fixme: Consider making `python-buffer' buffer-local as a buffer |
| 1330 ;; (not a name) in Python buffers from which `run-python' &c is | 1330 ;; (not a name) in Python buffers from which `run-python' &c is |
| 1331 ;; invoked. Would support multiple processes better. | 1331 ;; invoked. Would support multiple processes better. |
| 1332 (when (or new (not (comint-check-proc python-buffer))) | 1332 (when (or new (not (comint-check-proc python-buffer))) |
| 1333 (save-current-buffer | 1333 (with-current-buffer |
| 1334 (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) | 1334 (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) |
| 1335 (path (getenv "PYTHONPATH")) | 1335 (path (getenv "PYTHONPATH")) |
| 1336 (process-environment ; to import emacs.py | 1336 (process-environment ; to import emacs.py |
| 1337 (cons (concat "PYTHONPATH=" data-directory | 1337 (cons (concat "PYTHONPATH=" data-directory |
| 1338 (if path (concat ":" path))) | 1338 (if path (concat ":" path))) |
| 1339 process-environment))) | 1339 process-environment))) |
| 1340 (set-buffer (apply 'make-comint-in-buffer "Python" | 1340 (apply 'make-comint-in-buffer "Python" |
| 1341 (generate-new-buffer "*Python*") | 1341 (if new (generate-new-buffer "*Python*") "*Python*") |
| 1342 (car cmdlist) nil (cdr cmdlist))) | 1342 (car cmdlist) nil (cdr cmdlist))) |
| 1343 (setq-default python-buffer (current-buffer)) | 1343 (setq-default python-buffer (current-buffer)) |
| 1344 (setq python-buffer (current-buffer))) | 1344 (setq python-buffer (current-buffer)) |
| 1345 (accept-process-output (get-buffer-process python-buffer) 5) | 1345 (accept-process-output (get-buffer-process python-buffer) 5) |
| 1346 (inferior-python-mode))) | 1346 (inferior-python-mode) |
| 1347 ;; Load function definitions we need. | |
| 1348 ;; Before the preoutput function was used, this was done via -c in | |
| 1349 ;; cmdlist, but that loses the banner and doesn't run the startup | |
| 1350 ;; file. The code might be inline here, but there's enough that it | |
| 1351 ;; seems worth putting in a separate file, and it's probably cleaner | |
| 1352 ;; to put it in a module. | |
| 1353 ;; Ensure we're at a prompt before doing anything else. | |
| 1354 (python-send-receive "import emacs; print '_emacs_out ()'"))) | |
| 1347 (if (derived-mode-p 'python-mode) | 1355 (if (derived-mode-p 'python-mode) |
| 1348 (setq python-buffer (default-value 'python-buffer))) ; buffer-local | 1356 (setq python-buffer (default-value 'python-buffer))) ; buffer-local |
| 1349 ;; Load function definitions we need. | |
| 1350 ;; Before the preoutput function was used, this was done via -c in | |
| 1351 ;; cmdlist, but that loses the banner and doesn't run the startup | |
| 1352 ;; file. The code might be inline here, but there's enough that it | |
| 1353 ;; seems worth putting in a separate file, and it's probably cleaner | |
| 1354 ;; to put it in a module. | |
| 1355 ;; Ensure we're at a prompt before doing anything else. | |
| 1356 (python-send-receive "import emacs; print '_emacs_out ()'") | |
| 1357 ;; Without this, help output goes into the inferior python buffer if | 1357 ;; Without this, help output goes into the inferior python buffer if |
| 1358 ;; the process isn't already running. | 1358 ;; the process isn't already running. |
| 1359 (sit-for 1 t) ;Should we use accept-process-output instead? --Stef | 1359 (sit-for 1 t) ;Should we use accept-process-output instead? --Stef |
| 1360 (unless noshow (pop-to-buffer python-buffer t))) | 1360 (unless noshow (pop-to-buffer python-buffer t))) |
| 1361 | 1361 |
| 1367 ;; commands having set up such a state. | 1367 ;; commands having set up such a state. |
| 1368 | 1368 |
| 1369 (defun python-send-command (command) | 1369 (defun python-send-command (command) |
| 1370 "Like `python-send-string' but resets `compilation-shell-minor-mode'. | 1370 "Like `python-send-string' but resets `compilation-shell-minor-mode'. |
| 1371 COMMAND should be a single statement." | 1371 COMMAND should be a single statement." |
| 1372 (assert (not (string-match "\n" command))) | 1372 ;; (assert (not (string-match "\n" command))) |
| 1373 (let ((end (marker-position (process-mark (python-proc))))) | 1373 ;; (let ((end (marker-position (process-mark (python-proc))))) |
| 1374 (with-current-buffer python-buffer (goto-char (point-max))) | 1374 (with-current-buffer python-buffer (goto-char (point-max))) |
| 1375 (compilation-forget-errors) | 1375 (compilation-forget-errors) |
| 1376 (python-send-string command) | 1376 (python-send-string command) |
| 1377 (with-current-buffer python-buffer | 1377 (with-current-buffer python-buffer |
| 1378 (setq compilation-last-buffer (current-buffer))) | 1378 (setq compilation-last-buffer (current-buffer))) |
| 1380 ;; compilation-fake-loc in python-send-region. -- Stef | 1380 ;; compilation-fake-loc in python-send-region. -- Stef |
| 1381 ;; Must wait until this has completed before re-setting variables below. | 1381 ;; Must wait until this has completed before re-setting variables below. |
| 1382 ;; (python-send-receive "print '_emacs_out ()'") | 1382 ;; (python-send-receive "print '_emacs_out ()'") |
| 1383 ;; (with-current-buffer python-buffer | 1383 ;; (with-current-buffer python-buffer |
| 1384 ;; (set-marker compilation-parsing-end end)) | 1384 ;; (set-marker compilation-parsing-end end)) |
| 1385 )) | 1385 ) ;;) |
| 1386 | 1386 |
| 1387 (defun python-send-region (start end) | 1387 (defun python-send-region (start end) |
| 1388 "Send the region to the inferior Python process." | 1388 "Send the region to the inferior Python process." |
| 1389 ;; The region is evaluated from a temporary file. This avoids | 1389 ;; The region is evaluated from a temporary file. This avoids |
| 1390 ;; problems with blank lines, which have different semantics | 1390 ;; problems with blank lines, which have different semantics |
