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 102 |
|
8 | $Id: genutils.py 1032 2006-01-20 09:03:57Z 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> | |
@@ -209,7 +209,7 b' def fatal(msg,exit_val=1):' | |||||
209 |
|
209 | |||
210 |
|
210 | |||
211 | # useful for debugging |
|
211 | # useful for debugging | |
212 | def debugp(expr): |
|
212 | def debugp(expr,pre_msg=''): | |
213 | """Print the value of an expression from the caller's frame. |
|
213 | """Print the value of an expression from the caller's frame. | |
214 |
|
214 | |||
215 | Takes an expression, evaluates it in the caller's frame and prints both |
|
215 | Takes an expression, evaluates it in the caller's frame and prints both | |
@@ -217,7 +217,11 b' def debugp(expr):' | |||||
217 | suitable for eval().""" |
|
217 | suitable for eval().""" | |
218 |
|
218 | |||
219 | cf = sys._getframe(1) |
|
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 | StringTypes = types.StringTypes |
|
227 | StringTypes = types.StringTypes |
@@ -6,7 +6,7 b' Requires Python 2.3 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 103 |
|
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 | # indentation management |
|
560 | # indentation management | |
561 | self.autoindent = False |
|
561 | self.autoindent = False | |
562 | self.indent_current_nsp = 0 |
|
562 | self.indent_current_nsp = 0 | |
563 | self.indent_current = '' # actual indent string |
|
|||
564 |
|
563 | |||
565 | # Make some aliases automatically |
|
564 | # Make some aliases automatically | |
566 | # Prepare list of shell aliases to auto-define |
|
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 | Currently it handles auto-indent only.""" |
|
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 | def init_readline(self): |
|
1154 | def init_readline(self): | |
1155 | """Command history completion/saving/reloading.""" |
|
1155 | """Command history completion/saving/reloading.""" | |
@@ -1469,7 +1469,6 b' want to merge them back into the new files.""" % locals()' | |||||
1469 |
|
1469 | |||
1470 | if self.autoindent: |
|
1470 | if self.autoindent: | |
1471 | self.indent_current_nsp = 0 |
|
1471 | self.indent_current_nsp = 0 | |
1472 | self.indent_current = ' '* self.indent_current_nsp |
|
|||
1473 |
|
1472 | |||
1474 | except bdb.BdbQuit: |
|
1473 | except bdb.BdbQuit: | |
1475 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
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 | except: |
|
1536 | except: | |
1538 | self.showtraceback() |
|
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 | def autoindent_update(self,line): |
|
1543 | def autoindent_update(self,line): | |
1541 | """Keep track of the indent level.""" |
|
1544 | """Keep track of the indent level.""" | |
1542 |
|
1545 | |||
|
1546 | debugp('line','autoindent_update:') | |||
|
1547 | debugp('self.indent_current_nsp') | |||
1543 | if self.autoindent: |
|
1548 | if self.autoindent: | |
1544 | if line: |
|
1549 | if line: | |
1545 |
|
|
1550 | inisp = num_ini_spaces(line) | |
|
1551 | if inisp < self.indent_current_nsp: | |||
|
1552 | self.indent_current_nsp = inisp | |||
1546 |
|
1553 | |||
1547 | if line[-1] == ':': |
|
1554 | if line[-1] == ':': | |
1548 | self.indent_current_nsp += 4 |
|
1555 | self.indent_current_nsp += 4 | |
@@ -1551,10 +1558,6 b' want to merge them back into the new files.""" % locals()' | |||||
1551 | else: |
|
1558 | else: | |
1552 | self.indent_current_nsp = 0 |
|
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 | def runlines(self,lines): |
|
1561 | def runlines(self,lines): | |
1559 | """Run a string of one or more lines of source. |
|
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 | def resetbuffer(self): |
|
1724 | def resetbuffer(self): | |
1722 | """Reset the input buffer.""" |
|
1725 | """Reset the input buffer.""" | |
1723 | self.buffer[:] = [] |
|
1726 | self.buffer[:] = [] | |
1724 |
|
1727 | |||
1725 | def raw_input(self,prompt='',continue_prompt=False): |
|
1728 | def raw_input(self,prompt='',continue_prompt=False): | |
1726 | """Write a prompt and read a line. |
|
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 | # than necessary. We do this by trimming out the auto-indent initial |
|
1744 | # than necessary. We do this by trimming out the auto-indent initial | |
1742 | # spaces, if the user's actual input started itself with whitespace. |
|
1745 | # spaces, if the user's actual input started itself with whitespace. | |
1743 | #debugp('self.buffer[-1]') |
|
1746 | #debugp('self.buffer[-1]') | |
1744 | ## if self.autoindent: |
|
1747 | ||
1745 | ## try: |
|
1748 | debugp('line') | |
1746 | ## prev_line = self.buffer[-1] |
|
1749 | debugp('self.indent_current_nsp') | |
1747 | ## except IndexError: |
|
1750 | if self.autoindent: | |
1748 | ## prev_line = '' |
|
1751 | if num_ini_spaces(line) > self.indent_current_nsp: | |
1749 | ## prev_indent = num_ini_spaces(prev_line) |
|
1752 | line = line[self.indent_current_nsp:] | |
1750 | ## debugp('prev_indent') |
|
1753 | self.indent_current_nsp = 0 | |
1751 | ## # Split the user's input |
|
1754 | debugp('self.indent_current_nsp') | |
1752 | ## line1 = line[:self.indent_current_nsp] |
|
1755 | ||
1753 | ## line2 = line[self.indent_current_nsp:] |
|
1756 | debugp('line') | |
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') |
|
|||
1763 | return self.prefilter(line,continue_prompt) |
|
1757 | return self.prefilter(line,continue_prompt) | |
1764 |
|
1758 | |||
1765 | def split_user_input(self,line): |
|
1759 | def split_user_input(self,line): | |
@@ -1937,7 +1931,8 b' want to merge them back into the new files.""" % locals()' | |||||
1937 | # of a size different to the indent level, will exit the input loop. |
|
1931 | # of a size different to the indent level, will exit the input loop. | |
1938 |
|
1932 | |||
1939 | if (continue_prompt and self.autoindent and line.isspace() and |
|
1933 | if (continue_prompt and self.autoindent and line.isspace() and | |
1940 |
(line != self.indent_current |
|
1934 | (line != self.indent_current_str() or | |
|
1935 | (self.buffer[-1]).isspace() )): | |||
1941 | line = '' |
|
1936 | line = '' | |
1942 |
|
1937 | |||
1943 | self.log(line,continue_prompt) |
|
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 | 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu> |
|
13 | 2006-01-18 Fernando Perez <Fernando.Perez@colorado.edu> | |
2 |
|
14 | |||
3 | * IPython/Magic.py (magic_edit): fix check for when users don't |
|
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 | include ipythonrc |
|
2604 | include ipythonrc | |
2605 | \layout LyX-Code |
|
2605 | \layout LyX-Code | |
2606 |
|
2606 | |||
2607 |
|
|
2607 | # cancel earlier logfile invocation: | |
|
2608 | \layout LyX-Code | |||
|
2609 | ||||
|
2610 | logfile '' | |||
2608 | \layout LyX-Code |
|
2611 | \layout LyX-Code | |
2609 |
|
2612 | |||
2610 | execute import time |
|
2613 | execute import time |
General Comments 0
You need to be logged in to leave comments.
Login now