OGMGIC
OGMGIC

Reputation: 93

Emacs: starting a new inferior python shell when evaluating buffer

I am working in vanilla Emacs 23 on various python programs, when I evaluate a buffer, an inferior python shell is started as expected and the scripts run fine...

This is all fine, however, when working on multiple (unrelated) projects, the same python instance is used, is there a way I can create a new inferior python shell per source file?

Thanks

Upvotes: 2

Views: 750

Answers (2)

danelliottster
danelliottster

Reputation: 365

When I need a new inferior python shell in emacs and want to specify which python buffers send code to each shell I do the following. This gives me a little more control.

  1. Use the M-x rename-buffer command to set the existing inferior shell buffer name to something like *Python-otherbuff*

  2. (setq-local python-shell-buffer-name "Python-otherbuff") in each buffer which should interact with the old inferior shell.

  3. Use the usual command to create a new inferior python shell (e.g. C-c C-p) which will create a buffer called *Python* which all python buffers will interact with by default.

Upvotes: 2

0x5453
0x5453

Reputation: 13589

I haven't fully tested this, but I think this will work:

(add-hook 'python-mode-hook 
          (lambda ()
            (setq-local python-shell-buffer-name 
                        (format "Python %s" (buffer-file-name)))))

This should cause every buffer to use a different buffer name when launching a python shell. Each python shell buffer with a different name should have its own inferior python process.

Upvotes: 1

Related Questions