Opened 10 years ago

Closed 5 years ago

#10504 closed defect (fixed)

Sage in emacs fails for some functions

Reported by: fmaltey Owned by: iandrus
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: user interface Keywords:
Cc: Merged in:
Authors: Ivan Andrus Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: u/iandrus/dumb-term-no-autoindent (Commits) Commit: 4c085996f3516d661f2d0350b43a084b48359660
Dependencies: Stopgaps:

Description

I can define this function in a xterm or in a emacs buffer linked to the sage shell buffer.

I get an error when I type it in the *Sage Inferior* mode.

def test (n) :
  if n==2 :
    return 2
  else :
    return 3

In emacs I get the error around the "else :" line

------------------------------------------------
  File "<ipython console>", line 4
    se :
      ^^

SyntaxError: invalid syntax

sage:     return 3

-----------------------------------------------------
  File "<ipython console>", line 1
SyntaxError: 'return' outside function (<ipython console>, line 1)

This error isn't in the sage*.el mode because I get the same problem in any shell buffer that I run with [Alt-x] shell [return] sage [return].

Change History (8)

comment:1 Changed 9 years ago by iandrus

  • Owner changed from was to iandrus

FWIW typing it in without indenting works:

sage: def test(n) :
....: if n==2 :
....: return 2
....: else :
....: return 3
....: 
sage: test(2)
2

But indenting it "manually" causes problems:

def test (n) :
....:   if n==2 :
....:     return 2
....:   else :
------------------------------------------------------------
   File "<ipython console>", line 4
     se :
      ^
SyntaxError: invalid syntax

In a shell, the proper indentation is added automatically i.e. the transcript below resulted from typing exactly the same characters as the first:

sage: def test(n) :
....:     if n==2:
....:         return 2
....:     else:
....:         return 3
....:     
sage: test(3)
3

It's probably related to the TERM environment variable (set to "dumb" inside emacs), but I don't know where this is handled in Sage (probably ipython).

comment:2 Changed 8 years ago by iandrus

This can be done by adding to main() in ipy_user_conf.py:

    import os
    if os.environ['TERM'] == 'dumb':
        o.autoindent = 0

I plan to wait until after #12167 to fix this.

comment:3 Changed 7 years ago by iandrus

  • Authors set to Ivan Andrus
  • Branch set to u/iandrus/dumb-term-no-autoindent
  • Commit set to 4c085996f3516d661f2d0350b43a084b48359660
  • Status changed from new to needs_review

New commits:

4c08599Don't autoindent if the terminal is dumb (e.g. in Emacs) since it won't work

comment:4 follow-up: Changed 6 years ago by vbraun

Does it actually merge?

Also, wouldn't the same hold for plain IPython? Maybe its better to fix the default upstream?

comment:5 in reply to: ↑ 4 Changed 6 years ago by iandrus

  • Milestone set to sage-duplicate/invalid/wontfix

Replying to vbraun:

Does it actually merge?

Sorry, I must have tried merging it when I had an old branch checked out.

Also, wouldn't the same hold for plain IPython? Maybe its better to fix the default upstream?

Yes, you are right. It probably should be fixed upstream. You can close this ticket.

comment:6 Changed 6 years ago by vbraun

Can you link to the upstream ticket when you open it? IPython uses github as issue tracker.

comment:7 Changed 5 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

let us close that

comment:8 Changed 5 years ago by vbraun

  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.