From 9fc46f1fd9580c19656688e379e146401c19ef66 Mon Sep 17 00:00:00 2001 From: Elías Gabriel Pérez Date: Sun, 9 Nov 2025 09:20:05 +0200 Subject: hideshow: Rework previous changes * lisp/progmodes/hideshow.el (hs-grok-mode-type): Improve 'hs--set-variable'. * lisp/progmodes/python.el (python-base-mode, python-ts-mode): Provide backward-compatibility for older versions. --- lisp/progmodes/python.el | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'lisp/progmodes/python.el') 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'." #'python-eldoc-function)))) (eldoc-add-command-completions "python-indent-dedent-line-backspace") - (setq-local hs-block-start-regexp 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. - (setq-local hs-block-end-regexp "") - (setq-local hs-c-start-regexp "#") - (setq-local hs-forward-sexp-function #'python-hideshow-forward-sexp-function) - (setq-local hs-find-block-beginning-function #'python-nav-beginning-of-block) - (setq-local hs-find-next-block-function #'python-hideshow-find-next-block) - (setq-local hs-looking-at-block-start-predicate #'python-info-looking-at-beginning-of-block) + (if (< emacs-major-version 31) + (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 hs-block-start-regexp 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. + (setq-local hs-block-end-regexp "") + (setq-local hs-c-start-regexp "#") + (setq-local hs-forward-sexp-function #'python-hideshow-forward-sexp-function) + (setq-local hs-find-block-beginning-function #'python-nav-beginning-of-block) + (setq-local hs-find-next-block-function #'python-hideshow-find-next-block) + (setq-local hs-looking-at-block-start-predicate #'python-info-looking-at-beginning-of-block)) (setq-local outline-regexp (python-rx (* space) block-start)) (setq-local outline-level @@ -7437,8 +7452,9 @@ implementations: `python-mode' and `python-ts-mode'." (setq-local forward-sexp-function #'treesit-forward-sexp treesit-sexp-thing 'sexp) - (setq-local hs-treesit-things '(or defun sexp)) - (setq-local hs-adjust-block-end-function #'python-ts-hs-adjust-block-end-fn) + (when (>= emacs-major-version 31) + (setq-local hs-treesit-things '(or defun sexp)) + (setq-local hs-adjust-block-end-function #'python-ts-hs-adjust-block-end-fn)) (setq-local syntax-propertize-function #'python--treesit-syntax-propertize) -- cgit v1.2.1