aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el38
1 files changed, 27 insertions, 11 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 12557aecf4d..c4cf7ec46cf 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -7355,15 +7355,30 @@ implementations: `python-mode' and `python-ts-mode'."
7355 #'python-eldoc-function)))) 7355 #'python-eldoc-function))))
7356 (eldoc-add-command-completions "python-indent-dedent-line-backspace") 7356 (eldoc-add-command-completions "python-indent-dedent-line-backspace")
7357 7357
7358 (setq-local hs-block-start-regexp python-nav-beginning-of-block-regexp) 7358 (if (< emacs-major-version 31)
7359 ;; Use the empty string as end regexp so it doesn't default to 7359 (dolist (mode '(python-mode python-ts-mode))
7360 ;; "\\s)". This way parens at end of defun are properly hidden. 7360 (add-to-list
7361 (setq-local hs-block-end-regexp "") 7361 'hs-special-modes-alist
7362 (setq-local hs-c-start-regexp "#") 7362 `(,mode
7363 (setq-local hs-forward-sexp-function #'python-hideshow-forward-sexp-function) 7363 ,python-nav-beginning-of-block-regexp
7364 (setq-local hs-find-block-beginning-function #'python-nav-beginning-of-block) 7364 ;; Use the empty string as end regexp so it doesn't default to
7365 (setq-local hs-find-next-block-function #'python-hideshow-find-next-block) 7365 ;; "\\s)". This way parens at end of defun are properly hidden.
7366 (setq-local hs-looking-at-block-start-predicate #'python-info-looking-at-beginning-of-block) 7366 ""
7367 "#"
7368 python-hideshow-forward-sexp-function
7369 nil
7370 python-nav-beginning-of-block
7371 python-hideshow-find-next-block
7372 python-info-looking-at-beginning-of-block)))
7373 (setq-local hs-block-start-regexp python-nav-beginning-of-block-regexp)
7374 ;; Use the empty string as end regexp so it doesn't default to
7375 ;; "\\s)". This way parens at end of defun are properly hidden.
7376 (setq-local hs-block-end-regexp "")
7377 (setq-local hs-c-start-regexp "#")
7378 (setq-local hs-forward-sexp-function #'python-hideshow-forward-sexp-function)
7379 (setq-local hs-find-block-beginning-function #'python-nav-beginning-of-block)
7380 (setq-local hs-find-next-block-function #'python-hideshow-find-next-block)
7381 (setq-local hs-looking-at-block-start-predicate #'python-info-looking-at-beginning-of-block))
7367 7382
7368 (setq-local outline-regexp (python-rx (* space) block-start)) 7383 (setq-local outline-regexp (python-rx (* space) block-start))
7369 (setq-local outline-level 7384 (setq-local outline-level
@@ -7437,8 +7452,9 @@ implementations: `python-mode' and `python-ts-mode'."
7437 (setq-local forward-sexp-function #'treesit-forward-sexp 7452 (setq-local forward-sexp-function #'treesit-forward-sexp
7438 treesit-sexp-thing 'sexp) 7453 treesit-sexp-thing 'sexp)
7439 7454
7440 (setq-local hs-treesit-things '(or defun sexp)) 7455 (when (>= emacs-major-version 31)
7441 (setq-local hs-adjust-block-end-function #'python-ts-hs-adjust-block-end-fn) 7456 (setq-local hs-treesit-things '(or defun sexp))
7457 (setq-local hs-adjust-block-end-function #'python-ts-hs-adjust-block-end-fn))
7442 7458
7443 (setq-local syntax-propertize-function #'python--treesit-syntax-propertize) 7459 (setq-local syntax-propertize-function #'python--treesit-syntax-propertize)
7444 7460