aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorPaul Eggert2014-11-28 22:55:31 -0800
committerPaul Eggert2014-11-28 23:07:16 -0800
commit0cce3623b169732a51f055a86fc926313b11a5ee (patch)
tree17154977d6e77f604ede0b82f89b2aeb6925310a /lisp/progmodes/python.el
parent9875d23d86c0668b1e697b67a394560d66c7826d (diff)
parent6b765b8facbdbb03f28028007885236601652515 (diff)
downloademacs-0cce3623b169732a51f055a86fc926313b11a5ee.tar.gz
emacs-0cce3623b169732a51f055a86fc926313b11a5ee.zip
Merge branch 'emacs-24'.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el39
1 files changed, 27 insertions, 12 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9680a4aa9d5..b99e195f407 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -94,13 +94,13 @@
94;; python-shell-interpreter-args 94;; python-shell-interpreter-args
95;; "-i C:\\Python27\\Scripts\\ipython-script.py") 95;; "-i C:\\Python27\\Scripts\\ipython-script.py")
96 96
97;; If you are experiencing missing or delayed output in your shells, 97;; Missing or delayed output used to happen due to differences between
98;; that's likely caused by your Operating System's pipe buffering 98;; Operating Systems' pipe buffering (e.g. CPython 3.3.4 in Windows 7.
99;; (e.g. this is known to happen running CPython 3.3.4 in Windows 7.
100;; See URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17304'). To 99;; See URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17304'). To
101;; fix this, using CPython's "-u" commandline argument or setting the 100;; avoid this, the `python-shell-unbuffered' defaults to non-nil and
102;; "PYTHONUNBUFFERED" environment variable should help: See URL 101;; controls whether `python-shell-calculate-process-environment'
103;; `https://docs.python.org/3/using/cmdline.html#cmdoption-u'. 102;; should set the "PYTHONUNBUFFERED" environment variable on startup:
103;; See URL `https://docs.python.org/3/using/cmdline.html#cmdoption-u'.
104 104
105;; The interaction relies upon having prompts for input (e.g. ">>> " 105;; The interaction relies upon having prompts for input (e.g. ">>> "
106;; and "... " in standard Python shell) and output (e.g. "Out[1]: " in 106;; and "... " in standard Python shell) and output (e.g. "Out[1]: " in
@@ -1824,6 +1824,14 @@ Restart the Python shell after changing this variable for it to take effect."
1824 :group 'python 1824 :group 'python
1825 :safe 'booleanp) 1825 :safe 'booleanp)
1826 1826
1827(defcustom python-shell-unbuffered t
1828 "Should shell output be unbuffered?.
1829When non-nil, this may prevent delayed and missing output in the
1830Python shell. See commentary for details."
1831 :type 'boolean
1832 :group 'python
1833 :safe 'booleanp)
1834
1827(defcustom python-shell-process-environment nil 1835(defcustom python-shell-process-environment nil
1828 "List of environment variables for Python shell. 1836 "List of environment variables for Python shell.
1829This variable follows the same rules as `process-environment' 1837This variable follows the same rules as `process-environment'
@@ -2116,6 +2124,8 @@ uniqueness for different types of configurations."
2116 (virtualenv (if python-shell-virtualenv-root 2124 (virtualenv (if python-shell-virtualenv-root
2117 (directory-file-name python-shell-virtualenv-root) 2125 (directory-file-name python-shell-virtualenv-root)
2118 nil))) 2126 nil)))
2127 (when python-shell-unbuffered
2128 (setenv "PYTHONUNBUFFERED" "1"))
2119 (when python-shell-extra-pythonpaths 2129 (when python-shell-extra-pythonpaths
2120 (setenv "PYTHONPATH" (python-shell-calculate-pythonpath))) 2130 (setenv "PYTHONPATH" (python-shell-calculate-pythonpath)))
2121 (if (not virtualenv) 2131 (if (not virtualenv)
@@ -2849,25 +2859,30 @@ This function takes the list of setup code to send from the
2849 2859
2850(defcustom python-shell-completion-setup-code 2860(defcustom python-shell-completion-setup-code
2851 "try: 2861 "try:
2852 import readline, rlcompleter 2862 import __builtin__
2853except ImportError: 2863except ImportError:
2864 # Python 3
2865 import builtins as __builtin__
2866try:
2867 import readline, rlcompleter
2868except:
2854 def __PYTHON_EL_get_completions(text): 2869 def __PYTHON_EL_get_completions(text):
2855 return [] 2870 return []
2856else: 2871else:
2857 def __PYTHON_EL_get_completions(text): 2872 def __PYTHON_EL_get_completions(text):
2873 builtins = dir(__builtin__)
2858 completions = [] 2874 completions = []
2859 try: 2875 try:
2860 splits = text.split() 2876 splits = text.split()
2861 is_module = splits and splits[0] in ('from', 'import') 2877 is_module = splits and splits[0] in ('from', 'import')
2862 is_ipython = getattr( 2878 is_ipython = ('__IPYTHON__' in builtins or
2863 __builtins__, '__IPYTHON__', 2879 '__IPYTHON__active' in builtins)
2864 getattr(__builtins__, '__IPYTHON__active', False))
2865 if is_module: 2880 if is_module:
2866 from IPython.core.completerlib import module_completion 2881 from IPython.core.completerlib import module_completion
2867 completions = module_completion(text.strip()) 2882 completions = module_completion(text.strip())
2868 elif is_ipython and getattr(__builtins__, '__IP', None): 2883 elif is_ipython and '__IP' in builtins:
2869 completions = __IP.complete(text) 2884 completions = __IP.complete(text)
2870 elif is_ipython and getattr(__builtins__, 'get_ipython', None): 2885 elif is_ipython and 'get_ipython' in builtins:
2871 completions = get_ipython().Completer.all_completions(text) 2886 completions = get_ipython().Completer.all_completions(text)
2872 else: 2887 else:
2873 i = 0 2888 i = 0