[IPython-user] Question about ipython.el
bruno
bruno.chazelas@ias.u-psud...
Fri May 11 04:11:09 CDT 2007
Alexander Schmolck a écrit :
> bruno <bruno.chazelas@ias.u-psud.fr> writes:
>
>
>> I am quite a newbie to python and it is the only sure way I found to be sure
>> my modifications are taken into account.
>>
>> As a consequence I would like to add the following function to emacs :
>> kill ipython and restart it in a single key-stroke. I have begun to
>> learn Elisp to achieve this aim.
>> I nearly managed to do so but my attempt fails very near to completion. I am
>> seeking for help.
>>
>> here is the code I added to my .emacs :
>>
>> (defun py-shell-stop-and-restart ()
>> "Stop the current python process"
>> (interactive)
>> (setq oldbuf (current-buffer))
>> (setq oldwindow (selected-window))
>> (if (get-process "Python")
>> (progn (kill-process "Python")
>> (message "Python Killed"))
>> (message "Python is not running Yet"))
>> (select-window oldwindow)
>> (switch-to-buffer oldbuf)
>> (py-shell)
>> )
>> (define-key py-mode-map "\C-c;" 'py-shell-stop-and-restart)
>>
>> This codes properly kills the python interpreter if it is running, but
>> il fails to restart it. I don't understand why. It should restart via
>> the (py-shell-start) function. More strange the (py-shell) works when
>> the ipython shell is not working and thus cannot be killed.
>>
>> any one has an idea ?
>>
>
> Not sure what's going on (my first, and possibly completely wrong, guess would
> be the killing isn't finished by the time py-shell is called, but the process
> handling etc. in emacs is not presently mentally available to me and I've got
> no time to look it up again right now). Have you tried adding a delay?
>
>
I have just tried and you were exactly right ! a line :
(sleep-for 0.1) before the (py-shell) did the trick. I suppose it is an
awful hack, but it works fine for me.
Thanks a lot
Bruno
> Maybe a quick fix would be to try to define a keyboard macro to do something
> like "C-d and yes and M-x py-shell" roughly like so:
>
> C-x ( C-d y RET M-x py-shell C-x )
>
> Then test it by running it with C-x e, and if it works save it -- best resort
> to your emacs manual, but here's some doc for an old emacs version:
>
> <http://www.delorie.com/gnu/docs/emacs/emacs_489.html>
>
> if everything fails comp.emacs might prove hepful.
>
>
>> Thanks in advance and anyway thanks for the nice softwares
>>
>> Bruno Chazelas
>>
>
> 'as
>
More information about the IPython-user
mailing list