[IPython-user] using with emacs
fperez.net at gmail.com
Sat Jun 3 20:28:16 CDT 2006
On 6/3/06, Stefan van der Walt <stefan at sun.ac.za> wrote:
> On Sat, Jun 03, 2006 at 07:03:45PM -0600, Fernando Perez wrote:
> > On 6/3/06, Fernando Perez <fperez.net at gmail.com> wrote:
> > > One more thing. I have these two in my emacs config:
> > >
> > > (require 'ansi-color)
> > > (ansi-color-for-comint-mode-on)
> > >
> > > Do they help?
> > >
> > > Perhaps we should include them /inside/ ipython.el...
> > Well, ipython.el does include them already...
> > But I do see a difference if I comment them out in shell emacs
> > buffers: 'ls --color' gives me all sorts of garbage without them, and
> > produces correctly colored output when they are active (tested in both
> > emacs and xemacs).
> You are right -- I got excited too soon. This *does* fix my shell,
> which is great. But I can still reproduce last week's problem:
> 1. $ emacs /tmp/blah.py where blah.py is empty
> 2. type "123"
> 3. type C-c C-c
> Then I see a screen full of ansi garbage (irrespective of whether I
> have ansi settings in .emacs). If, however, I first start ipython
> using C-c !, and then do C-c C-c, it works fine.
Ah, I see it now. I must have misunderstood your original
description. I suspect I know the reason, but I don't know enough
elisp to fix it. I'd never seen the problem, b/c I'm always in the
habit (when I use emacs with an ipython buffer) of opening the ipython
session first with C-c !.
Here's the cause of the problem:
MR Buffer Size Mode File
-- ------ ---- ---- ----
.* "*Python Output*" 519 Fundamental
* blah.py 3 Python /tmp/blah.py
* *Python* 507 Comint
The buffer emacs creates to run your file with C-c C-c /when the
python process hasn't been started/ is a plain 'Fundamental' buffer,
not a comint one. That's a plain text buffer, which doesn't
understand ANSI escapes at all.
The fix would require either
a. Chaning the behavior of C-c to fire ipython with -colors NoColor
when opening a new one in a Fundamental buffer
b. Figuring out how to force ANSI filter in a Fundamental buffer
c. Opening the ipython process in a comint buffer whose subprocess
closes up instead of a Fundamental one.
I don't know enought about emacs internals to say which approach (if
any) is the correct solution, let alone to implement it. Patches
So for now, just develop a new habit: use C-c ! first anytime you plan
on using ipython inside emacs :)
More information about the IPython-user