##// END OF EJS Templates
%autocall fixes...
fperez -
Show More
@@ -5,7 +5,7 b' General purpose utilities.'
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 1007 2006-01-12 17:15:41Z vivainio $"""
8 $Id: genutils.py 1013 2006-01-13 08:33:32Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -937,12 +937,6 b' class SList(list):'
937 n = nlstr = property(get_nlstr)
937 n = nlstr = property(get_nlstr)
938
938
939 #----------------------------------------------------------------------------
939 #----------------------------------------------------------------------------
940 # This can be replaced with an isspace() call once we drop 2.2 compatibility
941 _isspace_match = re.compile(r'^\s+$').match
942 def isspace(s):
943 return bool(_isspace_match(s))
944
945 #----------------------------------------------------------------------------
946 def esc_quotes(strng):
940 def esc_quotes(strng):
947 """Return the input string with single and double quotes escaped out"""
941 """Return the input string with single and double quotes escaped out"""
948
942
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 1012 2006-01-12 21:29:37Z vivainio $
9 $Id: iplib.py 1013 2006-01-13 08:33:32Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -82,15 +82,26 b' from IPython.genutils import *'
82 raw_input_original = raw_input
82 raw_input_original = raw_input
83
83
84 # compiled regexps for autoindent management
84 # compiled regexps for autoindent management
85 ini_spaces_re = re.compile(r'^(\s+)')
86 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
85 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
87
86
88
87
89 #****************************************************************************
88 #****************************************************************************
90 # Some utility function definitions
89 # Some utility function definitions
91
90
91 ini_spaces_re = re.compile(r'^(\s+)')
92
93 def num_ini_spaces(strng):
94 """Return the number of initial spaces in a string"""
95
96 ini_spaces = ini_spaces_re.match(strng)
97 if ini_spaces:
98 return ini_spaces.end()
99 else:
100 return 0
101
92 def softspace(file, newvalue):
102 def softspace(file, newvalue):
93 """Copied from code.py, to remove the dependency"""
103 """Copied from code.py, to remove the dependency"""
104
94 oldvalue = 0
105 oldvalue = 0
95 try:
106 try:
96 oldvalue = file.softspace
107 oldvalue = file.softspace
@@ -473,8 +484,18 b' class InteractiveShell(object,Magic):'
473
484
474 # RegExp to identify potential function names
485 # RegExp to identify potential function names
475 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
486 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
476 # RegExp to exclude strings with this start from autocalling
487
477 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
488 # RegExp to exclude strings with this start from autocalling. In
489 # particular, all binary operators should be excluded, so that if foo
490 # is callable, foo OP bar doesn't become foo(OP bar), which is
491 # invalid. The characters '!=()' don't need to be checked for, as the
492 # _prefilter routine explicitely does so, to catch direct calls and
493 # rebindings of existing names.
494
495 # Warning: the '-' HAS TO BE AT THE END of the first group, otherwise
496 # it affects the rest of the group in square brackets.
497 self.re_exclude_auto = re.compile(r'^[<>,&^\|\*/\+-]'
498 '|^is |^not |^in |^and |^or ')
478
499
479 # try to catch also methods for stuff in lists/tuples/dicts: off
500 # try to catch also methods for stuff in lists/tuples/dicts: off
480 # (experimental). For this to work, the line_split regexp would need
501 # (experimental). For this to work, the line_split regexp would need
@@ -1077,6 +1098,7 b' want to merge them back into the new files.""" % locals()'
1077
1098
1078 Saving of persistent data should be performed here. """
1099 Saving of persistent data should be performed here. """
1079
1100
1101 #print '*** IPython exit cleanup ***' # dbg
1080 # input history
1102 # input history
1081 self.savehist()
1103 self.savehist()
1082
1104
@@ -1496,14 +1518,10 b' want to merge them back into the new files.""" % locals()'
1496
1518
1497 def autoindent_update(self,line):
1519 def autoindent_update(self,line):
1498 """Keep track of the indent level."""
1520 """Keep track of the indent level."""
1521
1499 if self.autoindent:
1522 if self.autoindent:
1500 if line:
1523 if line:
1501 ini_spaces = ini_spaces_re.match(line)
1524 self.indent_current_nsp = num_ini_spaces(line)
1502 if ini_spaces:
1503 nspaces = ini_spaces.end()
1504 else:
1505 nspaces = 0
1506 self.indent_current_nsp = nspaces
1507
1525
1508 if line[-1] == ':':
1526 if line[-1] == ':':
1509 self.indent_current_nsp += 4
1527 self.indent_current_nsp += 4
@@ -1701,10 +1719,26 b' want to merge them back into the new files.""" % locals()'
1701 # Try to be reasonably smart about not re-indenting pasted input more
1719 # Try to be reasonably smart about not re-indenting pasted input more
1702 # than necessary. We do this by trimming out the auto-indent initial
1720 # than necessary. We do this by trimming out the auto-indent initial
1703 # spaces, if the user's actual input started itself with whitespace.
1721 # spaces, if the user's actual input started itself with whitespace.
1704 if self.autoindent:
1722 #debugp('self.buffer[-1]')
1705 line2 = line[self.indent_current_nsp:]
1723 ## if self.autoindent:
1706 if line2[0:1] in (' ','\t'):
1724 ## try:
1707 line = line2
1725 ## prev_line = self.buffer[-1]
1726 ## except IndexError:
1727 ## prev_line = ''
1728 ## prev_indent = num_ini_spaces(prev_line)
1729 ## debugp('prev_indent')
1730 ## # Split the user's input
1731 ## line1 = line[:self.indent_current_nsp]
1732 ## line2 = line[self.indent_current_nsp:]
1733 ## if line1.isspace() and line2 and \
1734 ## num_ini_spaces(line2)==prev_indent:
1735 ## line = line2
1736 #debugp('line')
1737 #debugp('line1')
1738 #debugp('line2')
1739 ## if line1.isspace() and line2 and line2[0:1] in (' ','\t'):
1740 ## line = line2
1741 ## debugp('line')
1708 return self.prefilter(line,continue_prompt)
1742 return self.prefilter(line,continue_prompt)
1709
1743
1710 def split_user_input(self,line):
1744 def split_user_input(self,line):
@@ -1875,8 +1909,8 b' want to merge them back into the new files.""" % locals()'
1875 # lines of pure whitespace in a row, or a line of pure whitespace but
1909 # lines of pure whitespace in a row, or a line of pure whitespace but
1876 # of a size different to the indent level, will exit the input loop.
1910 # of a size different to the indent level, will exit the input loop.
1877
1911
1878 if (continue_prompt and self.autoindent and isspace(line) and
1912 if (continue_prompt and self.autoindent and line.isspace() and
1879 (line != self.indent_current or isspace(self.buffer[-1]))):
1913 (line != self.indent_current or (self.buffer[-1]).isspace() )):
1880 line = ''
1914 line = ''
1881
1915
1882 self.log(line,continue_prompt)
1916 self.log(line,continue_prompt)
@@ -1,3 +1,23 b''
1 2006-01-13 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (raw_input): temporarily deactivate all
4 attempts at allowing pasting of code with autoindent on. It
5 introduced bugs (reported by Prabhu) and I can't seem to find a
6 robust combination which works in all cases. Will have to revisit
7 later.
8
9 * IPython/genutils.py: remove isspace() function. We've dropped
10 2.2 compatibility, so it's OK to use the string method.
11
12 2006-01-12 Fernando Perez <Fernando.Perez@colorado.edu>
13
14 * IPython/iplib.py (InteractiveShell.__init__): fix regexp
15 matching what NOT to autocall on, to include all python binary
16 operators (including things like 'and', 'or', 'is' and 'in').
17 Prompted by a bug report on 'foo & bar', but I realized we had
18 many more potential bug cases with other operators. The regexp is
19 self.re_exclude_auto, it's fairly commented.
20
1 2006-01-12 Ville Vainio <vivainio@gmail.com>
21 2006-01-12 Ville Vainio <vivainio@gmail.com>
2
22
3 * IPython/iplib.py (make_quoted_expr,handle_shell_escape):
23 * IPython/iplib.py (make_quoted_expr,handle_shell_escape):
@@ -11,9 +31,9 b''
11 deleted all pretense of supporting multiline command strings in
31 deleted all pretense of supporting multiline command strings in
12 !system or %magic commands. Thanks to Jerry McRae for suggestions.
32 !system or %magic commands. Thanks to Jerry McRae for suggestions.
13
33
14 * doc/build_doc_instructions.txt added. Documentation on how to use
34 * doc/build_doc_instructions.txt added. Documentation on how to
15 doc/update_manual.py, added yesterday. Both files contributed by
35 use doc/update_manual.py, added yesterday. Both files contributed
16 Jörgen Stenarson <jorgen.stenarson@bostream.nu>. This slates
36 by Jörgen Stenarson <jorgen.stenarson-AT-bostream.nu>. This slates
17 doc/*.sh for deprecation at a later date.
37 doc/*.sh for deprecation at a later date.
18
38
19 * /ipython.py Added ipython.py to root directory for
39 * /ipython.py Added ipython.py to root directory for
General Comments 0
You need to be logged in to leave comments. Login now