Problem with Emacs mode, at start only
alex at somewhere.round.here
Fri Feb 18 05:24:54 CET 2000
Ah, it seems that I misread your post the first time around. I have a
different problem, where if I type C-c C-c when the *Python* buffer
hasn't been created, the script runs in non-interactive mode, which
isn't usually what I want. So I read "I do not have `*Python*' window
initialised" and jumped in and solved my own problem.
Well, thanks for responding to my misunderstanding so graciously.
(Sorry for misunderstanding you, too, Barry.)
I think I figured out what is happening. Suppose the python process in
the *Python* buffer has died. When you execute something like
(progn (save-window-excursion (py-shell)) (py-execute-buffer)),
py-comint-output-filter-function gets executed when the python startup
is completed. I think the problem with that is, the first thing it sees
is the '>>>' prompt, so it thinks that it is being called because a
subjob has just been finished by the interpreter. As a result, it
checks py-file-queue, and it finds there the file you were trying to
execute in the first place. Thinking that this file has just been
executed, it deletes it. Meanwhile, py-execute-file has been told by
py-execute-region to execute the file. It tells the python interpreter
to execute the temporary copy that has just been deleted from the disk.
Something like the following seems to get around that problem. It waits
until the initial prompt has been written before giving control to
py-execute-buffer. That means that the '## Working on region in
file...' message from py-execute-region is written afterward, and so
py-comint-output-filter-function doesn't see the '>>>' at the end of the
buffer next time around and get the wrong idea. Probably the real fix
is to rearrange the way these processes communicate in a slightly more
robust way, but I'll leave that to someone who knows what they're doing.
(define-key py-mode-map "\C-c\C-c"
'(lambda () (interactive)
(not (looking-at ">>>")))))
More information about the Python-list