##// END OF EJS Templates
_tentative_ fixes to pasting of multiline code with autoindent on. Needs...
fperez -
Show More
@@ -5,7 +5,7 b' General purpose utilities.'
5 5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 6 these things are also convenient when working at the command line.
7 7
8 $Id: genutils.py 1028 2006-01-16 21:42:33Z vivainio $"""
8 $Id: genutils.py 1032 2006-01-20 09:03:57Z fperez $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -209,7 +209,7 b' def fatal(msg,exit_val=1):'
209 209
210 210
211 211 # useful for debugging
212 def debugp(expr):
212 def debugp(expr,pre_msg=''):
213 213 """Print the value of an expression from the caller's frame.
214 214
215 215 Takes an expression, evaluates it in the caller's frame and prints both
@@ -217,7 +217,11 b' def debugp(expr):'
217 217 suitable for eval()."""
218 218
219 219 cf = sys._getframe(1)
220 print '[DBG] %s -> %r' % (expr,eval(expr,cf.f_globals,cf.f_locals))
220 print '[DBG] %s %s -> %r' % (pre_msg,expr,
221 eval(expr,cf.f_globals,cf.f_locals))
222
223 # deactivate it from here:
224 def debugp(expr,pre_msg=''): pass
221 225
222 226 #----------------------------------------------------------------------------
223 227 StringTypes = types.StringTypes
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 1031 2006-01-18 20:20:39Z vivainio $
9 $Id: iplib.py 1032 2006-01-20 09:03:57Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -560,7 +560,6 b' class InteractiveShell(object,Magic):'
560 560 # indentation management
561 561 self.autoindent = False
562 562 self.indent_current_nsp = 0
563 self.indent_current = '' # actual indent string
564 563
565 564 # Make some aliases automatically
566 565 # Prepare list of shell aliases to auto-define
@@ -1149,7 +1148,8 b' want to merge them back into the new files.""" % locals()'
1149 1148
1150 1149 Currently it handles auto-indent only."""
1151 1150
1152 self.readline.insert_text(self.indent_current)
1151 #debugp('self.indent_current_nsp','pre_readline:')
1152 self.readline.insert_text(self.indent_current_str())
1153 1153
1154 1154 def init_readline(self):
1155 1155 """Command history completion/saving/reloading."""
@@ -1469,7 +1469,6 b' want to merge them back into the new files.""" % locals()'
1469 1469
1470 1470 if self.autoindent:
1471 1471 self.indent_current_nsp = 0
1472 self.indent_current = ' '* self.indent_current_nsp
1473 1472
1474 1473 except bdb.BdbQuit:
1475 1474 warn("The Python debugger has exited with a BdbQuit exception.\n"
@@ -1537,12 +1536,20 b' want to merge them back into the new files.""" % locals()'
1537 1536 except:
1538 1537 self.showtraceback()
1539 1538
1539 def indent_current_str(self):
1540 """return the current level of indentation as a string"""
1541 return self.indent_current_nsp * ' '
1542
1540 1543 def autoindent_update(self,line):
1541 1544 """Keep track of the indent level."""
1542 1545
1546 debugp('line','autoindent_update:')
1547 debugp('self.indent_current_nsp')
1543 1548 if self.autoindent:
1544 1549 if line:
1545 self.indent_current_nsp = num_ini_spaces(line)
1550 inisp = num_ini_spaces(line)
1551 if inisp < self.indent_current_nsp:
1552 self.indent_current_nsp = inisp
1546 1553
1547 1554 if line[-1] == ':':
1548 1555 self.indent_current_nsp += 4
@@ -1551,10 +1558,6 b' want to merge them back into the new files.""" % locals()'
1551 1558 else:
1552 1559 self.indent_current_nsp = 0
1553 1560
1554 # indent_current is the actual string to be inserted
1555 # by the readline hooks for indentation
1556 self.indent_current = ' '* self.indent_current_nsp
1557
1558 1561 def runlines(self,lines):
1559 1562 """Run a string of one or more lines of source.
1560 1563
@@ -1721,7 +1724,7 b' want to merge them back into the new files.""" % locals()'
1721 1724 def resetbuffer(self):
1722 1725 """Reset the input buffer."""
1723 1726 self.buffer[:] = []
1724
1727
1725 1728 def raw_input(self,prompt='',continue_prompt=False):
1726 1729 """Write a prompt and read a line.
1727 1730
@@ -1741,25 +1744,16 b' want to merge them back into the new files.""" % locals()'
1741 1744 # than necessary. We do this by trimming out the auto-indent initial
1742 1745 # spaces, if the user's actual input started itself with whitespace.
1743 1746 #debugp('self.buffer[-1]')
1744 ## if self.autoindent:
1745 ## try:
1746 ## prev_line = self.buffer[-1]
1747 ## except IndexError:
1748 ## prev_line = ''
1749 ## prev_indent = num_ini_spaces(prev_line)
1750 ## debugp('prev_indent')
1751 ## # Split the user's input
1752 ## line1 = line[:self.indent_current_nsp]
1753 ## line2 = line[self.indent_current_nsp:]
1754 ## if line1.isspace() and line2 and \
1755 ## num_ini_spaces(line2)==prev_indent:
1756 ## line = line2
1757 #debugp('line')
1758 #debugp('line1')
1759 #debugp('line2')
1760 ## if line1.isspace() and line2 and line2[0:1] in (' ','\t'):
1761 ## line = line2
1762 ## debugp('line')
1747
1748 debugp('line')
1749 debugp('self.indent_current_nsp')
1750 if self.autoindent:
1751 if num_ini_spaces(line) > self.indent_current_nsp:
1752 line = line[self.indent_current_nsp:]
1753 self.indent_current_nsp = 0
1754 debugp('self.indent_current_nsp')
1755
1756 debugp('line')
1763 1757 return self.prefilter(line,continue_prompt)
1764 1758
1765 1759 def split_user_input(self,line):
@@ -1937,7 +1931,8 b' want to merge them back into the new files.""" % locals()'
1937 1931 # of a size different to the indent level, will exit the input loop.
1938 1932
1939 1933 if (continue_prompt and self.autoindent and line.isspace() and
1940 (line != self.indent_current or (self.buffer[-1]).isspace() )):
1934 (line != self.indent_current_str() or
1935 (self.buffer[-1]).isspace() )):
1941 1936 line = ''
1942 1937
1943 1938 self.log(line,continue_prompt)
@@ -1,3 +1,15 b''
1 2006-01-20 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (raw_input): I _think_ I got the pasting of
4 multiline code with autoindent on working. But I am really not
5 sure, so this needs more testing. Will commit a debug-enabled
6 version for now, while I test it some more, so that Ville and
7 others may also catch any problems. Also made
8 self.indent_current_str() a method, to ensure that there's no
9 chance of the indent space count and the corresponding string
10 falling out of sync. All code needing the string should just call
11 the method.
12
1 13 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu>
2 14
3 15 * IPython/Magic.py (magic_edit): fix check for when users don't
@@ -2604,7 +2604,10 b' I recently happened on a nifty way to keep tidy per-project log files.'
2604 2604 include ipythonrc
2605 2605 \layout LyX-Code
2606 2606
2607 logfile '' # cancel earlier logfile invocation
2607 # cancel earlier logfile invocation:
2608 \layout LyX-Code
2609
2610 logfile ''
2608 2611 \layout LyX-Code
2609 2612
2610 2613 execute import time
General Comments 0
You need to be logged in to leave comments. Login now