diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 39 |
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?. | ||
| 1829 | When non-nil, this may prevent delayed and missing output in the | ||
| 1830 | Python 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. |
| 1829 | This variable follows the same rules as `process-environment' | 1837 | This 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__ |
| 2853 | except ImportError: | 2863 | except ImportError: |
| 2864 | # Python 3 | ||
| 2865 | import builtins as __builtin__ | ||
| 2866 | try: | ||
| 2867 | import readline, rlcompleter | ||
| 2868 | except: | ||
| 2854 | def __PYTHON_EL_get_completions(text): | 2869 | def __PYTHON_EL_get_completions(text): |
| 2855 | return [] | 2870 | return [] |
| 2856 | else: | 2871 | else: |
| 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 |