3

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.

Community
  • 1
  • 1
hatmatrix
  • 42,883
  • 45
  • 137
  • 231

3 Answers3

2

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-procRET*Python*RET, or M-xmy-python-set-procRET*Python*<2>RET.

Daimrod
  • 4,902
  • 23
  • 25
  • Thanks - it was my mistake that I suggested `python-buffer` and `python-set-proc` as they appear to be relevant variables for loveshack python rather than `python-mode`. – hatmatrix Nov 30 '11 at 21:05
1

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

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
  • Case closed! Thanks - this is exactly what I needed. – hatmatrix Mar 07 '12 at 15:12
  • This variable does not seem to exist anymore. As this question arrived first on my search engine, here is the modern way. The variable is now named `python-shell-buffer-name`. By using `add-file-variable`, you can define a buffer-specific value to this variable with a string, like `"TOTO"`. It will then create a buffer named `*TOTO*` with the python shell. – Lalylulelo Nov 25 '21 at 12:30
0

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 ...

Andreas Röhler
  • 4,804
  • 14
  • 18