From 502f53eae6c62e6d2aea8dfef8e86f695a278e0c 2008-01-11 17:53:58 From: vivainio Date: 2008-01-11 17:53:58 Subject: [PATCH] readline.get_endidx is configurable, for emacs users --- diff --git a/IPython/completer.py b/IPython/completer.py index 073ea47..8d8ec63 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -247,6 +247,7 @@ class IPCompleter(Completer): delims = delims.replace(self.magic_escape,'') self.readline.set_completer_delims(delims) self.get_line_buffer = self.readline.get_line_buffer + self.get_endidx = self.readline.get_endidx self.omit__names = omit__names self.merge_completions = shell.rc.readline_merge_completions if alias_table is None: @@ -272,6 +273,7 @@ class IPCompleter(Completer): self.alias_matches, self.python_func_kw_matches] + # Code contributed by Alex Schmolck, for ipython/emacs integration def all_completions(self, text): """Return all possible completions for the benefit of emacs.""" @@ -560,8 +562,7 @@ class IPCompleter(Completer): pass return None - - + def complete(self, text, state,line_buffer=None): """Return the next possible completion for 'text'. @@ -584,6 +585,9 @@ class IPCompleter(Completer): # his tab! Incidentally, this enables pasting of tabbed text from # an editor (as long as autoindent is off). + # It should be noted that at least pyreadline still shows + # file completions - is there a way around it? + # don't apply this on 'dumb' terminals, such as emacs buffers, so we # don't interfere with their own tab-completion mechanism. if line_buffer is None: @@ -598,7 +602,7 @@ class IPCompleter(Completer): magic_escape = self.magic_escape magic_prefix = self.magic_prefix - self.lbuf = self.full_lbuf[:self.readline.get_endidx()] + self.lbuf = self.full_lbuf[:self.get_endidx()] try: if text.startswith(magic_escape): diff --git a/doc/ChangeLog b/doc/ChangeLog index 3f6c226..fb2511a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -6,6 +6,9 @@ * ipy_user_conf.py: Added an example on how to change term colors in config file (through using autoexec). + + * completer.py, test_completer.py: Ability to specify custom + get_endidx to replace readline.get_endidx. For emacs users. 2008-01-10 Ville Vainio diff --git a/test/test_completer.py b/test/test_completer.py new file mode 100644 index 0000000..2badc64 --- /dev/null +++ b/test/test_completer.py @@ -0,0 +1,37 @@ +""" +comp +""" + +# The prefilter always ends in a call to some self.handle_X method. We swap +# all of those out so that we can capture which one was called. + +import sys +sys.path.append('..') +import IPython +import IPython.ipapi + +IPython.Shell.start() + +ip = IPython.ipapi.get() + +completer = ip.IP.Completer + +print completer + +def do_test(text, line): + def get_endix(): + idx = len(line) -1 + print "Call endidx =>",idx + return idx + def get_line_buffer(): + print "Lbuf =>",line + return line + completer.get_line_buffer = get_line_buffer + completer.get_endidx = get_endix + l = completer.all_completions(text) + return l + +l = do_test ('p', 'print p') +assert 'pow' in l +l = do_test ('p', 'import p') +assert 'pprint' in l \ No newline at end of file