From a52ad71cc5d036f1973ff2e504e45992fec3fc04 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Fri, 29 Nov 2024 09:35:13 +0200 Subject: [PATCH] * lisp/progmodes/c-ts-mode.el: Improve logic of outlines (bug#74448). (c-ts-mode--outline-predicate): Instead of checking only for function_declarator nodes at the beginning of line (like in GNU coding style) handle other coding styles that start the function line with either storage class (e.g. static) or type. Suggested by Filippo Argiolas --- lisp/progmodes/c-ts-mode.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index c815ee35501..9bbb78e0862 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -973,9 +973,14 @@ 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 (and (equal (treesit-node-type node) "function_declarator") - (equal (treesit-node-type (treesit-node-parent node)) - "function_definition")) + (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))))