Function: run-python
run-python is an autoloaded, interactive and byte-compiled function
defined in python.el.gz.
Signature
(run-python &optional CMD DEDICATED SHOW)
Documentation
Run an inferior Python process.
Argument CMD defaults to python-shell-calculate-command return
value. When called interactively with prefix-arg, it allows
the user to edit such value and choose whether the interpreter
should be DEDICATED to the current buffer or project. When
numeric prefix arg is other than 0 or 4 do not SHOW.
For a given buffer and same values of DEDICATED, if a process is already running for it, it will do nothing. This means that if the current buffer is using a global process, the user is still able to switch it to use a dedicated one.
Runs the hook inferior-python-mode-hook after
comint-mode-hook is run. (Type C-h m (describe-mode) in the
process buffer for a list of commands.)
Probably introduced at or before Emacs version 29.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
;;;###autoload
(defun run-python (&optional cmd dedicated show)
"Run an inferior Python process.
Argument CMD defaults to `python-shell-calculate-command' return
value. When called interactively with `prefix-arg', it allows
the user to edit such value and choose whether the interpreter
should be DEDICATED to the current buffer or project. When
numeric prefix arg is other than 0 or 4 do not SHOW.
For a given buffer and same values of DEDICATED, if a process is
already running for it, it will do nothing. This means that if
the current buffer is using a global process, the user is still
able to switch it to use a dedicated one.
Runs the hook `inferior-python-mode-hook' after
`comint-mode-hook' is run. (Type \\[describe-mode] in the
process buffer for a list of commands.)"
(interactive
(if current-prefix-arg
(list
(read-shell-command "Run Python: " (python-shell-calculate-command))
(alist-get (car (read-multiple-choice "Make dedicated process?"
'((?b "to buffer")
(?p "to project")
(?n "no"))))
'((?b . buffer) (?p . project)))
(= (prefix-numeric-value current-prefix-arg) 4))
(list (python-shell-calculate-command)
python-shell-dedicated
t)))
(let* ((project (and (eq 'project dedicated)
(featurep 'project)
(project-current t)))
(default-directory (if project
(project-root project)
default-directory))
(buffer (python-shell-make-comint
(or cmd (python-shell-calculate-command))
(python-shell-get-process-name dedicated)
show)))
(get-buffer-process buffer)))