##// END OF EJS Templates
allow str_key in custom completer hooks. import completer.
vivainio -
Show More
@@ -42,6 +42,36 b' def apt_completers(self, event):'
42 # re_key specifies the regexp that triggers the specified completer
42 # re_key specifies the regexp that triggers the specified completer
43
43
44 ip.set_hook('complete_command', apt_completers, re_key = '.*apt-get')
44 ip.set_hook('complete_command', apt_completers, re_key = '.*apt-get')
45
46 ip.set_hook('complete_command', apt_completers, re_key = '.*yum')
45 ip.set_hook('complete_command', apt_completers, re_key = '.*yum')
47 No newline at end of file
46
47 py_std_modules = """\
48 BaseHTTPServer Bastion CGIHTTPServer ConfigParser Cookie
49 DocXMLRPCServer HTMLParser MimeWriter Queue SimpleHTTPServer
50 SimpleXMLRPCServer SocketServer StringIO UserDict UserList UserString
51 _LWPCookieJar _MozillaCookieJar __future__ __phello__.foo _strptime
52 _threading_local aifc anydbm asynchat asyncore atexit audiodev base64
53 bdb binhex bisect cProfile calendar cgi cgitb chunk cmd code codecs
54 codeop colorsys commands compileall contextlib cookielib copy copy_reg
55 csv dbhash decimal difflib dircache dis doctest dumbdbm dummy_thread
56 dummy_threading filecmp fileinput fnmatch formatter fpformat ftplib
57 functools getopt getpass gettext glob gopherlib gzip hashlib heapq
58 hmac htmlentitydefs htmllib httplib ihooks imaplib imghdr imputil
59 inspect keyword linecache locale macpath macurl2path mailbox mailcap
60 markupbase md5 mhlib mimetools mimetypes mimify modulefinder multifile
61 mutex netrc new nntplib ntpath nturl2path opcode optparse os
62 os2emxpath pdb pickle pickletools pipes pkgutil platform popen2 poplib
63 posixfile posixpath pprint profile pstats pty py_compile pyclbr pydoc
64 quopri random re repr rexec rfc822 rlcompleter robotparser runpy sched
65 sets sgmllib sha shelve shlex shutil site smtpd smtplib sndhdr socket
66 sre sre_compile sre_constants sre_parse stat statvfs string stringold
67 stringprep struct subprocess sunau sunaudio symbol symtable tabnanny
68 tarfile telnetlib tempfile textwrap this threading timeit toaiff token
69 tokenize trace traceback tty types unittest urllib urllib2 urlparse
70 user uu uuid warnings wave weakref webbrowser whichdb xdrlib xmllib
71 xmlrpclib zipfile"""
72
73 def module_completer(self,event):
74 """ Give completions after user has typed 'import' """
75 return py_std_modules.split()
76
77 ip.set_hook('complete_command', module_completer, str_key = 'import') No newline at end of file
@@ -72,6 +72,7 b' import re'
72 import shlex
72 import shlex
73 import sys
73 import sys
74 import IPython.rlineimpl as readline
74 import IPython.rlineimpl as readline
75 import itertools
75 from IPython.ipstruct import Struct
76 from IPython.ipstruct import Struct
76 from IPython import ipapi
77 from IPython import ipapi
77
78
@@ -534,8 +535,11 b' class IPCompleter(Completer):'
534 event = Struct()
535 event = Struct()
535 event.line = line
536 event.line = line
536 event.symbol = text
537 event.symbol = text
537 event.command = None
538 cmd = line.split(None,1)[0]
538 for c in self.custom_completers.flat_matches(self.lbuf):
539 event.command = cmd
540 for c in itertools.chain(
541 self.custom_completers.s_matches(cmd),
542 self.custom_completers.flat_matches(self.lbuf)):
539 # print "try",c # dbg
543 # print "try",c # dbg
540 try:
544 try:
541 res = c(event)
545 res = c(event)
@@ -37,6 +37,14 b' class StrDispatch(object):'
37
37
38 def __repr__(self):
38 def __repr__(self):
39 return "<Strdispatch %s, %s>" % (self.strs, self.regexs)
39 return "<Strdispatch %s, %s>" % (self.strs, self.regexs)
40
41 def s_matches(self, key):
42 if key not in self.strs:
43 return
44 for el in self.strs[key]:
45 yield el[1]
46
47
40 def flat_matches(self, key):
48 def flat_matches(self, key):
41 """ Yield all 'value' targets, without priority """
49 """ Yield all 'value' targets, without priority """
42 for val in self.dispatch(key):
50 for val in self.dispatch(key):
@@ -1,3 +1,10 b''
1 2006-10-31 Ville Vainio <vivainio@gmail.com>
2
3 * strdispatch.py, completer.py, ipy_stock_completers.py:
4 Allow str_key ("command") in completer hooks. Implement
5 trivial completer for 'import' (stdlib modules only). Rename
6 ipy_linux_package_managers.py to ipy_stock_completers.py.
7
1 2006-10-30 Ville Vainio <vivainio@gmail.com>
8 2006-10-30 Ville Vainio <vivainio@gmail.com>
2
9
3 * Debugger.py, iplib.py (debugger()): Add last set of Rocky
10 * Debugger.py, iplib.py (debugger()): Add last set of Rocky
General Comments 0
You need to be logged in to leave comments. Login now