I want to make a complement to run-python
in python-mode
. Here is my snippet:
(defun dpy-run-python ()
(interactive)
(when (python-shell-get-process)
(delete-process (python-shell-get-process)))
(run-python (python-shell-calculate-command) t)
(python-shell-send-buffer t)
)
Explain:
Each time when I run dpy-run-python
,it kill running python shell if any exists, then create a new process at the same window, which looks like:
However, my code come out error when executing:
I have read the source code of python.el
,it seems like some comint protocols between emacs and python shell process, but I have no idea what should I do.
run-python
in my snippet with the 2nd parat
means a dedicated process. And the python shell in image is a dedicated process in fact.run-python
will pass some special arguments to Python when it runs in a new buffer, but not in an existing buffer. Two suggestions: in part 1 you could not only kill the process but the buffer too; or, if you care about the contents of the buffer, there may be a specialized function you have to call instead ofdelete-process
to tell python mode that you're starting afresh.