[IPython-user] the edit magic saga continues...
danny_shevitz at yahoo.com
Tue May 17 17:25:33 CDT 2005
I now have a semi-complete resolution to my editor magic woes, and
thought I would relate them.
I am using TextPad on Windoze. The problem turned out to be that
TextPad was returning from os.system before the file was actually
edited. Fernando suggested I create my own editor hook which waits
correctly. Presumable this would use one of the os.spawn variants or
such. I'm sure this would work, but is not the way I solved it. I went
with the sleazy workaround.
The os.system command passes the string to a command shell. In my case
that string was "fullpath\texpad.exe tempfile". When TextPad creates a
file from the command line it throws up a dialog asking whether it is
ok to create the file. I have posted to a TextPad forum to see if there
is a silent way to open the program, but have not heard back.
Now here is what I found out that is goofy. TextPad has two modes of
operation, either it runs in a single instance or multiple instances. I
was running in the single instance mode, in other words if you double
click on a file or open a file from the command line (as ipython does),
then the file always opens in the running instance of the program and
does not run a new TextPad instance.
The funky thing is that when running in single instance mode, with
TextPad already open, when I clicked the dialog box to say it was ok to
create the file, that is when os.system was returning. NOT after the
file was closed. Somehow the fact that TextPad was already open changed
the behavior of the dialog box.
So the workaround turned out to be to set my environment variable to
D:/Progra~1/TextPa~1/TextPad.exe -m. The -m flag forces a new instance
of TextPad to open despite my global setting. Note I had to use the Dos
8.3 name in order to get the quoting correct. I cheated and put a
command line flag in the EDITOR environment variable and treated it
like part of the filename.
That's it. It's weird and I don't know why a single instance notepad
sends an operating system process exit after opening a dialog box, but
that is what's happening.
--- Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> danny shevitz wrote:
> > So after stepping through the code, magic edit was working. Then it
> > stopped working again. I have debugged some more and have further
> > trapped the problem. What seems to be the problem is that in
> > hooks.editor the
> > os.system call (line 72) is not waiting for the editor to close the
> > process before returning. In other words os.system(editor)is
> > immediately, before the editor is closed, so I always get empty
> > returned. Any changes to the temp file are never recorded.
> > Any ideas how to proceed from here...
> Good job. Have a look at the docstring for hooks.py, which indicates
> how to
> define your own editor hook. You'll have to write a function with
> the same
> signature, whic waits correctly under win32. You can then set this
> as your
> own hook in your config file.
> The default hook is a very basic one, whcih works OK under *nix and
> for notepad under win32, but it has very little smarts. That's why
> the hooks
> mechanism was put in place: so users could define arbitrarily
> editor handling functions.
> I hope this helps,
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
More information about the IPython-user