From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filippo Argiolas Newsgroups: gmane.emacs.bugs Subject: bug#74448: 30.0.92; c-ts-mode outlines only work with GNU or emacs style Date: Thu, 21 Nov 2024 10:47:35 +0100 Message-ID: References: <875xoh9gnw.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31043"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74448@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 21 10:49:30 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tE3oW-0007tI-GO for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 Nov 2024 10:49:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tE3o9-0008DQ-Pb; Thu, 21 Nov 2024 04:49:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tE3o7-0008Ci-4z for bug-gnu-emacs@gnu.org; Thu, 21 Nov 2024 04:49:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tE3o6-0004DM-Oo for bug-gnu-emacs@gnu.org; Thu, 21 Nov 2024 04:49:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=U4/3mTGG1RMdT7OGIu0jYEwWImxPTtW39Blw7X85QzU=; b=eJVmeJSnxhMSzRg6QdtCH2NmYPve1QeYS2ntDpJ8U8A4k0lzOe5HbSzhZsb3FCiuqJWpeNSjAn+1NMJtfaFjTadSVUkDDOFzO7XAaXKTfbZJtDQ9A1xsmapFFIDIRwqwtzJhjbG3PecoWDy5gzraOlwgE2CCFEhWHPncjjHdpWbHi0CoIXxtea9zmJKkicWQkJHoTpMrkkk7TowudAIpYnF9c4N/Nom3GSHBt9DTD6mEnDsSkROMk5+1L4OHZOy5El2pyOwu+1bOk3GgLBZmRXT7gjBnhDs3SFLqxtux9ge5/7po4c4wQb7wKBAFHMvlu3HkKsgPHXLSuYzdh6kx+A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tE3o6-0000tn-Fb for bug-gnu-emacs@gnu.org; Thu, 21 Nov 2024 04:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Filippo Argiolas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Nov 2024 09:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74448 X-GNU-PR-Package: emacs Original-Received: via spool by 74448-submit@debbugs.gnu.org id=B74448.17321825273429 (code B ref 74448); Thu, 21 Nov 2024 09:49:02 +0000 Original-Received: (at 74448) by debbugs.gnu.org; 21 Nov 2024 09:48:47 +0000 Original-Received: from localhost ([127.0.0.1]:49125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tE3nq-0000tF-La for submit@debbugs.gnu.org; Thu, 21 Nov 2024 04:48:47 -0500 Original-Received: from mail-wm1-f50.google.com ([209.85.128.50]:49523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tE3no-0000t0-BV for 74448@debbugs.gnu.org; Thu, 21 Nov 2024 04:48:45 -0500 Original-Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4316a44d1bbso5417365e9.3 for <74448@debbugs.gnu.org>; Thu, 21 Nov 2024 01:48:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732182458; x=1732787258; darn=debbugs.gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U4/3mTGG1RMdT7OGIu0jYEwWImxPTtW39Blw7X85QzU=; b=mQWlMPMOhHbPK5sohv61aY7Mb5acJy+mICQBvYkr2sVarE1CFL9GuwPF4giBi7D0lp oIF955dYjCbE/yxklsPV3eJ/lh6JrHcwKLTExsIx2h6btudiUvE2bWc5H1irBDFLQDh7 lP/IWMqy3myQIhY3zsXZ3QtEQ/8NkPqXvkpzytp6JUFs/tAuaFvw5+zKZgpTyldezut8 yb7HMMWma05x9VammMUKmEOxN839PGO0tyrjfh8suPt00dMIwM8+GCU7QXfwV32tpGV1 47sbe7wy+H/qZPUq5fzRR/ALLkcKTQQrQux4F8ObRL6gTL2ufeLNOEtYCmrDoP1WlEB+ 3Ijw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732182458; x=1732787258; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U4/3mTGG1RMdT7OGIu0jYEwWImxPTtW39Blw7X85QzU=; b=YTwXGLvQLrAVU8RL4egiScHy4SqEuzfdWOi5hKhTZg+uugEh2zY3Mgv5p011kBmFqr NDdp49QQD4F1/ce33I8DKNUhKrXfLrPPomsAnw8FjOYap2WqtEWet7tLnY0DQ+6bWiyg OzmuWy9D0QpEsCV4v7LWC7mm68R5jxHxA9zun0BEMKdXPaHmrTzSwKpq7ta1LnnV10rs 5eDpPsg7EoVZpSRPPgtjPWXdMJZYmYvL1nVQzEa8zukOLkq5dmySNAzOhFOv0kWk5Lhw tfHMBDU/a+O5+E7xeASJmEPncefcq5Ipq2pC5PnwLjTi8x9m4UMnuGbQMxhKmHpZBUQs gxBw== X-Gm-Message-State: AOJu0Yz9e6+uBn6yp3/BFTXA6wbJUSgbu+LqR8uV/hFId9TmzL/OZTmk l1j32GDuhbiiOkRjeSEEYHE53IrpGc1yMk0WT+afOaEwwN3+mawSTasgRLYg X-Google-Smtp-Source: AGHT+IHpucrLKgw/Xz43ZxjSXsswLwVeCVBT5SybLSha69+AK1aUEjdWWmt7HhnXk0aBp1ifPo8bpw== X-Received: by 2002:a05:600c:1f89:b0:431:60ac:9b0c with SMTP id 5b1f17b1804b1-4334f022976mr47552145e9.20.1732182457746; Thu, 21 Nov 2024 01:47:37 -0800 (PST) Original-Received: from mba ([151.81.191.240]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b46029acsm48218485e9.18.2024.11.21.01.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 01:47:37 -0800 (PST) In-Reply-To: <875xoh9gnw.fsf@mail.linkov.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295719 Archived-At: Juri Linkov writes: >> Hi, I've been playing with the new treesitter based outline minor mode >> and c-ts-mode. >> >> It seems that `outline-hide-subtree' is only working properly when code >> is formatted with either GNU or emacs style. >> >> To test try it with a function where the function declarator is preceded on the >> same line by either type or storage class and type. It will fold the >> function heading instead of the function body. >> >> Problem seems `c-ts-mode--outline-predicate' only checks for >> function_declarator nodes at the beginning of line (like in GNU coding >> style) but other coding style will start the function line with either >> storage class (e.g. static) or type. >> >> Something like this seems to work a little better: >> >> (defun c-ts-mode--outline-predicate (node) >> "Match outlines on lines with function names." >> (or (and (or (equal (treesit-node-type node) "function_declarator") >> (equal (treesit-node-type node) "storage_class_specifier") >> (equal (treesit-node-type node) "primitive_type") >> (equal (treesit-node-type node) "type_identifier")) >> (equal (treesit-node-type (treesit-node-parent node)) >> "function_definition")) >> ;; DEFUNs in Emacs sources. >> (and c-ts-mode-emacs-sources-support >> (c-ts-mode--emacs-defun-p node)))) >> >> But it kind of breaks GNU style by adding two outlines per function >> definition. Also it seems a bit ugly to enumerate all the node types by >> hand, there probably is a nicer way to detect a line with a >> function_declarator not at bol. >> >> Any better idea? > > Could you please send a few of short examples of each style. > This would help to make a better decision. > And later these examples could be added to tests. You should be able to see it with this example int bar(void) { return 1; } static int foo (int bar) { return 2; } int main(void) { return 3; } If you go to the third function and call `outline-hide-subtree' it replaces the function name with an ellipsis. Now if you call `outline-show-all' and try to collapse the second function (GNU style) it will show foo (int bar) {... which looks correct to me. If you show all again and collapse the first one it will do nothing and say "Before the first heading". This while still showing the outline icon in the margin. At the moment I am experimenting with this solution (DEFUN part omitted for brevity) but it's probably missing some edge case I am not aware of: (defun c-ts-mode--outline-predicate (node) "Match outlines on lines with function names." (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)))) Idea is to match a function declarator in the same line as `node' no matter what node is at bol. Ciao, Filippo