Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with multiline history recall in IPython #130

Closed
nbruin opened this issue Oct 14, 2006 · 3 comments
Closed

problem with multiline history recall in IPython #130

nbruin opened this issue Oct 14, 2006 · 3 comments

Comments

@nbruin
Copy link
Contributor

nbruin commented Oct 14, 2006

If you type a loop at the sage prompt:

----------------------------------
sage: for i in range(1,3):
   ...:     print i
   ...:
1
2
----------------------------------

and then do an "arrow up" key, it seems like the loop is recalled. However, it seems only the first line is actually still there:

-----------------------------------------
sage: for i in range(1,3):
    print i
   ....:     print "done"
   ....:
done
done
-----------------------------------------

Component: user interface

Issue created by migration from https://trac.sagemath.org/ticket/130

@williamstein

This comment has been minimized.

@williamstein
Copy link
Contributor

comment:2

In straight Ipython this problems doesn't happen. In sage it does. Tricky.

PLAN:

  1. disable bits of how sage customizes ipython until find the problem.

@williamstein
Copy link
Contributor

comment:3

Fixed

# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1169199334 28800
# Node ID e89f3913fa979d38a32cbcbef9b4d0af56c5de16
# Parent  cbda6c27c46e6e36c6c192550b172f79189ce974
Fix trac bug #130 -- multiline editing in Ipython/sage was broken.

diff -r cbda6c27c46e -r e89f3913fa97 sage/misc/interpreter.py
--- a/sage/misc/interpreter.py  Fri Jan 19 01:19:31 2007 -0800
+++ b/sage/misc/interpreter.py  Fri Jan 19 01:35:34 2007 -0800
@@ -152,7 +152,15 @@ def do_prefilter_paste(line, continuatio
 def do_prefilter_paste(line, continuation):
     """
     Alternate prefilter for input.
-    """
+
+    INPUT:
+        line -- a single line; must *not* have any newlines in it
+        continuation -- whether the input line is really part
+                     of the previous line, because of open parens or backslash.
+    """
+    if '\n' in line:
+        raise RuntimeError, "bug in function that calls do_prefilter_paste -- there can be no newlines in the input"
+    
     global attached
 
     # This is so it's OK to have lots of blank space at the
@@ -366,23 +374,34 @@ def process_file(name):
     return name2
     
 
-def sage_prefilter(self, line, continuation):
-    """
-    Alternate prefilter for input.
+def sage_prefilter(self, block, continuation):
+    """
+    SAGE's prefilter for input.  Given a string block (usually a
+    line), return the preparsed version of it.  
+
+    INPUT:
+        block -- string (usually a single line, but not always)
+        continuation -- whether or not this line is a continuation.
     """
     try:
-        line2 = do_prefilter_paste(line, continuation)
+        block2 = ''
+        for L in block.split('\n'):
+            M = do_prefilter_paste(L, continuation)
+            # The L[:len(L)-len(L.lstrip())]  business here preserves
+            # the whitespace at the beginning of L.
+            if block2 != '':
+                block2 += '\n'
+            block2 += L[:len(L)-len(L.lstrip())] + M 
 
     except None:
         
         print "WARNING: An error occured in the SAGE parser while"
-        print "parsing the following line:"
-        print line
+        print "parsing the following block:"
+        print block
         print "Please report this as a bug (include the output of typing '%hist')."
-        line2 = line
-        
-    from IPython.iplib import InteractiveShell
-    return InteractiveShell._prefilter(self, line2, continuation)
+        block2 = block
+        
+    return InteractiveShell._prefilter(self, block2, continuation)
 

@williamstein williamstein added this to the sage-1.8 milestone Jan 19, 2007
kryzar pushed a commit to kryzar/sage that referenced this issue Feb 6, 2023
This is needed for python 3.11 support (sagemath#33842) and to make cypari
compatible with current pari version

https://groups.google.com/g/sage-devel/c/jqmr6bDjDrk/m/XE2GlB_GBgAJ

Necessary follow ups:
- make cypari thread safe: see
[[https://github.com/sagemath/cypari2/pull/116|cypari2 sagemath#116]]
- remove optional build time dependency of cysignals on pari: see
[[https://github.com/sagemath/cypari2/pull/130|cypari2 sagemath#130]]

URL: https://trac.sagemath.org/33878
Reported by: gh-kliem
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik
tobiasdiez pushed a commit to tobiasdiez/sage that referenced this issue Feb 22, 2024
…output

Add possibility to disable output
mkoeppe added a commit to mkoeppe/sage that referenced this issue Nov 11, 2024
`docker.yml`: Set EXTRA_DOCKER_TAGS based on passagemath release tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants