aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-02-11 19:42:33 +0200
committerJuri Linkov2025-02-11 19:42:33 +0200
commit58c09c3d36075c3a1a9f178fd8ee019309e6f403 (patch)
tree0df0c17c7875f2d4e2d5a8416cdcf19c5e36a180
parent3e699b3047af70bc8d30e21b295b98dbd6797e9c (diff)
downloademacs-58c09c3d36075c3a1a9f178fd8ee019309e6f403.tar.gz
emacs-58c09c3d36075c3a1a9f178fd8ee019309e6f403.zip
Improve outline-predicate of ts-modes (bug#74448)
* lisp/progmodes/c-ts-mode.el (c-ts-mode--outline-predicate): Simplify since 'treesit-outline-search' was fixed in 302274b1862. Use 'treesit-parent-until' to handle the case with "pointer_declarator". * lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--outline-predicate): Add "block_sequence_item".
-rw-r--r--lisp/progmodes/c-ts-mode.el13
-rw-r--r--lisp/textmodes/yaml-ts-mode.el5
2 files changed, 8 insertions, 10 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index c5bf135e286..0396ddc2c8c 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -1041,14 +1041,11 @@ Return nil if NODE is not a defun node or doesn't have a name."
1041 1041
1042(defun c-ts-mode--outline-predicate (node) 1042(defun c-ts-mode--outline-predicate (node)
1043 "Match outlines on lines with function names." 1043 "Match outlines on lines with function names."
1044 (or (when-let* ((decl (treesit-node-child-by-field-name 1044 (or (and (equal (treesit-node-type node) "function_declarator")
1045 (treesit-node-parent node) "declarator")) 1045 ;; Handle the case when "function_definition" is
1046 (node-pos (treesit-node-start node)) 1046 ;; not an immediate parent of "function_declarator"
1047 (decl-pos (treesit-node-start decl)) 1047 ;; but there is e.g. "pointer_declarator" between them.
1048 (eol (save-excursion (goto-char node-pos) (line-end-position)))) 1048 (treesit-parent-until node "function_definition"))
1049 (and (equal (treesit-node-type decl) "function_declarator")
1050 (<= node-pos decl-pos)
1051 (< decl-pos eol)))
1052 ;; DEFUNs in Emacs sources. 1049 ;; DEFUNs in Emacs sources.
1053 (and c-ts-mode-emacs-sources-support 1050 (and c-ts-mode-emacs-sources-support
1054 (c-ts-mode--emacs-defun-p node)))) 1051 (c-ts-mode--emacs-defun-p node))))
diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index 7a5132634ca..72285d570f1 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -151,8 +151,9 @@ Return nil if there is no name or if NODE is not a defun node."
151 151
152(defun yaml-ts-mode--outline-predicate (node) 152(defun yaml-ts-mode--outline-predicate (node)
153 "Limit outlines to top-level mappings." 153 "Limit outlines to top-level mappings."
154 (when (equal (treesit-node-type node) "block_mapping_pair") 154 (let ((regexp (rx (or "block_mapping_pair" "block_sequence_item"))))
155 (not (treesit-parent-until node treesit-outline-predicate)))) 155 (when (string-match-p regexp (treesit-node-type node))
156 (not (treesit-parent-until node regexp)))))
156 157
157;;;###autoload 158;;;###autoload
158(define-derived-mode yaml-ts-mode text-mode "YAML" 159(define-derived-mode yaml-ts-mode text-mode "YAML"