Function: inferior-python-mode

inferior-python-mode is an interactive and byte-compiled function defined in python.el.gz.

Signature

(inferior-python-mode)

Documentation

Major mode for Python inferior process.

Runs a Python interpreter as a subprocess of Emacs, with Python I/O through an Emacs buffer. Variables python-shell-interpreter and python-shell-interpreter-args control which Python interpreter is run. Variables python-shell-prompt-regexp, python-shell-prompt-output-regexp, python-shell-prompt-block-regexp, python-shell-font-lock-enable, python-shell-completion-setup-code, python-eldoc-setup-code, python-ffap-setup-code can customize this mode for different Python interpreters.

This mode resets comint-output-filter-functions locally, so you may want to re-add custom functions to it using the inferior-python-mode-hook.

You can also add additional setup code to be run at initialization of the interpreter via python-shell-setup-codes variable.

(Type C-h m (describe-mode) in the process buffer for a list of commands.)

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(define-derived-mode inferior-python-mode comint-mode "Inferior Python"
  "Major mode for Python inferior process.
Runs a Python interpreter as a subprocess of Emacs, with Python
I/O through an Emacs buffer.  Variables `python-shell-interpreter'
and `python-shell-interpreter-args' control which Python
interpreter is run.  Variables
`python-shell-prompt-regexp',
`python-shell-prompt-output-regexp',
`python-shell-prompt-block-regexp',
`python-shell-font-lock-enable',
`python-shell-completion-setup-code',
`python-eldoc-setup-code',
`python-ffap-setup-code' can
customize this mode for different Python interpreters.

This mode resets `comint-output-filter-functions' locally, so you
may want to re-add custom functions to it using the
`inferior-python-mode-hook'.

You can also add additional setup code to be run at
initialization of the interpreter via `python-shell-setup-codes'
variable.

\(Type \\[describe-mode] in the process buffer for a list of commands.)"
  (when python-shell--parent-buffer
    (python-util-clone-local-variables python-shell--parent-buffer))
  (setq-local indent-tabs-mode nil)
  ;; Users can interactively override default values for
  ;; `python-shell-interpreter' and `python-shell-interpreter-args'
  ;; when calling `run-python'.  This ensures values let-bound in
  ;; `python-shell-make-comint' are locally set if needed.
  (setq-local python-shell-interpreter
              (or python-shell--interpreter python-shell-interpreter))
  (setq-local python-shell-interpreter-args
              (or python-shell--interpreter-args python-shell-interpreter-args))
  (setq-local python-shell--prompt-calculated-input-regexp nil)
  (setq-local python-shell--block-prompt nil)
  (setq-local python-shell--prompt-calculated-output-regexp nil)
  (python-shell-prompt-set-calculated-regexps)
  (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp)
  (setq-local comint-prompt-read-only t)
  (setq mode-line-process '(":%s"))
  (setq-local comint-output-filter-functions
              '(ansi-color-process-output
                python-shell-comint-watch-for-first-prompt-output-filter
                comint-watch-for-password-prompt))
  (setq-local comint-highlight-input nil)
  (setq-local compilation-error-regexp-alist
              python-shell-compilation-regexp-alist)
  (setq-local scroll-conservatively 1)
  (add-hook 'completion-at-point-functions
            #'python-shell-completion-at-point nil 'local)
  (define-key inferior-python-mode-map "\t"
    #'python-shell-completion-complete-or-indent)
  (make-local-variable 'python-shell-internal-last-output)
  (when python-shell-font-lock-enable
    (python-shell-font-lock-turn-on))
  (compilation-shell-minor-mode 1)
  (python-pdbtrack-setup-tracking))