mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-26 20:27:15 +08:00
Merge pull request #289 from asmeurer/pythonrc
Some fixes to the .pythonrc.py code
This commit is contained in:
@@ -14,13 +14,39 @@ def setup_readline():
|
|||||||
|
|
||||||
This function setups :mod:`readline` to use Jedi in Python interactive
|
This function setups :mod:`readline` to use Jedi in Python interactive
|
||||||
shell. If you want to use a custom ``PYTHONSTARTUP`` file (typically
|
shell. If you want to use a custom ``PYTHONSTARTUP`` file (typically
|
||||||
``$HOME/.pythonrc.py``), you can add this piece of code:
|
``$HOME/.pythonrc.py``), you can add this piece of code::
|
||||||
|
|
||||||
>>> try:
|
try:
|
||||||
... from jedi.utils import setup_readline
|
from jedi.utils import setup_readline
|
||||||
... setup_readline()
|
setup_readline()
|
||||||
... except ImportError:
|
except ImportError:
|
||||||
... print('Install Jedi with pip! No autocompletion otherwise.')
|
# Fallback to the stdlib readline completer if it is installed.
|
||||||
|
# Taken from http://docs.python.org/2/library/rlcompleter.html
|
||||||
|
print("Jedi is not installed, falling back to readline")
|
||||||
|
try:
|
||||||
|
import readline
|
||||||
|
import rlcompleter
|
||||||
|
readline.parse_and_bind("tab: complete")
|
||||||
|
except ImportError:
|
||||||
|
print("Readline is not installed either. No tab completion is enabled.")
|
||||||
|
|
||||||
|
This will fallback to the readline completer if Jedi is not installed.
|
||||||
|
The readline completer will only complete names in the global namespace,
|
||||||
|
so for example,
|
||||||
|
|
||||||
|
>>> ran<TAB> # doctest: +SKIP
|
||||||
|
|
||||||
|
will complete to ``range``
|
||||||
|
|
||||||
|
with both Jedi and readline, but
|
||||||
|
|
||||||
|
>>> range(10).cou<TAB> # doctest: +SKIP
|
||||||
|
|
||||||
|
will show complete to ``range(10).count`` only with Jedi.
|
||||||
|
|
||||||
|
You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to
|
||||||
|
your shell profile (usually ``.bash_profile`` or ``.profile`` if you use
|
||||||
|
bash).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user