Problem with Emacs mode, at start only

François Pinard pinard at iro.umontreal.ca
Thu Feb 17 20:54:53 EST 2000


Alex <alex at somewhere.round.here> writes:

> Hi, Francois.  Adding something like the following code to your .emacs
> file might go some way to solving your problem.  Actually, it's been a bit
> of a pain for me, too, but I didn't realize it until I read your post.  :)

> (add-hook 'python-mode-hook '(lambda ()
> 			       (save-window-excursion
> 				 (py-shell)
> 				 (local-unset-key "\C-c\C-c")
> 				 (local-set-key "\C-c\C-s"
> 						'comint-interrupt-subjob))))

Thanks a lot.  I put this in `.emacs', and things are already nicer! :-)

> [...] You will still have to switch to the python shell in order see
> the results of executing your code, though.

Good idea.  I made it automatic this way:


(defadvice py-execute-buffer (before display-py-shell-for-buffer activate)
  (let ((buffer (get-buffer "*Python*")))
    (when buffer
      (save-excursion
	(pop-to-buffer buffer)))))

(defadvice py-execute-region (before display-py-shell-for-region activate)
  (let ((buffer (get-buffer "*Python*")))
    (when buffer
      (save-excursion
	(pop-to-buffer buffer)))))


To be complete, I guess I should also learn how to test if the Python
process is active, and avoid popping its buffer when it is not.  Better
might be to find a way for re-activating the Python process on the fly.
Why would Python die, now that `C-c C-c' has been rebound to `C-c C-s'?
Hmph!  It still happens, whenever I execute `sys.exit(N)' in a script.
Nevertheless, the light is brighter already.  Thanks for having helped me!

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list