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 302274b186
.
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".
This commit is contained in:
parent
3e699b3047
commit
58c09c3d36
2 changed files with 8 additions and 10 deletions
|
@ -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))))
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue