Mercurial > emacs
comparison lisp/progmodes/python.el @ 90599:c358d0861b16
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 414-422)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 128-130)
- Update from CVS
- Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-108
| author | Miles Bader <miles@gnu.org> |
|---|---|
| date | Tue, 05 Sep 2006 02:54:22 +0000 |
| parents | 6823a91487f2 a9874901ba07 |
| children | a1a25ac6c88a |
comparison
equal
deleted
inserted
replaced
| 90598:4a8681a3d827 | 90599:c358d0861b16 |
|---|---|
| 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) | |
| 1377 (with-current-buffer python-buffer | |
| 1378 (setq compilation-last-buffer (current-buffer))) | |
| 1379 ;; No idea what this is for but it breaks the call to | |
| 1380 ;; compilation-fake-loc in python-send-region. -- Stef | |
| 1376 ;; Must wait until this has completed before re-setting variables below. | 1381 ;; Must wait until this has completed before re-setting variables below. |
| 1377 (python-send-receive (concat command "; print '_emacs_out ()'")) | 1382 ;; (python-send-receive "print '_emacs_out ()'") |
| 1378 (with-current-buffer python-buffer | 1383 ;; (with-current-buffer python-buffer |
| 1379 (set-marker compilation-parsing-end end) | 1384 ;; (set-marker compilation-parsing-end end)) |
| 1380 (setq compilation-last-buffer (current-buffer))))) | 1385 ) ;;) |
| 1381 | 1386 |
| 1382 (defun python-send-region (start end) | 1387 (defun python-send-region (start end) |
| 1383 "Send the region to the inferior Python process." | 1388 "Send the region to the inferior Python process." |
| 1384 ;; The region is evaluated from a temporary file. This avoids | 1389 ;; The region is evaluated from a temporary file. This avoids |
| 1385 ;; problems with blank lines, which have different semantics | 1390 ;; problems with blank lines, which have different semantics |
| 1592 "`eldoc-print-current-symbol-info' for Python. | 1597 "`eldoc-print-current-symbol-info' for Python. |
| 1593 Only works when point is in a function name, not its arg list, for | 1598 Only works when point is in a function name, not its arg list, for |
| 1594 instance. Assumes an inferior Python is running." | 1599 instance. Assumes an inferior Python is running." |
| 1595 (let ((symbol (with-syntax-table python-dotty-syntax-table | 1600 (let ((symbol (with-syntax-table python-dotty-syntax-table |
| 1596 (current-word)))) | 1601 (current-word)))) |
| 1597 ;; First try the symbol we're on. | 1602 ;; This is run from timers, so inhibit-quit tends to be set. |
| 1598 (or (and symbol | 1603 (with-local-quit |
| 1599 (python-send-receive (format "emacs.eargs(%S, %s)" | 1604 ;; First try the symbol we're on. |
| 1600 symbol python-imports))) | 1605 (or (and symbol |
| 1601 ;; Try moving to symbol before enclosing parens. | 1606 (python-send-receive (format "emacs.eargs(%S, %s)" |
| 1602 (let ((s (syntax-ppss))) | 1607 symbol python-imports))) |
| 1603 (unless (zerop (car s)) | 1608 ;; Try moving to symbol before enclosing parens. |
| 1604 (when (eq ?\( (char-after (nth 1 s))) | 1609 (let ((s (syntax-ppss))) |
| 1605 (save-excursion | 1610 (unless (zerop (car s)) |
| 1606 (goto-char (nth 1 s)) | 1611 (when (eq ?\( (char-after (nth 1 s))) |
| 1607 (skip-syntax-backward "-") | 1612 (save-excursion |
| 1608 (let ((point (point))) | 1613 (goto-char (nth 1 s)) |
| 1609 (skip-chars-backward "a-zA-Z._") | 1614 (skip-syntax-backward "-") |
| 1610 (if (< (point) point) | 1615 (let ((point (point))) |
| 1611 (python-send-receive | 1616 (skip-chars-backward "a-zA-Z._") |
| 1612 (format "emacs.eargs(%S, %s)" | 1617 (if (< (point) point) |
| 1613 (buffer-substring-no-properties (point) point) | 1618 (python-send-receive |
| 1614 python-imports))))))))))) | 1619 (format "emacs.eargs(%S, %s)" |
| 1620 (buffer-substring-no-properties (point) point) | |
| 1621 python-imports)))))))))))) | |
| 1615 | 1622 |
| 1616 ;;;; Info-look functionality. | 1623 ;;;; Info-look functionality. |
| 1617 | 1624 |
| 1618 (defun python-after-info-look () | 1625 (defun python-after-info-look () |
| 1619 "Set up info-look for Python. | 1626 "Set up info-look for Python. |
