sudo
sudo

Reputation: 647

ipython emacs IndentationError

Really annoying problem in ipython prompt in emacs:

In [128]: if 1==1:
   .....:     print "yes"
   .....: else:    
   .....:     print "no"
   .....:     
IndentationError: unindent does not match any outer indentation level

It looks perfectly aligned to me, not sure what trigger the error. No such problem when I do this in terminal.

Upvotes: 5

Views: 873

Answers (2)

Ivan Andrus
Ivan Andrus

Reputation: 5301

You might try toggling autoindent with

%autoindent

since I think that has caused the problem for me before.

You can change this permanently using ipython's customization. After the proper imports (see the link) the following should work in ipy_user_conf.py:

# Emacs sets the term to dumb so we can distinguish that way
if os.environ['TERM'] == 'dumb':
    ip.options.autoindent = 0

Upvotes: 3

Greg E.
Greg E.

Reputation: 2742

Yeah, this is strange. On my end, using the standard python interpreter within an emacs shell works fine when evaluating your code, but using ipython fails. If you're using the python-mode.el package, you probably need to install ipython.el to get proper ipython support. OTOH, if you're using the python.el that normally ships with emacs, you may have to switch to the standard python interpreter (I believe ipython.el is only intended for use with the third-party python-mode.el package, not the python.el that emacs uses by default).

Upvotes: 0

Related Questions