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: Tree-sitter indentation for js-mode & cc-mode Date: Wed, 26 Oct 2022 18:43:00 -0700 Message-ID: <9AF8BFDC-C9A2-4AE5-A8D2-E6AA05DA3C91@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2790"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Theodor Thornhill To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 27 03:44: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 1onrx3-0000WI-5h for ged-emacs-devel@m.gmane-mx.org; Thu, 27 Oct 2022 03:44:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onrvH-0000qm-RR; Wed, 26 Oct 2022 21:43:07 -0400 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 1onrvF-0000qR-R5 for emacs-devel@gnu.org; Wed, 26 Oct 2022 21:43:05 -0400 Original-Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onrvE-00024y-2w for emacs-devel@gnu.org; Wed, 26 Oct 2022 21:43:05 -0400 Original-Received: by mail-pg1-x52f.google.com with SMTP id e129so16863498pgc.9 for ; Wed, 26 Oct 2022 18:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=Q4ZmfUc2/ypSNBqbXRtwXXkduCzql/wdHdQvY5kny4I=; b=q4OUqz84LVroPkr6ix02ZrXDh9+ezwC/mHj8HPfZfxR3Txl+qEiTF1eqTWnvpzkNsq lBniQ68Irh6TmdgehDmFFFWR4glgm6zhYXRpgLjQcpDONASB4uLY5B8q6c/Poelabz8v viE4ozZhiblcE2r8s2quFoDtnkFajTNJXw9E6GxcZtMHhm/wTGzY9wiMuOpwBP+JRyoy b/pAfCCgd4PlzxjmkgqwKWZxk/2wsnBtMOxpk3IjVMfKDmhpDYcRWL+XmJ4mvGNgq1OQ TuN06bIhS9FnLaES8kHhOWqxRkjtoy5YZPKPq3diW5UAeyYcyHQXgwD/jL4KqqakZvFm TBDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q4ZmfUc2/ypSNBqbXRtwXXkduCzql/wdHdQvY5kny4I=; b=ffxJKLqFrpVRWSNhufCRIyhfNR/3IiLbMa7Hv+YnHMfFN2FvPFuUVE/Xe4DbAz9AKO 1TXI7wQ6IefjTAPGayjujBhglxkCvjBNLUN2pvas/OFErFq/mlSJHZbBeTWMbzvEGDm0 y5MQ2gpY2H23dEFx8+4u2w0yKTYl75rM3j/M5HmkmsGvtzJpENbDxJNH2wEnBxejKzwU 8p3ZskHeUUI4bAhdunD6XQDyRqYg/Msc1iBGQxKIf5KTbVUYFYvFKszbdhXOi0eTQe77 yYLnUKxwrv3ddtWmMBVVNLGmtmfjJKsghc16BC54aoIfqBfEHBt520xLTA8StLSji4Nz kWQw== X-Gm-Message-State: ACrzQf1ZztWJXi7g4aAN2523mvxIHWZ0IIIqz/JLH8ooE9ZIZKNzdJg1 5OZg9aBkl5Qdwsb1AcrW27vJyJ9kqxE= X-Google-Smtp-Source: AMsMyM66BYgz8lBwGgMnfAqDeU8n6YfHhXOko+qzLfaRVrsRdodNwSqIWbvK2EJd8whtB4kpLPD6Tg== X-Received: by 2002:a63:1944:0:b0:455:bea0:97ee with SMTP id 4-20020a631944000000b00455bea097eemr40706256pgz.258.1666834982011; Wed, 26 Oct 2022 18:43:02 -0700 (PDT) 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 c11-20020a170902d48b00b001869f2120a6sm3555235plg.108.2022.10.26.18.43.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2022 18:43:01 -0700 (PDT) X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=casouri@gmail.com; helo=mail-pg1-x52f.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: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298592 Archived-At: I did some work to allow tree-sitter indentation engine to plug in to = c-offset-alist. Currently in a tree-sitter indent rule, we have (MATCHER ANCHOR OFFSET) OFFSET is normally an integer, but now it can also be a syntax symbol = recognized by cc-mode=E2=80=99s indentation engine. In that case, = tree-sitter indent calculates the indent using c-calc-offset, passing = the syntax symbol and anchor position to it, and c-calc-offset will give = us the integer offset based on c-offset-alist. I=E2=80=99ve written indent rules for js-mode, they are in = js-treesit-cc-indent-rules. Overall it works pretty well. Theo, could = you give it a try? =46rom my testing it is already an improvement from = the original rules. I didn=E2=80=99t finish the JSX part and just copied = your original rules for JSX. In the future I can probably port that to = cc-style too. I also added imenu support for js-mode and ts-mode, and navigation for = python-mode. Yuan=