[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#74448: 30.0.92; c-ts-mode outlines only work with GNU or emacs style
From: |
Juri Linkov |
Subject: |
bug#74448: 30.0.92; c-ts-mode outlines only work with GNU or emacs style |
Date: |
Fri, 22 Nov 2024 09:39:16 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) |
>> Thanks, I confirm your solution is better than the current state.
>> Hope you could find a common denominator that covers all possible cases.
>
> Seems to work with the code I tested. Guess it's still not perfect, if a
> function declaration is splitted over multiple lines it will be folded
> where the function name is and I think that's what we want.
>
> A minor problem is with GNU style declarations type and storage class
> specifier will go in to the previous subtree when you collapse
> everything.
>
> But it's probably good enough. As far as I can tell the way it works now
> it folds from one outline to the next. The treesitter way would be to
> fold up to where the toplevel node ends.
>
> Maybe that's the job for a more specialized treesit folding package and
> this is already good for outline-minor-mode.
outline-minor-mode is designed to always fold from the current heading line
until the next heading line. Maybe outline-minor-mode could be extended
to detach the heading from the outline boundaries. For example,
by adding separate regexps/functions to match outline boundaries
while outline-regexp/outline-search-function will still be used
only for the heading line.
> By the way, the complete defun with Emacs source parsing restored is:
>
> (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)))
> ;; DEFUNs in Emacs sources.
> (and c-ts-mode-emacs-sources-support
> (c-ts-mode--emacs-defun-p node))))
>
>
> Feel free to improve on this if you decide to install it, I never did
> the copyright assignment but I think it's trivial enough to enter
> without it.
Thanks, will test it more before installing.