Open johanrosenkilde opened 8 years ago
Actually, this error occurs without Evil at all: Type 2+2<C-j><Enter>
and the sage shell will display 4 and then promptly exit.
Actually, this error occurs without Evil at all: Type 2+2
and the sage shell will display 4 and then promptly exit.
Thanks for reporting. But I cannot reproduce this. Can you reproduce this with emacs -Q
and only sage-shell-mode
(and evil-mode
) is loaded? Could you provide Emacs version and name of commands bound to those keys?
Hmm, indeed. Sorry for the noise, I should have tested more myself.
On a fresh emacs -Q
requiring only sage-shell-mode
and evil
, all is fine. I'm trying to analyse what the difference between the two setups are, but it's not so clear.
I'm running Emacs 24.5.1. I'm disabling evil mode in the Sage buffer before relaunching. Then I'm doing the following:
M-x run-sage
2+2<C-j><enter>
C-j
is bound to (electric-newline-and-maybe-indent)
. <enter>
is bound to your (sage-shell:send-input)
.
I'm looking further into whether electric-newline-and-maybe-indent
is the culprit.
OK, got it: the problem is when use-prompt-toolkit
is set to true. Try evaluating the following in an emacs -Q
window:
(add-to-list 'load-path _"<your-path-to-deferred>")_
(add-to-list 'load-path "<your-path-to-sage-shell-mode")
(require 'sage-shell-mode)
(setq sage-shell:use-prompt-toolkit t)
then run the following
M-x sage-shell:run-sage
sage: <C-j><enter>
<sage process quits>
I thought use-prompt-toolkit
was required for sage-shell-mode
to work with ipython 5
, which is why I had it turned on. This seems to be a misunderstanding. When should it be used?
I thought use-prompt-toolkit was required for sage-shell-mode to work with ipython 5, which is why I had it turned on. This seems to be a misunderstanding. When should it be used?
If you are using Sage 7.3 built from the master branch, then you should not turn it on. If you are an arch Linux user and install Sage by pacman
, then probably you should turn it on.
If sage-shell:use-prompt-toolkit
is nil but it should be non-nil, then the following message will be displayed.
To use sage-shell-mode properly, please set `sage-shell:use-prompt-toolkit' to t. And restart the SageMath process.
I use Sage 7.4 beta3 with sage-shell:use-prompt-toolkit
turned on, but I still cannot reproduce this.
I can reproduce this with Sage 7.2 and sage-shell:use-prompt-toolkit
turned on. Probably, you should set it to nil
.
If the output of sage -c 'import IPython; print IPython.version_info[0]'
is less than five, then you should set it to nil
.
OK, indeed: I confused my two installations of Sage, and forgot that my "stable" installation is still at 7.3. Following the docs everything and setting sage-shell:use-prompt-toolkit
as one should, then everything works. Setting sage-shell:use-prompt-toolkit
to t
for Sage 7.3 or earlier seems to be the source of this problem.
I presume that in a reasonably short while, sage-shell::use-prompt-toolkit t
will be the default, at which point it's only retained for backward compatibility with older Sages. So I don't think it's really worth it to try and detect this.
I presume that in a reasonably short while, sage-shell::use-prompt-toolkit t will be the default, at which point it's only retained for backward compatibility with older Sages.
If sage-shell::use-prompt-toolkit
is set to non-nil in older Sages, it causes actual problems (as you described). So I think it is safer to set the default value to nil
.
Maybe I should find a way to warn users if sage-shell:prompt-toolkit
is set to non-nil
but it should be nil
.
IMHO sage-shell:use-prompt-toolkit
should start defaulting to t
once Sage 7.4 has been stable for, say, 6 months. Then the Install documentation should just be modified to say that "If you're running an old Sage 7.3 or older, then you should set sage-shell:use-prompt-toolkit
to nil
".
This could coincide with a "release" of sage-shell-mode
. In fact, it could seem that sage-mode
is not going to be salvaged, in which case we should switch the "official Emacs sage mode" to sage-shell-mode
. The change in default of sage-shell:use-prompt-toolkit
could coincide with this shipping of sage-shell-mode
with Sage.
@jsrndk, I see. I agree with you. I will change the default value.
By the way, we can warn users if they should set sage-shell:use-prompt-toolkit
to nil
, but it is non-nil.
(deferred:$
(deferred:process
(sage-shell:sage-executable)
"-c" "import IPython; print IPython.version_info[0]")
(deferred:nextc it
(lambda (x) (let ((version (string-to-number (sage-shell:trim-right x))))
(when (and (< version 5) sage-shell:use-prompt-toolkit)
(message "Set `sage-shell:use-prompt-toolkit' to `nil'"))))))
I used deferred
because the command sage -c 'import IPython; print IPython.version_info[0]'
takes so much time. I will add a similar code to sage-shell-mode
.
Hmm, but if you are going to run that check every time you start a Sage process anyway, why don't you just run it first and then set the value correctly, and start Sage? Because the two will be run in parallel? Alternatively, could you first start Sage and then run the command inside the living Sage process?
Because the two will be run in parallel?
Yes. To reduce the start up time. I will also add a variable to disable the check.
Alternatively, could you first start Sage and then run the command inside the living Sage process?
It may be possible. But if sage-shell:use-prompt-toolkit
is not correct, something may be broken. So I am not sure.
I use Evil in Emacs which means I'm usually writing in "insert" state and not in "emacs" state.
In the Sage shell, pressing Enter when in Emacs state works as normal. If in insert state, it inserts a newline character (visually at least) and goes to the next line. Switching to Emacs state and then pressing Enter will now evaluate the command and then exit the Sage process: