5

I just upgraded emacs to 25.3. Before the upgrade when I opened a Python shell, it would ask me whether I wanted a 'dedicated' shell (for the buffer I was in), to which I usually replied 'yes'. Now, I do not have the option. I want a dedicated process (the opposite of this question).

I searched the Python options, and didn't see anything that looked promising. Does the 'flying circus' python mode have support for multiple python shells? If not, does anyone know where I can find a version of python mode that works with Emacs 25, and has this functionality?

1 Answer 1

7

OK, so I figured this out (thanks largely to this answer). Now, rather than simply typing C-c C-p, I use C-u C-c C-p to get the options of specifying the Python command I want, and to select a dedicated interpreter.

Because I use dedicated shells so often, I created this fn:

(defun my-python-start-or-switch-repl (&optional msg)
  "Start and/or switch to the REPL."
  (interactive "p")
  (if (python-shell-get-process)
      (python-shell-switch-to-shell)
    (progn
      (run-python (python-shell-calculate-command) t t)
      (python-shell-switch-to-shell)
      )
    )
  )

And mapped it to C-c ! with:

(add-hook 'python-mode-hook
          (lambda () (define-key python-mode-map (kbd "C-c !") 'my-python-start-or-switch-repl))
          )

Now C-c ! either opens the shell for the current buffer, or opens a new dedicated python shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.