]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve outline-predicate of ts-modes (bug#74448)
authorJuri Linkov <juri@linkov.net>
Tue, 11 Feb 2025 17:42:33 +0000 (19:42 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 12 Feb 2025 10:49:16 +0000 (11:49 +0100)
* 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".

(cherry picked from commit 58c09c3d36075c3a1a9f178fd8ee019309e6f403)

lisp/progmodes/c-ts-mode.el
lisp/textmodes/yaml-ts-mode.el

index c5bf135e286d7d894a7041b6c13ccbbd9cf45e14..0396ddc2c8c6f32f37509907641fca3cf4d3d2fb 100644 (file)
@@ -1041,14 +1041,11 @@ Return nil if NODE is not a defun node or doesn't have a name."
 
 (defun c-ts-mode--outline-predicate (node)
   "Match outlines on lines with function names."
-  (or (when-let* ((decl (treesit-node-child-by-field-name
-                         (treesit-node-parent node) "declarator"))
-                  (node-pos (treesit-node-start node))
-                  (decl-pos (treesit-node-start decl))
-                  (eol (save-excursion (goto-char node-pos) (line-end-position))))
-        (and (equal (treesit-node-type decl) "function_declarator")
-             (<= node-pos decl-pos)
-             (< decl-pos eol)))
+  (or (and (equal (treesit-node-type node) "function_declarator")
+           ;; Handle the case when "function_definition" is
+           ;; not an immediate parent of "function_declarator"
+           ;; but there is e.g. "pointer_declarator" between them.
+           (treesit-parent-until node "function_definition"))
       ;; DEFUNs in Emacs sources.
       (and c-ts-mode-emacs-sources-support
            (c-ts-mode--emacs-defun-p node))))
index 7a5132634cacc27b4b8567487566f4cc31c6d8dd..72285d570f146aa06265d2ecde13775c3101b9ed 100644 (file)
@@ -151,8 +151,9 @@ Return nil if there is no name or if NODE is not a defun node."
 
 (defun yaml-ts-mode--outline-predicate (node)
   "Limit outlines to top-level mappings."
-  (when (equal (treesit-node-type node) "block_mapping_pair")
-    (not (treesit-parent-until node treesit-outline-predicate))))
+  (let ((regexp (rx (or "block_mapping_pair" "block_sequence_item"))))
+    (when (string-match-p regexp (treesit-node-type node))
+      (not (treesit-parent-until node regexp)))))
 
 ;;;###autoload
 (define-derived-mode yaml-ts-mode text-mode "YAML"