Variable: python-base-mode-map

python-base-mode-map is a variable defined in python.el.gz.

Value


Documentation

Keymap for python-base-mode.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
;;;###autoload
(define-derived-mode python-base-mode prog-mode "Python"
  "Generic major mode for editing Python files.

This is a generic major mode intended to be inherited by
concrete implementations.  Currently there are two concrete
implementations: `python-mode' and `python-ts-mode'."
  (setq-local tab-width 8)
  (setq-local indent-tabs-mode nil)

  (setq-local comment-start "# ")
  (setq-local comment-start-skip "#+\\s-*")

  (setq-local parse-sexp-lookup-properties t)
  (setq-local parse-sexp-ignore-comments t)

  (setq-local forward-sexp-function python-forward-sexp-function)

  (setq-local indent-line-function #'python-indent-line-function)
  (setq-local indent-region-function #'python-indent-region)
  ;; Because indentation is not redundant, we cannot safely reindent code.
  (setq-local electric-indent-inhibit t)
  (setq-local electric-indent-chars
              (cons ?: electric-indent-chars))

  ;; Add """ ... """ pairing to electric-pair-mode.
  (add-hook 'post-self-insert-hook
            #'python-electric-pair-string-delimiter 'append t)

  (setq-local paragraph-start "\\s-*$")
  (setq-local fill-paragraph-function #'python-fill-paragraph)
  (setq-local normal-auto-fill-function #'python-do-auto-fill)

  (setq-local beginning-of-defun-function #'python-nav-beginning-of-defun)
  (setq-local end-of-defun-function #'python-nav-end-of-defun)

  (add-hook 'completion-at-point-functions
            #'python-completion-at-point nil 'local)

  (add-hook 'post-self-insert-hook
            #'python-indent-post-self-insert-function 'append 'local)

  (setq-local add-log-current-defun-function
              #'python-info-current-defun)

  (setq-local skeleton-further-elements
              '((abbrev-mode nil)
                (< '(backward-delete-char-untabify (min python-indent-offset
                                                        (current-column))))
                (^ '(- (1+ (current-indentation))))))

  (with-no-warnings
    ;; suppress warnings about eldoc-documentation-function being obsolete
    (if (null eldoc-documentation-function)
        ;; Emacs<25
        (setq-local eldoc-documentation-function #'python-eldoc-function)
      (if (boundp 'eldoc-documentation-functions)
          (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t)
        (add-function :before-until (local 'eldoc-documentation-function)
                      #'python-eldoc-function))))

  ;; TODO: Use tree-sitter to figure out the block in `python-ts-mode'.
  (dolist (mode '(python-mode python-ts-mode))
    (add-to-list
     'hs-special-modes-alist
     `(,mode
       ,python-nav-beginning-of-block-regexp
       ;; Use the empty string as end regexp so it doesn't default to
       ;; "\\s)".  This way parens at end of defun are properly hidden.
       ""
       "#"
       python-hideshow-forward-sexp-function
       nil
       python-nav-beginning-of-block
       python-hideshow-find-next-block
       python-info-looking-at-beginning-of-block)))

  (setq-local outline-regexp (python-rx (* space) block-start))
  (setq-local outline-level
              (lambda ()
                "`outline-level' function for Python mode."
                (1+ (/ (current-indentation) python-indent-offset))))

  (setq-local prettify-symbols-alist python-prettify-symbols-alist)

  (make-local-variable 'python-shell-internal-buffer)

  (add-hook 'flymake-diagnostic-functions #'python-flymake nil t))