all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Filippo Argiolas <filippo.argiolas@gmail.com>
Cc: 74448@debbugs.gnu.org
Subject: bug#74448: 30.0.92; c-ts-mode outlines only work with GNU or emacs style
Date: Fri, 29 Nov 2024 09:35:59 +0200	[thread overview]
Message-ID: <87mshi4hls.fsf@mail.linkov.net> (raw)
In-Reply-To: <m2frnj7qo5.fsf@gmail.com> (Filippo Argiolas's message of "Fri, 22 Nov 2024 07:01:30 +0100")

close 74448 31.0.50
thanks

> 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.

Actually this problem exists not only for declarations,
but also for preprocessor directives.  For example:

  #ifdef HAVE_XDBE
  static void
  x_set_inhibit_double_buffering (struct frame *f,
                                  Lisp_Object new_value,
                                  Lisp_Object old_value)

a dangling #ifdef will inevitably remain in the previous outline.
And I see no clear way to split such code to outlines
with function declaration headings.

> 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.

Probably it would be sufficient to define one additional function
'outline-prefix-function' that will find the beginning of either
the current outline or the next outline.
And it can be called after every call of 'outline-search-function'
to adjust the found position, but only for hiding outlines.
Still not sure if it can theoretically handle all cases.

> Maybe that's the job for a more specialized treesit folding package and
> this is already good for outline-minor-mode.

Indeed, maybe simpler would be to write a new package from scratch,
since the design of outline-minor-mode is too line-oriented.

> 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, this logic makes sense.  So after testing more cases I pushed it
to master.





      parent reply	other threads:[~2024-11-29  7:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 22:22 bug#74448: 30.0.92; c-ts-mode outlines only work with GNU or emacs style Filippo Argiolas
2024-11-21  7:42 ` Juri Linkov
2024-11-21  9:47   ` Filippo Argiolas
2024-11-21 18:17     ` Juri Linkov
2024-11-22  6:01       ` Filippo Argiolas
2024-11-22  7:39         ` Juri Linkov
2024-11-29  7:35         ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mshi4hls.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=74448@debbugs.gnu.org \
    --cc=filippo.argiolas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.