emacs python-mode: designate which python shell to send commands to
-
27-04-2021 - |
Frage
A follow up on this question - if I have two python shells running in emacs, how can I designate which shell commands from each python script buffer is sent to? I suspect it has something to do with python-buffer
and python-set-proc
but setting these variables to the name of the shell is apparently not the solution.
Edit: actually since I am using python-mode
rather than loveshack python, it probably does not have to do with python-buffer
and python-set-proc
.
Lösung
In any Python buffer, you can use the variable py-which-bufname
to control which Python shell your code gets sent to when executing it. The variable is buffer-local, so in order to set it to a custom value you'll need to change it from within the buffer by pressing M-:
and entering the following
(setq py-which-bufname "My-Custom-Bufname")
This also makes it easy to quickly create new process buffers: If you set py-which-bufname
to a name for which there is no corresponding process buffer, you can just issue C-c !
to quickly create one.
HTH
Andere Tipps
You can set a new value to python-buffer
.
(defun my-python-set-proc (buffer-name)
(interactive "B")
(setf python-buffer (get-buffer buffer-name))
(python-set-proc))
And then M-xmy-python-set-proc
RET*Python*
RET,
or M-xmy-python-set-proc
RET*Python*<2>
RET.
py-shell-name sets the default, which might be overwritten by command
Should the buffer code contain a shebang specifying pythonVERSION , than this takes precedence over default setting.
You may enforce executing buffer through specific pythonVERSION by calling a command of class py-execute-buffer-pythonVERSION
See menu PyExec, entry Execute buffer ...