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.el78
1 files changed, 46 insertions, 32 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4617ecc420d..f946509d6e0 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1354,14 +1354,6 @@ Restart the python shell after changing this variable for it to take effect."
1354 :group 'python 1354 :group 'python
1355 :safe 'booleanp) 1355 :safe 'booleanp)
1356 1356
1357(defcustom python-shell-send-setup-max-wait 5
1358 "Seconds to wait for process output before code setup.
1359If output is received before the specified time then control is
1360returned in that moment and not after waiting."
1361 :type 'integer
1362 :group 'python
1363 :safe 'integerp)
1364
1365(defcustom python-shell-process-environment nil 1357(defcustom python-shell-process-environment nil
1366 "List of environment variables for Python shell. 1358 "List of environment variables for Python shell.
1367This variable follows the same rules as `process-environment' 1359This variable follows the same rules as `process-environment'
@@ -1571,7 +1563,8 @@ non-nil the buffer is shown."
1571 (current-buffer (current-buffer))) 1563 (current-buffer (current-buffer)))
1572 (with-current-buffer buffer 1564 (with-current-buffer buffer
1573 (inferior-python-mode) 1565 (inferior-python-mode)
1574 (python-util-clone-local-variables current-buffer)))) 1566 (python-util-clone-local-variables current-buffer))
1567 (accept-process-output (get-buffer-process buffer))))
1575 (and pop (pop-to-buffer proc-buffer-name t)) 1568 (and pop (pop-to-buffer proc-buffer-name t))
1576 proc-buffer-name))) 1569 proc-buffer-name)))
1577 1570
@@ -1605,21 +1598,24 @@ process buffer for a list of commands.)"
1605 "Run an inferior Internal Python process. 1598 "Run an inferior Internal Python process.
1606Input and output via buffer named after 1599Input and output via buffer named after
1607`python-shell-internal-buffer-name' and what 1600`python-shell-internal-buffer-name' and what
1608`python-shell-internal-get-process-name' returns. This new kind 1601`python-shell-internal-get-process-name' returns.
1609of shell is intended to be used for generic communication related 1602
1610to defined configurations. The main difference with global or 1603This new kind of shell is intended to be used for generic
1611dedicated shells is that these ones are attached to a 1604communication related to defined configurations, the main
1612configuration, not a buffer. This means that can be used for 1605difference with global or dedicated shells is that these ones are
1613example to retrieve the sys.path and other stuff, without messing 1606attached to a configuration, not a buffer. This means that can
1614with user shells. Runs the hook 1607be used for example to retrieve the sys.path and other stuff,
1615`inferior-python-mode-hook' (after the `comint-mode-hook' is 1608without messing with user shells. Note that
1616run). \(Type \\[describe-mode] in the process buffer for a list 1609`python-shell-enable-font-lock' and `inferior-python-mode-hook'
1617of commands.)" 1610are set to nil for these shells, so setup codes are not sent at
1618 (set-process-query-on-exit-flag 1611startup."
1619 (get-buffer-process 1612 (let ((python-shell-enable-font-lock nil)
1620 (python-shell-make-comint 1613 (inferior-python-mode-hook nil))
1621 (python-shell-parse-command) 1614 (set-process-query-on-exit-flag
1622 (python-shell-internal-get-process-name))) nil)) 1615 (get-buffer-process
1616 (python-shell-make-comint
1617 (python-shell-parse-command)
1618 (python-shell-internal-get-process-name))) nil)))
1623 1619
1624(defun python-shell-get-process () 1620(defun python-shell-get-process ()
1625 "Get inferior Python process for current buffer and return it." 1621 "Get inferior Python process for current buffer and return it."
@@ -1657,12 +1653,25 @@ This is really not necessary at all for the code to work but it's
1657there for compatibility with CEDET.") 1653there for compatibility with CEDET.")
1658(make-variable-buffer-local 'python-shell-internal-buffer) 1654(make-variable-buffer-local 'python-shell-internal-buffer)
1659 1655
1656(defvar python-shell-internal-last-output nil
1657 "Last output captured by the internal shell.
1658This is really not necessary at all for the code to work but it's
1659there for compatibility with CEDET.")
1660(make-variable-buffer-local 'python-shell-internal-last-output)
1661
1660(defun python-shell-internal-get-or-create-process () 1662(defun python-shell-internal-get-or-create-process ()
1661 "Get or create an inferior Internal Python process." 1663 "Get or create an inferior Internal Python process."
1662 (let* ((proc-name (python-shell-internal-get-process-name)) 1664 (let* ((proc-name (python-shell-internal-get-process-name))
1663 (proc-buffer-name (format "*%s*" proc-name))) 1665 (proc-buffer-name (format "*%s*" proc-name)))
1664 (run-python-internal) 1666 (when (not (process-live-p proc-name))
1665 (setq python-shell-internal-buffer proc-buffer-name) 1667 (run-python-internal)
1668 (setq python-shell-internal-buffer proc-buffer-name)
1669 ;; XXX: Why is this `sit-for' needed?
1670 ;; `python-shell-make-comint' calls `accept-process-output'
1671 ;; already but it is not helping to get proper output on
1672 ;; 'gnu/linux when the internal shell process is not running and
1673 ;; a call to `python-shell-internal-send-string' is issued.
1674 (sit-for 0.1 t))
1666 (get-buffer-process proc-buffer-name))) 1675 (get-buffer-process proc-buffer-name)))
1667 1676
1668(define-obsolete-function-alias 1677(define-obsolete-function-alias
@@ -1671,6 +1680,9 @@ there for compatibility with CEDET.")
1671(define-obsolete-variable-alias 1680(define-obsolete-variable-alias
1672 'python-buffer 'python-shell-internal-buffer "24.2") 1681 'python-buffer 'python-shell-internal-buffer "24.2")
1673 1682
1683(define-obsolete-variable-alias
1684 'python-preoutput-result 'python-shell-internal-last-output "24.2")
1685
1674(defun python-shell-send-string (string &optional process msg) 1686(defun python-shell-send-string (string &optional process msg)
1675 "Send STRING to inferior Python PROCESS. 1687 "Send STRING to inferior Python PROCESS.
1676When MSG is non-nil messages the first line of STRING." 1688When MSG is non-nil messages the first line of STRING."
@@ -1722,11 +1734,14 @@ the output."
1722(defun python-shell-internal-send-string (string) 1734(defun python-shell-internal-send-string (string)
1723 "Send STRING to the Internal Python interpreter. 1735 "Send STRING to the Internal Python interpreter.
1724Returns the output. See `python-shell-send-string-no-output'." 1736Returns the output. See `python-shell-send-string-no-output'."
1725 (python-shell-send-string-no-output 1737 ;; XXX Remove `python-shell-internal-last-output' once CEDET is
1726 ;; Makes this function compatible with the old 1738 ;; updated to support this new mode.
1727 ;; python-send-receive. (At least for CEDET). 1739 (setq python-shell-internal-last-output
1728 (replace-regexp-in-string "_emacs_out +" "" string) 1740 (python-shell-send-string-no-output
1729 (python-shell-internal-get-or-create-process) nil)) 1741 ;; Makes this function compatible with the old
1742 ;; python-send-receive. (At least for CEDET).
1743 (replace-regexp-in-string "_emacs_out +" "" string)
1744 (python-shell-internal-get-or-create-process) nil)))
1730 1745
1731(define-obsolete-function-alias 1746(define-obsolete-function-alias
1732 'python-send-receive 'python-shell-internal-send-string "24.2") 1747 'python-send-receive 'python-shell-internal-send-string "24.2")
@@ -1807,7 +1822,6 @@ This function takes the list of setup code to send from the
1807`python-shell-setup-codes' list." 1822`python-shell-setup-codes' list."
1808 (let ((msg "Sent %s") 1823 (let ((msg "Sent %s")
1809 (process (get-buffer-process (current-buffer)))) 1824 (process (get-buffer-process (current-buffer))))
1810 (accept-process-output process python-shell-send-setup-max-wait)
1811 (dolist (code python-shell-setup-codes) 1825 (dolist (code python-shell-setup-codes)
1812 (when code 1826 (when code
1813 (message (format msg code)) 1827 (message (format msg code))