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: Fri, 22 Nov 2024 07:01:30 +0100 Message-ID: References: <875xoh9gnw.fsf@mail.linkov.net> <87v7wge93a.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="18798"; 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 Fri Nov 22 07:03:23 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 1tEMlH-0004m7-BU for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Nov 2024 07:03:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEMky-0003Fc-7k; Fri, 22 Nov 2024 01:03:04 -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 1tEMkw-0003FN-Ql for bug-gnu-emacs@gnu.org; Fri, 22 Nov 2024 01:03:02 -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 1tEMkw-0008Nw-FR for bug-gnu-emacs@gnu.org; Fri, 22 Nov 2024 01:03: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=40wRLmzIrdOMVNcybRsuFQBMeYieqHwQh3c1Oe3694s=; b=W0fPlqo3YnYuWHieK5RfMXVcGAisQw5KycPB7QcQK328jOswejBk7x5wkMWICWe3igxPo07/TVJwyX2986q9/G4fzLI4dpVJLySYQvhzHqwuLNrORqOrLbjEtwH4I5Bu4N42vWxf3vlY8CzDF3GuWjF2iTKPB6vh62PK+32giw69hXhKBB7P5wduwOGqHBqYYb9myyqdm/wrMu1LiqxJuyzefN7CMinqCDTOpnP1PbkvuFh42XUl/Tlh5CMsW4RZek9XCGFB+6oZ8oJYfkgfwY7Ef1RKmWTd6Yla+2AcMMNkbjGPwQWAbvdoBsBzZQthftLCe1P/GcqhOIQKDofimQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tEMkw-0006om-9n for bug-gnu-emacs@gnu.org; Fri, 22 Nov 2024 01:03: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: Fri, 22 Nov 2024 06:03: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.173225536226144 (code B ref 74448); Fri, 22 Nov 2024 06:03:02 +0000 Original-Received: (at 74448) by debbugs.gnu.org; 22 Nov 2024 06:02:42 +0000 Original-Received: from localhost ([127.0.0.1]:52749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tEMkc-0006nb-2X for submit@debbugs.gnu.org; Fri, 22 Nov 2024 01:02:42 -0500 Original-Received: from mail-wm1-f45.google.com ([209.85.128.45]:42426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tEMkZ-0006nL-9I for 74448@debbugs.gnu.org; Fri, 22 Nov 2024 01:02:40 -0500 Original-Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4315eac969aso9308265e9.1 for <74448@debbugs.gnu.org>; Thu, 21 Nov 2024 22:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732255293; x=1732860093; 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=40wRLmzIrdOMVNcybRsuFQBMeYieqHwQh3c1Oe3694s=; b=SSs06OoJcPSTCi53lnnHJy2vHlfmWIHCn6bKb2ZiEYqJM8hqBlrIFJwscR3ZoAPPCj t9CdF1ug+uSMVWbsWN0LDMiUcdBQkg2NzbYIRH5gHc/et6YUW2of2psMMjuvTufp94dG j0SkLpzsNVBZGjpk78PWLbdNH2Kxe8YPp+jGN7zNx5ztzAXXVu+uQQ7gIGJv1O7BHPka r79US+9tLYfDIszJc0S19FbNxR5HShDp2zVH+ZCIOoUVC/v0G9y/DecZJ20AA7JtO6u0 U14bY3VG7tYx7c0sygGXs9b6Yid9/LS5lp3LCMl4Hy03h1MXAeI3dfqw/ESOHih0vGQ+ WcWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732255293; x=1732860093; 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=40wRLmzIrdOMVNcybRsuFQBMeYieqHwQh3c1Oe3694s=; b=qWRT2MFhDSw7JCX1Z5gKHSk5cnU2Kt1pXBoAzEqHoquTWysVTHjzj3GIngUlnwQtkE uhGUqGdnIgumQ0rB8X/ItDtcMquCZTXj2R+s+Fo7EeE4eitVOgxorpAxRqdUJbDrgKOm 7LOj9GOxQNrqrzv/SlvuoqzWyhTPG4B0DTJgYWBL6RRW7wLZWYGRHEg7/546gsQfJd9Z HZPVzwEb67xU+akR1DUiL1jioU3lW0SOAalq+juJ8y8XjQBMN6FXwsLBy3gCe47b+glt sfuc+1biy6NualnICQyG4CADUb2kAgKemYWcqM4llqzLoUFOk3eW9f2B3RHhCe8aVhc2 N0fQ== X-Gm-Message-State: AOJu0Yy12AoaoBpJgRIkPg0cu4+YhmW/rdGCCmraEqUwfnUjuJmw4HGZ Ah8lYpQS0rwqZktTbRnOnnK+8y3uuXQKEXTKyKjBd5OT8AI+qNF8EXMVv+nS X-Gm-Gg: ASbGncvrf/I0iSCVgbtX1JYbvD70CCSc51mvkPW5/14JG0tumASGzbUaPjK6EOr1AIB PW0RUb8UmpUNlP+kbIRnBiy7nRBFEa6fLBIA2MwufOxL0+PukZ0wN0QQhBnYqscaV4CvmKW/eDZ xcX66Hwbv5sMqMD5yLVzsBfuBnLcY98yyxtpdNo/K12+cqtJEjJqNfVIt2Dsu4mx0yv9l7pnsy0 ygqtJs1wZPWTr4/Rehat/1PxKib5SL6A7H7ETPG2YbvSctiTIyQSXHjYZo= X-Google-Smtp-Source: AGHT+IHeZTuGqjOMw+THaNKzCl2Ndb1mLaOL8Iw9B/eQOIeAAZ68eq0+fTs5XNnUiOCZSk3cAk/aVg== X-Received: by 2002:a05:600c:a296:b0:42c:b826:a26c with SMTP id 5b1f17b1804b1-433c5ca2428mr47080895e9.8.1732255292624; Thu, 21 Nov 2024 22:01:32 -0800 (PST) Original-Received: from mba ([151.81.191.240]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b463ab5fsm81739335e9.27.2024.11.21.22.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 22:01:31 -0800 (PST) In-Reply-To: <87v7wge93a.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:295768 Archived-At: Juri Linkov writes: >> 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. > > 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. 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! Filippo