Show More
@@ -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 95 |
|
9 | $Id: iplib.py 955 2005-12-27 07:50:29Z fperez $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -447,8 +447,18 b' try:' | |||||
447 |
|
447 | |||
448 | This is called successively with state == 0, 1, 2, ... until it |
|
448 | This is called successively with state == 0, 1, 2, ... until it | |
449 | returns None. The completion should begin with 'text'. """ |
|
449 | returns None. The completion should begin with 'text'. """ | |
450 |
|
450 | |||
451 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg |
|
451 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg | |
|
452 | ||||
|
453 | # if there is only a tab on a line with only whitespace, instead | |||
|
454 | # of the mostly useless 'do you want to see all million | |||
|
455 | # completions' message, just do the right thing and give the user | |||
|
456 | # his tab! Incidentally, this enables pasting of tabbed text from | |||
|
457 | # an editor (as long as autoindent is off). | |||
|
458 | if not self.get_line_buffer().strip(): | |||
|
459 | self.readline.insert_text('\t') | |||
|
460 | return None | |||
|
461 | ||||
452 | magic_escape = self.magic_escape |
|
462 | magic_escape = self.magic_escape | |
453 | magic_prefix = self.magic_prefix |
|
463 | magic_prefix = self.magic_prefix | |
454 |
|
464 | |||
@@ -477,7 +487,7 b' try:' | |||||
477 | return None |
|
487 | return None | |
478 | except: |
|
488 | except: | |
479 | # If completion fails, don't annoy the user. |
|
489 | # If completion fails, don't annoy the user. | |
480 |
|
|
490 | return None | |
481 |
|
491 | |||
482 | except ImportError: |
|
492 | except ImportError: | |
483 | pass # no readline support |
|
493 | pass # no readline support | |
@@ -1473,6 +1483,10 b' want to merge them back into the new files.""" % locals()' | |||||
1473 | # Mark activity in the builtins |
|
1483 | # Mark activity in the builtins | |
1474 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1484 | __builtin__.__dict__['__IPYTHON__active'] += 1 | |
1475 |
|
1485 | |||
|
1486 | # compiled regexps for autoindent management | |||
|
1487 | ini_spaces_re = re.compile(r'^(\s+)') | |||
|
1488 | dedent_re = re.compile(r'^\s+raise|^\s+return') | |||
|
1489 | ||||
1476 | # exit_now is set by a call to %Exit or %Quit |
|
1490 | # exit_now is set by a call to %Exit or %Quit | |
1477 | while not self.exit_now: |
|
1491 | while not self.exit_now: | |
1478 | try: |
|
1492 | try: | |
@@ -1483,7 +1497,7 b' want to merge them back into the new files.""" % locals()' | |||||
1483 | else: |
|
1497 | else: | |
1484 | prompt = self.outputcache.prompt1 |
|
1498 | prompt = self.outputcache.prompt1 | |
1485 | try: |
|
1499 | try: | |
1486 | line = self.raw_input(prompt) |
|
1500 | line = self.raw_input(prompt,more) | |
1487 | if self.autoindent: |
|
1501 | if self.autoindent: | |
1488 | self.readline_startup_hook(None) |
|
1502 | self.readline_startup_hook(None) | |
1489 | except EOFError: |
|
1503 | except EOFError: | |
@@ -1500,7 +1514,7 b' want to merge them back into the new files.""" % locals()' | |||||
1500 | # Auto-indent management |
|
1514 | # Auto-indent management | |
1501 | if self.autoindent: |
|
1515 | if self.autoindent: | |
1502 | if line: |
|
1516 | if line: | |
1503 |
ini_spaces = re.match( |
|
1517 | ini_spaces = ini_spaces_re.match(line) | |
1504 | if ini_spaces: |
|
1518 | if ini_spaces: | |
1505 | nspaces = ini_spaces.end() |
|
1519 | nspaces = ini_spaces.end() | |
1506 | else: |
|
1520 | else: | |
@@ -1509,7 +1523,7 b' want to merge them back into the new files.""" % locals()' | |||||
1509 |
|
1523 | |||
1510 | if line[-1] == ':': |
|
1524 | if line[-1] == ':': | |
1511 | self.readline_indent += 4 |
|
1525 | self.readline_indent += 4 | |
1512 |
elif re.match( |
|
1526 | elif dedent_re.match(line): | |
1513 | self.readline_indent -= 4 |
|
1527 | self.readline_indent -= 4 | |
1514 | else: |
|
1528 | else: | |
1515 | self.readline_indent = 0 |
|
1529 | self.readline_indent = 0 | |
@@ -1720,18 +1734,29 b' want to merge them back into the new files.""" % locals()' | |||||
1720 | self.code_to_run = None |
|
1734 | self.code_to_run = None | |
1721 | return outflag |
|
1735 | return outflag | |
1722 |
|
1736 | |||
1723 |
def raw_input(self, |
|
1737 | def raw_input(self,prompt='',continue_prompt=False): | |
1724 | """Write a prompt and read a line. |
|
1738 | """Write a prompt and read a line. | |
1725 |
|
1739 | |||
1726 | The returned line does not include the trailing newline. |
|
1740 | The returned line does not include the trailing newline. | |
1727 | When the user enters the EOF key sequence, EOFError is raised. |
|
1741 | When the user enters the EOF key sequence, EOFError is raised. | |
1728 |
|
1742 | |||
1729 | The base implementation uses the built-in function |
|
1743 | Optional inputs: | |
1730 | raw_input(); a subclass may replace this with a different |
|
1744 | ||
1731 | implementation. |
|
1745 | - prompt(''): a string to be printed to prompt the user. | |
|
1746 | ||||
|
1747 | - continue_prompt(False): whether this line is the first one or a | |||
|
1748 | continuation in a sequence of inputs. | |||
1732 | """ |
|
1749 | """ | |
1733 | return self.prefilter(raw_input_original(prompt), |
|
1750 | ||
1734 | prompt==self.outputcache.prompt2) |
|
1751 | line = raw_input_original(prompt) | |
|
1752 | # Try to be reasonably smart about not re-indenting pasted input more | |||
|
1753 | # than necessary. We do this by trimming out the auto-indent initial | |||
|
1754 | # spaces, if the user's actual input started itself with whitespace. | |||
|
1755 | if self.autoindent: | |||
|
1756 | line2 = line[self.readline_indent:] | |||
|
1757 | if line2[0:1] in (' ','\t'): | |||
|
1758 | line = line2 | |||
|
1759 | return self.prefilter(line,continue_prompt) | |||
1735 |
|
1760 | |||
1736 | def split_user_input(self,line): |
|
1761 | def split_user_input(self,line): | |
1737 | """Split user input into pre-char, function part and rest.""" |
|
1762 | """Split user input into pre-char, function part and rest.""" | |
@@ -1778,7 +1803,7 b' want to merge them back into the new files.""" % locals()' | |||||
1778 | self._last_input_line = line |
|
1803 | self._last_input_line = line | |
1779 |
|
1804 | |||
1780 | #print '***line: <%s>' % line # dbg |
|
1805 | #print '***line: <%s>' % line # dbg | |
1781 |
|
1806 | |||
1782 | # the input history needs to track even empty lines |
|
1807 | # the input history needs to track even empty lines | |
1783 | if not line.strip(): |
|
1808 | if not line.strip(): | |
1784 | if not continue_prompt: |
|
1809 | if not continue_prompt: |
@@ -1,3 +1,15 b'' | |||||
|
1 | 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu> | |||
|
2 | ||||
|
3 | * IPython/iplib.py (raw_input): improve indentation management. | |||
|
4 | It is now possible to paste indented code with autoindent on, and | |||
|
5 | the code is interpreted correctly (though it still looks bad on | |||
|
6 | screen, due to the line-oriented nature of ipython). | |||
|
7 | (MagicCompleter.complete): change behavior so that a TAB key on an | |||
|
8 | otherwise empty line actually inserts a tab, instead of completing | |||
|
9 | on the entire global namespace. This makes it easier to use the | |||
|
10 | TAB key for indentation. After a request by Hans Meine | |||
|
11 | <hans_meine-AT-gmx.net> | |||
|
12 | ||||
1 | 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu> |
|
13 | 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu> | |
2 |
|
14 | |||
3 | * IPython/ultraTB.py (VerboseTB.text): harden reporting against |
|
15 | * IPython/ultraTB.py (VerboseTB.text): harden reporting against |
General Comments 0
You need to be logged in to leave comments.
Login now