aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el97
1 files changed, 52 insertions, 45 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index c38a6e82f83..66d8cd4714f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1330,30 +1330,30 @@ buffer for a list of commands.)"
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
@@ -1369,15 +1369,20 @@ buffer for a list of commands.)"
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'.
1371COMMAND should be a single statement." 1371COMMAND 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 ;; Must wait until this has completed before re-setting variables below. 1376 (python-send-string command)
1377 (python-send-receive (concat command "; print '_emacs_out ()'"))
1378 (with-current-buffer python-buffer 1377 (with-current-buffer python-buffer
1379 (set-marker compilation-parsing-end end) 1378 (setq compilation-last-buffer (current-buffer)))
1380 (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
1381 ;; Must wait until this has completed before re-setting variables below.
1382 ;; (python-send-receive "print '_emacs_out ()'")
1383 ;; (with-current-buffer python-buffer
1384 ;; (set-marker compilation-parsing-end end))
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."
@@ -1594,24 +1599,26 @@ Only works when point is in a function name, not its arg list, for
1594instance. Assumes an inferior Python is running." 1599instance. 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