From: Marius Kjeldahl <marius.kjeldahl@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: 74386@debbugs.gnu.org, Theodor Thornhill <theo@thornhill.no>
Subject: bug#74386: Tree-sitter javascript indentation
Date: Mon, 18 Nov 2024 09:35:41 +0100 [thread overview]
Message-ID: <CAHdMyCK5VP3kj1ZsM1mUyfuTja_a+GZm+rgV=zswpYKTShUZTQ@mail.gmail.com> (raw)
In-Reply-To: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev>
Can confirm your patch solves both the variants I showed. This will
also help me to dig into and understand more of what is going on, and
allows me to experiment more with my preferences (and tree-sitter in
general). So thank you very much.
When I get a clue, or when someone with a clue comes up with it, a
patch which make these things configurable with easy settings would
probably be. a good idea (instead of diving into "tree-sitter
internals").
Thanks,
Marius K.
On Sun, 17 Nov 2024 at 23:12, Dmitry Gutov <dmitry@gutov.dev> wrote:
>
> On 17/11/2024 21:21, Marius Kjeldahl wrote:
> > Great, thanks.
> >
> > Here are two examples (fingers crossed):
> >
> > function a(b,
> > c) {
> > ....d();
> >
> > and
> >
> > if (clause1
> > && clause2) {
> > ....callSomeFunc();
> >
> > Notice in both cases the four dots "...." representing spaces used for
> > indentation. I would like only two dots (two spaces) for those
> > specific examples.
>
> Thank you, these two examples should be handled by the patch below.
>
> It's a change which could affect a fair amount of other examples too -
> for example
>
> Foobar
> .find()
> .catch((err) => {
> return 2;
> })
> .then((num) => {
> console.log(num);
> });
>
> turns into
>
> Foobar
> .find()
> .catch((err) => {
> return 2;
> })
> .then((num) => {
> console.log(num);
> });
>
>
> I'm not 100% sure if that's good or bad (maybe worse compatibility with
> js-mode, that we could say), so it would be useful to go through a bunch
> of other examples and decide whether what we had is a bug, or these
> should be supported as different styles, or etc.
>
> Cc'ing the original author of js-ts-mode, Theodor, for consultation.
>
> BTW, to try out such a patch you need to apply it, evaluate the defvar
> form (C-M-x, for example), and then re-enable the major mode in a given
> buffer (M-x js-ts-mode).
>
> diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
> index f74b8ab1c46..17a9509dd45 100644
> --- a/lisp/progmodes/js.el
> +++ b/lisp/progmodes/js.el
> @@ -3453,7 +3453,7 @@ js--treesit-indent-rules
> (let ((switch-case (rx "switch_" (or "case" "default"))))
> `((javascript
> ((parent-is "program") parent-bol 0)
> - ((node-is "}") parent-bol 0)
> + ((node-is "}") standalone-parent 0)
> ((node-is ")") parent-bol 0)
> ((node-is "]") parent-bol 0)
> ((node-is ">") parent-bol 0)
> @@ -3466,7 +3466,7 @@ js--treesit-indent-rules
> ;; "{" on the newline.
> ((node-is "statement_block") parent-bol js-indent-level)
> ((parent-is "named_imports") parent-bol js-indent-level)
> - ((parent-is "statement_block") parent-bol js-indent-level)
> + ((parent-is "statement_block") standalone-parent js-indent-level)
> ((parent-is "variable_declarator") parent-bol js-indent-level)
> ((parent-is "arguments") parent-bol js-indent-level)
> ((parent-is "array") parent-bol js-indent-level)
> @@ -3481,7 +3481,6 @@ js--treesit-indent-rules
> ((parent-is "binary_expression") parent-bol js-indent-level)
> ((parent-is "class_body") parent-bol js-indent-level)
> ((parent-is ,switch-case) parent-bol js-indent-level)
> - ((parent-is "statement_block") parent-bol js-indent-level)
> ((match "while" "do_statement") parent-bol 0)
> ((match "else" "if_statement") parent-bol 0)
> ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do")
> "_statement")
>
next prev parent reply other threads:[~2024-11-18 8:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-16 23:26 bug#74386: Tree-sitter javascript indentation Marius Kjeldahl
2024-11-17 19:18 ` Dmitry Gutov
2024-11-17 19:21 ` Marius Kjeldahl
2024-11-17 22:12 ` Dmitry Gutov
2024-11-17 22:21 ` Marius Kjeldahl
2024-11-17 22:41 ` Dmitry Gutov
2024-11-18 8:35 ` Marius Kjeldahl [this message]
2024-11-18 15:29 ` Dmitry Gutov
2024-11-30 10:01 ` Eli Zaretskii
2024-12-01 5:23 ` Yuan Fu
2024-12-01 13:11 ` Dmitry Gutov
2024-12-01 19:10 ` Yuan Fu
2024-12-01 22:33 ` Dmitry Gutov
2024-12-02 2:31 ` Yuan Fu
2024-12-11 6:18 ` Yuan Fu
2024-12-12 3:20 ` Dmitry Gutov
2024-12-12 5:28 ` Yuan Fu
2024-12-13 3:34 ` Dmitry Gutov
2024-12-13 5:34 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHdMyCK5VP3kj1ZsM1mUyfuTja_a+GZm+rgV=zswpYKTShUZTQ@mail.gmail.com' \
--to=marius.kjeldahl@gmail.com \
--cc=74386@debbugs.gnu.org \
--cc=dmitry@gutov.dev \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.