diff options
| author | Karoly Lorentey | 2006-10-14 17:36:28 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2006-10-14 17:36:28 +0000 |
| commit | 12b6af5c7ed2cfdb9783312bf890cf1e6c80c67a (patch) | |
| tree | 1775f9fd1c92defd8b61304a08ec00da95bc4539 /lisp/progmodes/python.el | |
| parent | 3f87f67ee215ffeecbd2f53bd7f342cdf03f47df (diff) | |
| parent | f763da8d0808af7c80d72bc586bf4fcf50b37ddd (diff) | |
| download | emacs-12b6af5c7ed2cfdb9783312bf890cf1e6c80c67a.tar.gz emacs-12b6af5c7ed2cfdb9783312bf890cf1e6c80c67a.zip | |
Merged from emacs@sv.gnu.org
Patches applied:
* emacs@sv.gnu.org/emacs--devo--0--patch-413
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-414
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-415
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-416
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-417
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-418
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-419
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-420
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-421
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-422
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-423
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-424
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-425
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-426
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-427
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-428
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-429
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-430
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-431
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-432
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-433
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-434
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-435
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-436
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-437
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-438
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-439
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-440
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-441
lisp/url/url-methods.el: Fix format error when http_proxy is empty string
* emacs@sv.gnu.org/emacs--devo--0--patch-442
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-443
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-444
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-445
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-446
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-447
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-448
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-449
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-450
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-451
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-452
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-453
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-454
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-455
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-456
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-457
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-458
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-459
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-460
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-461
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-462
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-463
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-464
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-465
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-466
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-467
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-468
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-469
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-470
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-471
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-472
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-473
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-128
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-129
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-130
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-131
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-132
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-133
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-134
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-135
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-136
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-137
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-138
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-139
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-140
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-141
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-142
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-143
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-144
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-145
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-146
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-147
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-148
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-149
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-582
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 118 |
1 files changed, 65 insertions, 53 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index c38a6e82f83..0387c05134e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -67,7 +67,8 @@ | |||
| 67 | (eval-when-compile | 67 | (eval-when-compile |
| 68 | (require 'cl) | 68 | (require 'cl) |
| 69 | (require 'compile) | 69 | (require 'compile) |
| 70 | (require 'comint)) | 70 | (require 'comint) |
| 71 | (require 'hippie-exp)) | ||
| 71 | 72 | ||
| 72 | (autoload 'comint-mode "comint") | 73 | (autoload 'comint-mode "comint") |
| 73 | 74 | ||
| @@ -95,7 +96,9 @@ | |||
| 95 | "import" "in" "is" "lambda" "not" "or" "pass" "print" | 96 | "import" "in" "is" "lambda" "not" "or" "pass" "print" |
| 96 | "raise" "return" "try" "while" "yield" | 97 | "raise" "return" "try" "while" "yield" |
| 97 | ;; Future keywords | 98 | ;; Future keywords |
| 98 | "as" "None") | 99 | "as" "None" |
| 100 | ;; Not real keywords, but close enough to be fontified as such | ||
| 101 | "self" "True" "False") | ||
| 99 | symbol-end) | 102 | symbol-end) |
| 100 | ;; Definitions | 103 | ;; Definitions |
| 101 | (,(rx symbol-start (group "class") (1+ space) (group (1+ (or word ?_)))) | 104 | (,(rx symbol-start (group "class") (1+ space) (group (1+ (or word ?_)))) |
| @@ -1286,7 +1289,7 @@ Don't save anything for STR matching `inferior-python-filter-regexp'." | |||
| 1286 | ;; Maybe we could be more selective here. | 1289 | ;; Maybe we could be more selective here. |
| 1287 | (if (zerop (length res)) | 1290 | (if (zerop (length res)) |
| 1288 | (not (bolp)) | 1291 | (not (bolp)) |
| 1289 | (string-match res ".\\'")))) | 1292 | (string-match ".\\'" res)))) |
| 1290 | ;; The need for this seems to be system-dependent: | 1293 | ;; The need for this seems to be system-dependent: |
| 1291 | ;; What is this all about, exactly? --Stef | 1294 | ;; What is this all about, exactly? --Stef |
| 1292 | ;; (if (and (eq ?. (aref s 0))) | 1295 | ;; (if (and (eq ?. (aref s 0))) |
| @@ -1330,30 +1333,30 @@ buffer for a list of commands.)" | |||
| 1330 | ;; (not a name) in Python buffers from which `run-python' &c is | 1333 | ;; (not a name) in Python buffers from which `run-python' &c is |
| 1331 | ;; invoked. Would support multiple processes better. | 1334 | ;; invoked. Would support multiple processes better. |
| 1332 | (when (or new (not (comint-check-proc python-buffer))) | 1335 | (when (or new (not (comint-check-proc python-buffer))) |
| 1333 | (save-current-buffer | 1336 | (with-current-buffer |
| 1334 | (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) | 1337 | (let* ((cmdlist (append (python-args-to-list cmd) '("-i"))) |
| 1335 | (path (getenv "PYTHONPATH")) | 1338 | (path (getenv "PYTHONPATH")) |
| 1336 | (process-environment ; to import emacs.py | 1339 | (process-environment ; to import emacs.py |
| 1337 | (cons (concat "PYTHONPATH=" data-directory | 1340 | (cons (concat "PYTHONPATH=" data-directory |
| 1338 | (if path (concat ":" path))) | 1341 | (if path (concat ":" path))) |
| 1339 | process-environment))) | 1342 | process-environment))) |
| 1340 | (set-buffer (apply 'make-comint-in-buffer "Python" | 1343 | (apply 'make-comint-in-buffer "Python" |
| 1341 | (generate-new-buffer "*Python*") | 1344 | (if new (generate-new-buffer "*Python*") "*Python*") |
| 1342 | (car cmdlist) nil (cdr cmdlist))) | 1345 | (car cmdlist) nil (cdr cmdlist))) |
| 1343 | (setq-default python-buffer (current-buffer)) | 1346 | (setq-default python-buffer (current-buffer)) |
| 1344 | (setq python-buffer (current-buffer))) | 1347 | (setq python-buffer (current-buffer)) |
| 1345 | (accept-process-output (get-buffer-process python-buffer) 5) | 1348 | (accept-process-output (get-buffer-process python-buffer) 5) |
| 1346 | (inferior-python-mode))) | 1349 | (inferior-python-mode) |
| 1350 | ;; Load function definitions we need. | ||
| 1351 | ;; Before the preoutput function was used, this was done via -c in | ||
| 1352 | ;; cmdlist, but that loses the banner and doesn't run the startup | ||
| 1353 | ;; file. The code might be inline here, but there's enough that it | ||
| 1354 | ;; seems worth putting in a separate file, and it's probably cleaner | ||
| 1355 | ;; to put it in a module. | ||
| 1356 | ;; Ensure we're at a prompt before doing anything else. | ||
| 1357 | (python-send-receive "import emacs; print '_emacs_out ()'"))) | ||
| 1347 | (if (derived-mode-p 'python-mode) | 1358 | (if (derived-mode-p 'python-mode) |
| 1348 | (setq python-buffer (default-value 'python-buffer))) ; buffer-local | 1359 | (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 | 1360 | ;; Without this, help output goes into the inferior python buffer if |
| 1358 | ;; the process isn't already running. | 1361 | ;; the process isn't already running. |
| 1359 | (sit-for 1 t) ;Should we use accept-process-output instead? --Stef | 1362 | (sit-for 1 t) ;Should we use accept-process-output instead? --Stef |
| @@ -1369,15 +1372,20 @@ buffer for a list of commands.)" | |||
| 1369 | (defun python-send-command (command) | 1372 | (defun python-send-command (command) |
| 1370 | "Like `python-send-string' but resets `compilation-shell-minor-mode'. | 1373 | "Like `python-send-string' but resets `compilation-shell-minor-mode'. |
| 1371 | COMMAND should be a single statement." | 1374 | COMMAND should be a single statement." |
| 1372 | (assert (not (string-match "\n" command))) | 1375 | ;; (assert (not (string-match "\n" command))) |
| 1373 | (let ((end (marker-position (process-mark (python-proc))))) | 1376 | ;; (let ((end (marker-position (process-mark (python-proc))))) |
| 1374 | (with-current-buffer python-buffer (goto-char (point-max))) | 1377 | (with-current-buffer python-buffer (goto-char (point-max))) |
| 1375 | (compilation-forget-errors) | 1378 | (compilation-forget-errors) |
| 1376 | ;; Must wait until this has completed before re-setting variables below. | 1379 | (python-send-string command) |
| 1377 | (python-send-receive (concat command "; print '_emacs_out ()'")) | ||
| 1378 | (with-current-buffer python-buffer | 1380 | (with-current-buffer python-buffer |
| 1379 | (set-marker compilation-parsing-end end) | 1381 | (setq compilation-last-buffer (current-buffer))) |
| 1380 | (setq compilation-last-buffer (current-buffer))))) | 1382 | ;; No idea what this is for but it breaks the call to |
| 1383 | ;; compilation-fake-loc in python-send-region. -- Stef | ||
| 1384 | ;; Must wait until this has completed before re-setting variables below. | ||
| 1385 | ;; (python-send-receive "print '_emacs_out ()'") | ||
| 1386 | ;; (with-current-buffer python-buffer | ||
| 1387 | ;; (set-marker compilation-parsing-end end)) | ||
| 1388 | ) ;;) | ||
| 1381 | 1389 | ||
| 1382 | (defun python-send-region (start end) | 1390 | (defun python-send-region (start end) |
| 1383 | "Send the region to the inferior Python process." | 1391 | "Send the region to the inferior Python process." |
| @@ -1419,11 +1427,13 @@ COMMAND should be a single statement." | |||
| 1419 | "Evaluate STRING in inferior Python process." | 1427 | "Evaluate STRING in inferior Python process." |
| 1420 | (interactive "sPython command: ") | 1428 | (interactive "sPython command: ") |
| 1421 | (comint-send-string (python-proc) string) | 1429 | (comint-send-string (python-proc) string) |
| 1422 | (comint-send-string (python-proc) | 1430 | (unless (string-match "\n\\'" string) |
| 1423 | ;; If the string is single-line or if it ends with \n, | 1431 | ;; Make sure the text is properly LF-terminated. |
| 1424 | ;; only add a single \n, otherwise add 2, so as to | 1432 | (comint-send-string (python-proc) "\n")) |
| 1425 | ;; make sure we terminate the multiline instruction. | 1433 | (when (string-match "\n[ \t].*\n?\\'" string) |
| 1426 | (if (string-match "\n.+\\'" string) "\n\n" "\n"))) | 1434 | ;; If the string contains a final indented line, add a second newline so |
| 1435 | ;; as to make sure we terminate the multiline instruction. | ||
| 1436 | (comint-send-string (python-proc) "\n"))) | ||
| 1427 | 1437 | ||
| 1428 | (defun python-send-buffer () | 1438 | (defun python-send-buffer () |
| 1429 | "Send the current buffer to the inferior Python process." | 1439 | "Send the current buffer to the inferior Python process." |
| @@ -1594,24 +1604,26 @@ Only works when point is in a function name, not its arg list, for | |||
| 1594 | instance. Assumes an inferior Python is running." | 1604 | instance. Assumes an inferior Python is running." |
| 1595 | (let ((symbol (with-syntax-table python-dotty-syntax-table | 1605 | (let ((symbol (with-syntax-table python-dotty-syntax-table |
| 1596 | (current-word)))) | 1606 | (current-word)))) |
| 1597 | ;; First try the symbol we're on. | 1607 | ;; This is run from timers, so inhibit-quit tends to be set. |
| 1598 | (or (and symbol | 1608 | (with-local-quit |
| 1599 | (python-send-receive (format "emacs.eargs(%S, %s)" | 1609 | ;; First try the symbol we're on. |
| 1600 | symbol python-imports))) | 1610 | (or (and symbol |
| 1601 | ;; Try moving to symbol before enclosing parens. | 1611 | (python-send-receive (format "emacs.eargs(%S, %s)" |
| 1602 | (let ((s (syntax-ppss))) | 1612 | symbol python-imports))) |
| 1603 | (unless (zerop (car s)) | 1613 | ;; Try moving to symbol before enclosing parens. |
| 1604 | (when (eq ?\( (char-after (nth 1 s))) | 1614 | (let ((s (syntax-ppss))) |
| 1605 | (save-excursion | 1615 | (unless (zerop (car s)) |
| 1606 | (goto-char (nth 1 s)) | 1616 | (when (eq ?\( (char-after (nth 1 s))) |
| 1607 | (skip-syntax-backward "-") | 1617 | (save-excursion |
| 1608 | (let ((point (point))) | 1618 | (goto-char (nth 1 s)) |
| 1609 | (skip-chars-backward "a-zA-Z._") | 1619 | (skip-syntax-backward "-") |
| 1610 | (if (< (point) point) | 1620 | (let ((point (point))) |
| 1611 | (python-send-receive | 1621 | (skip-chars-backward "a-zA-Z._") |
| 1612 | (format "emacs.eargs(%S, %s)" | 1622 | (if (< (point) point) |
| 1613 | (buffer-substring-no-properties (point) point) | 1623 | (python-send-receive |
| 1614 | python-imports))))))))))) | 1624 | (format "emacs.eargs(%S, %s)" |
| 1625 | (buffer-substring-no-properties (point) point) | ||
| 1626 | python-imports)))))))))))) | ||
| 1615 | 1627 | ||
| 1616 | ;;;; Info-look functionality. | 1628 | ;;;; Info-look functionality. |
| 1617 | 1629 | ||