From: Yuan Fu <casouri@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Cc: Theodor Thornhill <theo@thornhill.no>
Subject: Tree-sitter indentation for js-mode & cc-mode
Date: Wed, 26 Oct 2022 18:43:00 -0700 [thread overview]
Message-ID: <9AF8BFDC-C9A2-4AE5-A8D2-E6AA05DA3C91@gmail.com> (raw)
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’s 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’ve 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? From my testing it is already an improvement from the original rules. I didn’t 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
next reply other threads:[~2022-10-27 1:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 1:43 Yuan Fu [this message]
2022-10-27 9:11 ` Tree-sitter indentation for js-mode & cc-mode Theodor Thornhill
2022-10-27 9:28 ` Theodor Thornhill
2022-10-27 9:58 ` Theodor Thornhill
2022-10-27 15:21 ` Yuan Fu
2022-10-27 18:36 ` Theodor Thornhill
2022-10-28 8:15 ` Yuan Fu
2022-10-28 8:59 ` Theodor Thornhill
2022-10-28 9:10 ` Theodor Thornhill
2022-10-28 19:43 ` Yuan Fu
2022-10-28 19:49 ` Theodor Thornhill
2022-10-29 1:05 ` Yuan Fu
2022-10-29 5:53 ` Eli Zaretskii
2022-10-29 6:54 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9AF8BFDC-C9A2-4AE5-A8D2-E6AA05DA3C91@gmail.com \
--to=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=theo@thornhill.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).