From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter support for C-like languages Date: Thu, 10 Nov 2022 14:58:12 -0800 Message-ID: <45FD2F78-F15B-488B-9348-A8E298D8AD35@gmail.com> References: <87tu36em9t.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_C96430F8-A000-48C5-99A6-0DB3FE044ACC" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37736"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 10 23:58:57 2022 Return-path: Envelope-to: ged-emacs-devel@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 1otGVc-0009cc-Pz for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Nov 2022 23:58:56 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otGV4-0006Fl-K7; Thu, 10 Nov 2022 17:58:22 -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 1otGV0-0006EA-1g for emacs-devel@gnu.org; Thu, 10 Nov 2022 17:58:18 -0500 Original-Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otGUy-00031D-3u for emacs-devel@gnu.org; Thu, 10 Nov 2022 17:58:17 -0500 Original-Received: by mail-pj1-x1035.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so3205211pjk.1 for ; Thu, 10 Nov 2022 14:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=yyQpZAImjsf+O+hW2Xy7g+Oya/+tm2V5BfIOgavrSbs=; b=qM0Y9UEbd5fiF1u8ySjv3e9xb9roaF5qqqHtAi0mijErTia1flw04DK0FnQnEhDmMB 5d11w+/t+kgTGTROT3q2NbqyFp3qDy8wFGgdnOHInqcMY/SKixeCBbmrN2rHjkTmUeqK YbhR4ux/j+DmI8ro7sOlJDeWGS2BsYHbD6iFvkDBG1CnvTaDWZ3LRJzZk4GZ+PjhthdM Sqg4KtHrURRRsFeH+uqXMGRTZMx9Od36gMi6J8R5DZCrrad/X+ko5NptW8/yiotmhm7h FupoimEuhlMnK7d57keY1WmFpugKj1WZrj486+4FKoiO8SJ4rQJjbOGMd1ivUD0VOYTw aP7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yyQpZAImjsf+O+hW2Xy7g+Oya/+tm2V5BfIOgavrSbs=; b=jpcb3cNqoVcwA1pPxX4tx8MnEhVemGJ3u7U9GAPjK2M/P9SDTuSahZzzYSFcZTEaZz HC5PGbZ3EGp7kP6LLgLYqLE/x55NQT2DVLCvOUWQbe1TudZOqASPn5+9GqL8WS7EYdh6 9ifw6pIS44zvnWuuFnCNg7yQuNwqfLrp7T1Vh3HPWOBozE8fLcsAOJvSj0/bQXUaxR5h WpA03CaMxXGBHEuGCzQ4RLgYjlUS0i62VbrFduyS+f7BSvdsAvPqF0AZV2lQz2hOL9/q IaBLMhgDfaN0VFi0FVRda6/9is4UeLWdUd3wwEDiXIQjI29q7vieWpmYEA8hEq8DXY2I QjPg== X-Gm-Message-State: ACrzQf1FjvpJwQM3VHLBOl4LylfXJWDeO4ht86zIzF9pymAwR0I6UMD0 s7UhDuZvc/lQ9QkNmkOWLuQ= X-Google-Smtp-Source: AMsMyM6Lw+KzplvDCHwyRNC21kul+3p9dnhI/sPD8KAv014tExua95nvwV859PM3Rn2LATYLeUK0HQ== X-Received: by 2002:a17:90b:354f:b0:212:e75b:1602 with SMTP id lt15-20020a17090b354f00b00212e75b1602mr2417259pjb.139.1668121094154; Thu, 10 Nov 2022 14:58:14 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id a11-20020a170902710b00b0018685aaf41dsm225688pll.18.2022.11.10.14.58.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2022 14:58:13 -0800 (PST) In-Reply-To: <87tu36em9t.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=casouri@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299528 Archived-At: --Apple-Mail=_C96430F8-A000-48C5-99A6-0DB3FE044ACC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 10, 2022, at 9:45 AM, Theodor Thornhill = wrote: >=20 >=20 >=20 > Hi all, >=20 > See the attached patch for support for several C-like languages. >=20 > They all support: > - Font locking > - Indentation (with styles for c/c++) > - Movement > - Imenu > - Which-func >=20 > These modes are meant as a supplement to tree-sitter. >=20 > I'm hopeful for some constructive criticism, and some testing. This > patch needs to be applied to the feature/tree-sitter branch, and = should > hopefully be applied there before we merge the branch to master, well > before Emacs 29 is cut. >=20 > I hope you like it, >=20 > Theo This is fantastic! I=E2=80=99m trying them out right now :-) Some things I noticed: The indentation for the closing bracket of a struct is off: struct regexp_cache { struct regexp_cache *next; }; Imenu has some duplicate entries, the patch below should fix that. I also added the new contextual thingy to font-lock settings. Yuan --Apple-Mail=_C96430F8-A000-48C5-99A6-0DB3FE044ACC Content-Disposition: attachment; filename=cc-modes.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="cc-modes.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 9da20485af4..b48ab667311 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -185,7 +185,8 @@ c-ts-mode--font-lock-settings :language 'c :override t :feature 'comment - `((comment) @font-lock-comment-face) + `((comment) @font-lock-comment-face + (comment) @contexual) :language 'c :override t :feature 'preprocessor @@ -224,6 +225,7 @@ c-ts-mode--font-lock-settings :override t :feature 'string `((string_literal) @font-lock-string-face + ((string_literal)) @contextual (system_lib_string) @font-lock-string-face (escape_sequence) @font-lock-string-face) :language 'c @@ -327,7 +329,14 @@ c-ts-mode--imenu-1 (marker (when ts-node (set-marker (make-marker) (treesit-node-start ts-node))))) + ;; A struct_specifier could be inside a parameter list or another + ;; struct definition. In those cases we don't include it. (cond + ((string-match-p + (rx (or "parameter" "field") "_declaration") + (or (treesit-node-type (treesit-node-parent ts-node)) + "")) + nil) ((null ts-node) subtrees) (subtrees `((,name ,(cons name marker) ,@subtrees))) --Apple-Mail=_C96430F8-A000-48C5-99A6-0DB3FE044ACC--