mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
Add simple PYTHONSTARTUP file
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
from os import path
|
||||||
|
print(path.join(path.dirname(path.abspath(__file__)), 'replstartup.py'))
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"""
|
||||||
|
``PYTHONSTARTUP`` to use Jedi in your Python interpreter.
|
||||||
|
|
||||||
|
To use Jedi completion in Python interpreter, add the following in your shell
|
||||||
|
setup (e.g., ``.bashrc``)::
|
||||||
|
|
||||||
|
export PYTHONSTARTUP="$(python -m jedi)"
|
||||||
|
|
||||||
|
Then you will be able to use Jedi completer in your Python interpreter::
|
||||||
|
|
||||||
|
$ python
|
||||||
|
Python 2.7.2+ (default, Jul 20 2012, 22:15:08)
|
||||||
|
[GCC 4.6.1] on linux2
|
||||||
|
Type "help", "copyright", "credits" or "license" for more information.
|
||||||
|
>>> import os
|
||||||
|
>>> os.path.join().split().in<TAB> # doctest: +SKIP
|
||||||
|
os.path.join().split().index os.path.join().split().insert
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import jedi.utils
|
||||||
|
jedi.utils.setup_readline()
|
||||||
|
del jedi
|
||||||
|
# Note: try not to do many things here, as it will contaminate global
|
||||||
|
# namespace of the interpreter.
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
Utilities for end-users.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from jedi import Interpreter
|
||||||
|
|
||||||
|
|
||||||
|
def readline_complete(text, state):
|
||||||
|
"""
|
||||||
|
Function to be passed to :func:`readline.set_completer`.
|
||||||
|
|
||||||
|
Usage::
|
||||||
|
|
||||||
|
import readline
|
||||||
|
readline.set_completer(readline_complete)
|
||||||
|
|
||||||
|
"""
|
||||||
|
ns = vars(sys.modules['__main__'])
|
||||||
|
completions = Interpreter(text, [ns]).completions()
|
||||||
|
try:
|
||||||
|
return text + completions[state].complete
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def setup_readline():
|
||||||
|
"""
|
||||||
|
Install Jedi completer to :mod:`readline`.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
import readline
|
||||||
|
except ImportError:
|
||||||
|
print("Module readline not available.")
|
||||||
|
else:
|
||||||
|
readline.set_completer(readline_complete)
|
||||||
|
readline.parse_and_bind("tab: complete")
|
||||||
|
|
||||||
|
# Default delimiters minus "()":
|
||||||
|
readline.set_completer_delims(' \t\n`~!@#$%^&*-=+[{]}\\|;:\'",<>/?')
|
||||||
Reference in New Issue
Block a user