Function: python-ts-mode
python-ts-mode is an autoloaded, interactive and byte-compiled
function defined in python.el.gz.
Signature
(python-ts-mode)
Documentation
Major mode for editing Python files, using tree-sitter library.
python-nav-up-list
<backtab> python-indent-dedent-line
C-M-h python-mark-defun
C-M-i completion-at-point
C-M-u python-nav-backward-up-list
C-M-x python-shell-send-defun
C-c < python-indent-shift-left
C-c > python-indent-shift-right
C-c C-b python-shell-send-block
C-c C-c python-shell-send-buffer
C-c C-d python-describe-at-point
C-c C-e python-shell-send-statement
C-c C-f python-eldoc-at-point
C-c C-j imenu
C-c C-l python-shell-send-file
C-c C-p run-python
C-c C-r python-shell-send-region
C-c C-s python-shell-send-string
C-c C-t c python-skeleton-class
C-c C-t d python-skeleton-def
C-c C-t f python-skeleton-for
C-c C-t i python-skeleton-if
C-c C-t m python-skeleton-import
C-c C-t t python-skeleton-try
C-c C-t w python-skeleton-while
C-c C-v python-check
C-c C-z python-shell-switch-to-shell
C-c TAB a python-add-import
C-c TAB f python-fix-imports
C-c TAB r python-remove-import
C-c TAB s python-sort-imports
DEL python-indent-dedent-line-backspace
M-a python-nav-backward-block
M-e python-nav-forward-block
In addition to any hooks its parent mode python-base-mode might have
run, this mode runs the hook python-ts-mode-hook, as the final or
penultimate step during initialization.
Probably introduced at or before Emacs version 29.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
;;;###autoload
(define-derived-mode python-ts-mode python-base-mode "Python"
"Major mode for editing Python files, using tree-sitter library.
\\{python-ts-mode-map}"
:syntax-table python-mode-syntax-table
(when (treesit-ready-p 'python)
(treesit-parser-create 'python)
(setq-local treesit-font-lock-feature-list
'(( comment definition)
( keyword string type)
( assignment builtin constant decorator
escape-sequence number string-interpolation )
( bracket delimiter function operator variable property)))
(setq-local treesit-font-lock-settings python--treesit-settings)
(setq-local imenu-create-index-function
#'python-imenu-treesit-create-index)
(setq-local treesit-defun-type-regexp (rx (or "function" "class")
"_definition"))
(setq-local treesit-defun-name-function
#'python--treesit-defun-name)
(treesit-major-mode-setup)
(setq-local syntax-propertize-function #'python--treesit-syntax-propertize)
(python-skeleton-add-menu-items)
(when python-indent-guess-indent-offset
(python-indent-guess-indent-offset))
(add-to-list 'auto-mode-alist '("\\.py[iw]?\\'" . python-ts-mode))
(add-to-list 'interpreter-mode-alist '("python[0-9.]*" . python-ts-mode))))