@code{outline-regexp} or @code{outline-search-function}.
@end defvar
-If built with tree-sitter, Emacs can automatically use
-Outline minor mode if the major mode sets the following variable.
+If built with tree-sitter, Emacs can automatically use Outline
+minor mode if the major mode sets one of the following variables.
@defvar treesit-outline-predicate
This variable instructs Emacs how to find lines with outline headings.
@defvar treesit-aggregated-outline-predicate
This variable allows major modes to configure outlines for multiple
languages. Its value is an alist mapping language symbols to outline
-headings of the form described above for the value of
+headings as described above for the value of
@code{treesit-outline-predicate}.
If this variable is non-@code{nil}, it overrides
(treesit-node-end parent)
(treesit-node-start parent))))
(setq parent (treesit-parent-until parent pred)))
+
+ (when-let* ((_ (null parent))
+ (parser (treesit-node-parser (treesit-node-at (point))))
+ (_ (not (eq parser treesit-primary-parser)))
+ (guest-root-node (treesit-parser-root-node parser)))
+ ;; Continue from the host node that contains the guest parser.
+ (setq parent (treesit-thing-at
+ (- (treesit-node-start guest-root-node) 2) pred)))
+
(or (when (and default-pos
(or (null parent)
(if (> arg 0)
"Return the depth of the current outline heading."
(let* ((node (treesit-outline--at-point))
(level 1)
- (parser (when treesit-aggregated-outline-predicate
+ (parser (when (and treesit-aggregated-outline-predicate node)
(treesit-node-parser node)))
(pred (if treesit-aggregated-outline-predicate
(alist-get (treesit-language-at (point))
treesit-outline-predicate)))
(while (setq node (treesit-parent-until node pred))
(setq level (1+ level)))
- (when-let* ((_ parser)
+ (when-let* ((_ (and parser (not (eq parser treesit-primary-parser))))
+ (guest-root-node (treesit-parser-root-node parser))
(host-lang (treesit-parser-language treesit-primary-parser))
- (_ (not (eq (treesit-language-at (point)) host-lang)))
(host-pred (alist-get host-lang treesit-aggregated-outline-predicate)))
- ;; Now need to break out of embedded confinement
- ;; and get the host node that contains the guest ranges
- (setq node (treesit-parser-root-node parser))
+ ;; Continue from the host node that contains the guest parser.
+ (setq node (treesit-node-at (- (treesit-node-start guest-root-node) 2)))
(while (setq node (treesit-parent-until node host-pred))
(setq level (1+ level))))
level))