# HG changeset patch
# User Volker Braun <vbraun@stp.dias.ie>
# Date 1338183910 25200
# Node ID ba26719f779c58a212e238464e2c8bac5696e002
# Parent e0ca8faea9da9b3a5ee0ea89cea50d29968b822b
Autodedent stuff that you enter in the Sage shell
diff git a/sage/misc/interpreter.py b/sage/misc/interpreter.py
a

b


314  314  libraries += 'DYLD_LIBRARY_PATH=$$SAGE_ORIG_DYLD_LIBRARY_PATH;' 
315  315  return super(SageInteractiveShell, self).system_raw(cmd) 
316  316  
 317  def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'): 
 318  """ 
 319  Override ``interactivity`` 
 320  
 321  EXAMPLES:: 
 322  
 323  sage: from sage.misc.interpreter import get_test_shell 
 324  sage: shell = get_test_shell() 
 325  sage: shell.run_cell('for i in range(3): i') # indirect doctest 
 326  0 
 327  1 
 328  2 
 329  """ 
 330  super(SageInteractiveShell, self).run_ast_nodes(nodelist, cell_name, interactivity='all') 
 331  
317  332  ####################################### 
318  333  # Magic functions 
319  334  ####################################### 
… 
… 

665  680  return interface + '.interact()' 
666  681  return line 
667  682  
 683  class SagePromptDedenter(): 
 684  """ 
 685  Remove leading spaces from the imput line. 
 686  """ 
 687  def __call__(self, line, line_number, block_start): 
 688  """ 
 689  Transform ``line``. 
 690  
 691  INPUT: 
 692  
 693   ``line``  string. The line to be transformed. 
 694  
 695   ``line_number``  integer. The line number. For a singleline input, this is always zero. 
 696  
 697   ``block_start``  boolean. Whether the line is at the 
 698  beginning of a new block. 
 699  
 700  OUTPUT: 
 701  
 702  A string, the transformed line. 
 703  
 704  EXAMPLES:: 
 705  
 706  sage: from sage.misc.interpreter import SagePromptDedenter 
 707  sage: spd = SagePromptDedenter() 
 708  sage: spd(' 1 + \\', 0, False) 
 709  '1 + \\' 
 710  sage: spd(' 2', 1, False) 
 711  '2' 
 712  sage: spd('3', 2, False) # try our best with incorrect indentation 
 713  '3' 
 714  """ 
 715  if line_number == 0: 
 716  dedent_line = line.lstrip() 
 717  self._dedent = len(line)  len(dedent_line) 
 718  return dedent_line 
 719  else: 
 720  dedent = min(len(line)len(line.lstrip()), self._dedent) 
 721  return line[dedent:] 
668  722  
669  723  ################################################################### 
670  724  # Input Splitter 
… 
… 

700  754  InputSplitter.__init__(self, input_mode) 
701  755  self._buffer_raw = [] 
702  756  self._transforms = [ 
 757  SagePromptDedenter(), 
 758  SagePromptTransformer(), 
703  759  InterfaceMagicTransformer(), 
704   SagePromptTransformer(), 
705  760  LoadAttachTransformer(), 
706  761  SagePreparseTransformer() ] 
707  762  