From e879edb21bd0aec631a26a27de7445039eeee93e 2005-12-31 23:07:31 From: fperez Date: 2005-12-31 23:07:31 Subject: [PATCH] - improve support for tab-completion under emacs - support N-M notation for slices in magics (includes endpoint) --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 8c969ad..1d7ea6f 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 984 2005-12-31 08:40:31Z fperez $""" +$Id: Magic.py 986 2005-12-31 23:07:31Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -128,12 +128,21 @@ license. To use profiling, please install"python2.3-profiler" from non-free.""") The set of slices is given as a list of strings (like ['1','4:8','9'], since this function is for use by magic functions which get their - arguments as strings.""" + arguments as strings. + + Note that slices can be called with two notations: + + N:M -> standard python form, means including items N...(M-1). + + N-M -> include items N..M (closed endpoint).""" cmds = [] for chunk in slices: if ':' in chunk: ini,fin = map(int,chunk.split(':')) + elif '-' in chunk: + ini,fin = map(int,chunk.split('-')) + fin += 1 else: ini = int(chunk) fin = ini+1 @@ -1539,7 +1548,7 @@ Currently the magic system has the following functions:\n""" """Define a set of input lines as a macro for future re-execution. Usage:\\ - %macro name n1:n2 n3:n4 ... n5 .. n6 ... + %macro name n1-n2 n3-n4 ... n5 .. n6 ... This will define a global variable called `name` which is a string made of joining the slices and lines you specify (n1,n2,... numbers @@ -1548,8 +1557,12 @@ Currently the magic system has the following functions:\n""" you had typed them. You just type 'name' at the prompt and the code executes. - Note that the slices use the standard Python slicing notation (5:8 - means include lines numbered 5,6,7). + The notation for indicating number ranges is: n1-n2 means 'use line + numbers n1,...n2' (the endpoint is included). That is, '5-7' means + using the lines numbered 5,6 and 7. + + Note: as a 'hidden' feature, you can also use traditional python slice + notation, where N:M means numbers N through M-1. For example, if your history contains (%hist prints it): @@ -1563,7 +1576,7 @@ Currently the magic system has the following functions:\n""" you can create a macro with lines 44 through 47 (included) and line 49 called my_macro with: - In [51]: %macro my_macro 44:48 49 + In [51]: %macro my_macro 44-47 49 Now, typing `my_macro` (without quotes) will re-execute all this code in one pass. @@ -1600,7 +1613,7 @@ Currently the magic system has the following functions:\n""" """Save a set of lines to a given filename. Usage:\\ - %save filename n1:n2 n3:n4 ... n5 .. n6 ... + %save filename n1-n2 n3-n4 ... n5 .. n6 ... This function uses the same syntax as %macro for line extraction, but instead of creating a macro it saves the resulting string to the diff --git a/IPython/Release.py b/IPython/Release.py index 692da90..db2ca98 100644 --- a/IPython/Release.py +++ b/IPython/Release.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Release data for the IPython project. -$Id: Release.py 984 2005-12-31 08:40:31Z fperez $""" +$Id: Release.py 986 2005-12-31 23:07:31Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2005 Fernando Perez @@ -22,9 +22,9 @@ name = 'ipython' # because bdist_rpm does not accept dashes (an RPM) convention, and # bdist_deb does not accept underscores (a Debian convention). -version = '0.7.0.rc4' +version = '0.7.0.rc5' -revision = '$Revision: 984 $' +revision = '$Revision: 986 $' description = "An enhanced interactive Python shell." diff --git a/IPython/completer.py b/IPython/completer.py index 2bc3781..4ef1768 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -256,6 +256,12 @@ class IPCompleter(Completer): self.space_name_re = re.compile(r'([^\\] )') # Hold a local ref. to glob.glob for speed self.glob = glob.glob + + # Determine if we are running on 'dumb' terminals, like (X)Emacs + # buffers, to avoid completion problems. + term = os.environ.get('TERM','xterm') + self.dumb_terminal = term in ['dumb','emacs'] + # Special handling of backslashes needed in win32 platforms if sys.platform == "win32": self.clean_glob = self._clean_glob_win32 @@ -496,7 +502,10 @@ class IPCompleter(Completer): # completions' message, just do the right thing and give the user # his tab! Incidentally, this enables pasting of tabbed text from # an editor (as long as autoindent is off). - if not self.get_line_buffer().strip(): + + # don't apply this on 'dumb' terminals, such as emacs buffers, so we + # don't interfere with their own tab-completion mechanism. + if not (self.dumb_terminal or self.get_line_buffer().strip()): self.readline.insert_text('\t') return None diff --git a/doc/ChangeLog b/doc/ChangeLog index 72a6567..ffc1d72 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,9 +1,17 @@ 2005-12-31 Fernando Perez + * IPython/completer.py (IPCompleter.complete): small patch to help + tab-completion under Emacs, after a suggestion by John Barnard + . + + * IPython/Magic.py (Magic.extract_input_slices): added support for + the slice notation in magics to use N-M to represent numbers N...M + (closed endpoints). This is used by %macro and %save. + * IPython/completer.py (Completer.attr_matches): for modules which define __all__, complete only on those. After a patch by Jeffrey - Collins . Also, clean up and speed up - this routine. + Collins . Also, clean up and + speed up this routine. * IPython/Logger.py (Logger.log): fix a history handling bug. I don't know if this is the end of it, but the behavior now is