diff options
| author | Elías Gabriel Pérez | 2025-10-13 18:45:21 -0600 |
|---|---|---|
| committer | Juri Linkov | 2025-11-04 19:15:10 +0200 |
| commit | 959345f602d9a779875df689bdf0adb2b84be4dc (patch) | |
| tree | 83f5210e8b4c48573859c51e35bf7735b1525aab /lisp/progmodes/python.el | |
| parent | 11860fe936cfbb9dc13ab728e5c9719b7e7721a3 (diff) | |
| download | emacs-959345f602d9a779875df689bdf0adb2b84be4dc.tar.gz emacs-959345f602d9a779875df689bdf0adb2b84be4dc.zip | |
hideshow: Rewrite 'hs-special-modes-alist'
Rewrite the format in 'hs-special-modes-alist' to make easier to
exclude some values, add support for settings inheritance
according to current major mode and parents, and support string
hiding for lisp modes.
Bug#79671
* lisp/progmodes/hideshow.el (hs-modes-alist): New variable.
(hs-special-modes-alist): Mark as obsolete.
(hs-forward-sexp-func, hs-adjust-block-beginning)
(hs-find-block-beginning-func, hs-find-next-block-func)
(hs-looking-at-block-start-p-func): Set default values to nil.
(hs-inside-comment-p): Remove function.
(hs-adjust-block-end, hs-treesit-things): New buffer-local
variables.
(hs-block-positions): Minor updates.
(hs--get-mode-value): New function.
(hs-grok-mode-type): Rewrite.
* lisp/progmodes/f90.el (hs-special-modes-alist):
* lisp/progmodes/fortran.el (hs-special-modes-alist):
* lisp/progmodes/icon.el (icon-mode):
* lisp/progmodes/lua-mode.el (lua-mode):
* lisp/progmodes/python.el (python-base-mode):
* lisp/progmodes/verilog-mode.el (verilog-mode):
* lisp/progmodes/vhdl-mode.el (vhdl-hs-minor-mode): Rewrite
settings.
* lisp/progmodes/python.el (python-ts-hs-adjust-block-end-fn):
New function.
* lisp/treesit.el (treesit-hs-block-end)
(treesit-hs-find-block-beginning, treesit-hs-find-next-block)
(treesit-hs-looking-at-block-start-p): Minor updates.
* doc/emacs/programs.texi (Hideshow):
* etc/NEWS: Document changes.
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 |