Variable: python-shell-completion-setup-code
python-shell-completion-setup-code is a customizable variable defined
in python.el.gz.
Value
"\ndef __PYTHON_EL_get_completions(text):\n completions = []\n completer = None\n\n try:\n import readline\n\n try:\n import __builtin__\n except ImportError:\n # Python 3\n import builtins as __builtin__\n builtins = dir(__builtin__)\n\n is_ipython = ('__IPYTHON__' in builtins or\n '__IPYTHON__active' in builtins)\n splits = text.split()\n is_module = splits and splits[0] in ('from', 'import')\n\n if is_ipython and is_module:\n from IPython.core.completerlib import module_completion\n completions = module_completion(text.strip())\n elif is_ipython and '__IP' in builtins:\n completions = __IP.complete(text)\n elif is_ipython and 'get_ipython' in builtins:\n completions = get_ipython().Completer.all_completions(text)\n else:\n # Try to reuse current completer.\n completer = readline.get_completer()\n if not completer:\n # importing rlcompleter sets the completer, use it as a\n # last resort to avoid breaking customizations.\n import rlcompleter\n completer = readline.get_completer()\n if getattr(completer, 'PYTHON_EL_WRAPPED', False):\n completer.print_mode = False\n i = 0\n while True:\n completion = completer(text, i)\n if not completion:\n break\n i += 1\n completions.append(completion)\n except:\n pass\n finally:\n if getattr(completer, 'PYTHON_EL_WRAPPED', False):\n completer.print_mode = True\n return completions"
Documentation
Code used to setup completion in inferior Python processes.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
;;; Shell completion
(defcustom python-shell-completion-setup-code
"
def __PYTHON_EL_get_completions(text):
completions = []
completer = None
try:
import readline
try:
import __builtin__
except ImportError:
# Python 3
import builtins as __builtin__
builtins = dir(__builtin__)
is_ipython = ('__IPYTHON__' in builtins or
'__IPYTHON__active' in builtins)
splits = text.split()
is_module = splits and splits[0] in ('from', 'import')
if is_ipython and is_module:
from IPython.core.completerlib import module_completion
completions = module_completion(text.strip())
elif is_ipython and '__IP' in builtins:
completions = __IP.complete(text)
elif is_ipython and 'get_ipython' in builtins:
completions = get_ipython().Completer.all_completions(text)
else:
# Try to reuse current completer.
completer = readline.get_completer()
if not completer:
# importing rlcompleter sets the completer, use it as a
# last resort to avoid breaking customizations.
import rlcompleter
completer = readline.get_completer()
if getattr(completer, 'PYTHON_EL_WRAPPED', False):
completer.print_mode = False
i = 0
while True:
completion = completer(text, i)
if not completion:
break
i += 1
completions.append(completion)
except:
pass
finally:
if getattr(completer, 'PYTHON_EL_WRAPPED', False):
completer.print_mode = True
return completions"
"Code used to setup completion in inferior Python processes."
:type 'string)