Strange behavior with ipython in Emacs
I'm having a small problem using ipython as my python interpreter with python-mode.el. everything functionally works, but pressing RET jumps ahead two lines (whether开发者_运维问答 I've entered an expression or not) and the auto-indent for function definitions is strange. This is what it looks like:
In [164]: a = 1
In [165]:
In [166]: a + 3
Out[166]: 4
In [167]:
In [168]: def nine():
.....: .....: return 4+5
.....:
In [169]:
In [170]:
There should only be one .....: on the 'return' line. I suspect some indent/newline function in ipython.el or python-mode.el is being called twice somehow. (I don't really know elisp but this may be the issue that gets me into it).
When I do 'M-x ansi-term RET ipython' it works as expected, but this is not ideal because sending code from other files, debugging, etc. don't work.
I can imagine two ways to fix this: either figure out how my setup is causing the double indents/newlines and fix that, or somehow change the default python interpreter from ipython.el to ipython in ansi-term while still preserving the ability to send code and debug.
Any advice on where to start with these is appreciated.
You could check your binding for RET in a Python buffer (M-x describe-bindings) and then go from there. For me it is bound to newline. Click on the bound function or use M-x describe-function to look for the definition of the bound function.
OK I figured this out in the course of porting the .emacs from my Ubuntu work machine to my MacBook.
First, I commented out the following lines from my .emacs:
(defadvice comint-send-input (around block-comint-formatting activate)
(if (string= (buffer-name) "*Python*")
(letf (((symbol-function 'add-text-properties) (lambda (x y z) nil)))
ad-do-it))
ad-do-it)
Which got rid of the double newline thing. I also added
(define-key py-shell-map "\C-j" 'ipython-send-and-indent)
to then end of my ipython.el so I could use it then same way as in python-mode.
M-x ipython RET
is all you need with current python-mode.el
http://launchpad.net/python-mode
It's not perfect with ipython though, you might help sending bug-reports
精彩评论