sagemath / sage-shell-mode

Emacs front end for SageMath
GNU General Public License v3.0
98 stars 16 forks source link

Pasting code into a Sage process doesn't work with `use-prompt-toolkit` #18

Closed johanrosenkilde closed 7 years ago

johanrosenkilde commented 7 years ago

I'm having trouble pasting (yanking) multiple lines of code into a Sage 7.4.beta3 process with use-prompt-toolkit set to t.

The pasted code appears but when pressing ENT, it disappears again and no code was evaluated.

stakemori commented 7 years ago

Thanks for reporting and improving sage-shell-mode.

I confirmed this bug and will fix it. But I cannot completely fix it at the moment. This is due to an issue of IPython. We cannot turn off the auto indentation and it breaks the indentation when pasting code, even if I fix sage-shell-mode.

johanrosenkilde commented 7 years ago

I'm asking naively now: isn't it sage-shell-mode that's sending code to the IPython process? So sage-shell-mode should be able to catch the pasted code, break it up into lines, and send each line to the IPython process?

stakemori commented 7 years ago

So sage-shell-mode should be able to catch the pasted code, break it up into lines, and send each line to the IPython process?

If you evaluate the following code in a Sage shell buffer, you will see an indentation error.

(process-send-string (get-buffer-process sage-shell:process-buffer)
                     "def foo(x):
    if x == 1:
        return 1
    elif x%2 == 0:
        if x == 0:
            return 0
        else:
            return 1
    else:
        return x")

It may work if the leading white spaces are stripped from each lines. But auto indentation may not be correct always.

johanrosenkilde commented 7 years ago

Yeah ok, I see the problem . I don't see how IPython's current semantics of trying to help with indentation is usable in any circumstance :-S

stakemori commented 7 years ago

I have fixed this issue in master using %cpaste. Thanks for reporting.

johanrosenkilde commented 7 years ago

Awesome, thanks!