diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5a96972caa7..9826edfc054 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -5912,6 +5912,22 @@ are also searched. REGEXP is passed to `looking-at' to set | |||
| 5912 | (beginning-of-line) | 5912 | (beginning-of-line) |
| 5913 | (looking-at regexp))))) | 5913 | (looking-at regexp))))) |
| 5914 | 5914 | ||
| 5915 | (defun python-ts-hs-adjust-block-end-fn (block-beg) | ||
| 5916 | "Python-ts-mode specific `hs-adjust-block-end' function for `hs-minor-mode'. | ||
| 5917 | |||
| 5918 | BLOCK-BEG is the beginning position where the hiding will be performed. | ||
| 5919 | |||
| 5920 | This is only used to properly hide the block when there are not closing | ||
| 5921 | parens." | ||
| 5922 | (unless (save-excursion | ||
| 5923 | (goto-char block-beg) | ||
| 5924 | (treesit-thing-at | ||
| 5925 | (1- (point)) | ||
| 5926 | '(or "argument_list" | ||
| 5927 | (and anonymous "\\`[](),[{}]\\'") | ||
| 5928 | "string"))) | ||
| 5929 | (line-end-position))) | ||
| 5930 | |||
| 5915 | 5931 | ||
| 5916 | ;;; Imenu | 5932 | ;;; Imenu |
| 5917 | 5933 | ||
| @@ -7339,21 +7355,24 @@ implementations: `python-mode' and `python-ts-mode'." | |||
| 7339 | #'python-eldoc-function)))) | 7355 | #'python-eldoc-function)))) |
| 7340 | (eldoc-add-command-completions "python-indent-dedent-line-backspace") | 7356 | (eldoc-add-command-completions "python-indent-dedent-line-backspace") |
| 7341 | 7357 | ||
| 7342 | ;; TODO: Use tree-sitter to figure out the block in `python-ts-mode'. | 7358 | (add-to-list |
| 7343 | (dolist (mode '(python-mode python-ts-mode)) | 7359 | 'hs-modes-alist |
| 7344 | (add-to-list | 7360 | `(python-mode |
| 7345 | 'hs-special-modes-alist | 7361 | (start . ,python-nav-beginning-of-block-regexp) |
| 7346 | `(,mode | 7362 | ;; Use the empty string as end regexp so it doesn't default to |
| 7347 | ,python-nav-beginning-of-block-regexp | 7363 | ;; "\\s)". This way parens at end of defun are properly hidden. |
| 7348 | ;; Use the empty string as end regexp so it doesn't default to | 7364 | (end . "") |
| 7349 | ;; "\\s)". This way parens at end of defun are properly hidden. | 7365 | (c-start . "#") |
| 7350 | "" | 7366 | (forward-fn . python-hideshow-forward-sexp-function) |
| 7351 | "#" | 7367 | (find-beg-fn . python-nav-beginning-of-block) |
| 7352 | python-hideshow-forward-sexp-function | 7368 | (find-next-fn . python-hideshow-find-next-block) |
| 7353 | nil | 7369 | (look-start-fn . python-info-looking-at-beginning-of-block))) |
| 7354 | python-nav-beginning-of-block | 7370 | |
| 7355 | python-hideshow-find-next-block | 7371 | (add-to-list |
| 7356 | python-info-looking-at-beginning-of-block))) | 7372 | 'hs-modes-alist |
| 7373 | '(python-ts-mode | ||
| 7374 | (treesit-things . (or defun sexp)) | ||
| 7375 | (adjust-end-fn . python-ts-hs-adjust-block-end-fn))) | ||
| 7357 | 7376 | ||
| 7358 | (setq-local outline-regexp (python-rx (* space) block-start)) | 7377 | (setq-local outline-regexp (python-rx (* space) block-start)) |
| 7359 | (setq-local outline-level | 7378 | (setq-local outline-level |