unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Theodor Thornhill <theo@thornhill.no>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel <emacs-devel@gnu.org>, Yuan Fu <casouri@gmail.com>
Subject: Re: Comments to the new tree sitter implementation
Date: Sun, 24 Apr 2022 07:06:00 +0200	[thread overview]
Message-ID: <87v8uzqddz.fsf@thornhill.no> (raw)
In-Reply-To: <jwvwnff1p7p.fsf-monnier+emacs@gnu.org>

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 1. New parent-beginning-of-line preset
>>
>> For typescript-mode more often that not you want to find some close
>> parent, then go to beginning of line to calculate the offset.  A
>> suggested implementation of this is:
>
> FWIW, I think this is a "quick hack" which gives fairly good results at
> little effort but doesn't help in the long run because you'll have to
> refine it sooner or later: it's never actually right, it's only ever
> right by accident.
>

Yes, absolutely.  Will indentation rules ever be perfect?  I'm thinking
a good approach is to provide something simple enough to not be too
controversial, and make sure a formatter takes care of the rest.  I
guess if we should cover all variants of the problems you outline I'd
have to provide a rule for all cases, don't I?  Or is there another way
you see?

>> ```typescript
>> function foo() {
>>   bar(() => ({
>>     baz
>>   }))
>> }
>> ```
>
> What if there's another argument to `bar` after the
> `() => ({ baz })` function, or if the user just prefers
>
>     function foo() {
>       bar(() => ({
>             baz
>           }))
>     }

In the first case you described my example function is surely wrong.  In
the second case I'm thinking either we provide some
'tree-sitter-simle-indent-override' defcustom that people can put their
own indentation rules into should they have some particular indentation
need

For typescript I'm now for the time being using the base 'prettier'
formatter just as a guidance tool for how to indent, as well as observe
how vscode behaves when typing.  Because the way Emacs handles
indentation is very different from how other editors do it (Emacs is
more of a formatter than the usual tab + shift-tab indenting method of
other editors), we have to make sure that both ways of indenting is
pleasant.  By this I mean that typing out a file from scratch should
indent as we type like how vscode or vim does it, while "C-x h TAB"
should work like a formatter.

With using prettiers default rules it would return

```typescript
function foo() {
  bar(
    () => ({
      baz,
    }),
    foo
  );
}
```

for the case where there's an extra arg where you specified.  This was
my reasoning for why this preset was ok enough.  It may not be for the
general case, though.  And fwiw, vscode indents it like this while
typing:

```typescript
function foo() {
   bar(() => ({
     baz
   }),
   foo
   )
}
```

This looks more like "I'm not even gonna try, just return 0 indent."



  reply	other threads:[~2022-04-24  5:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-23 12:33 Comments to the new tree sitter implementation Theodor Thornhill
2022-04-23 22:27 ` Stefan Monnier
2022-04-24  5:06   ` Theodor Thornhill [this message]
2022-04-24  5:36     ` Theodor Thornhill
2022-04-24 20:27       ` Stefan Monnier
2022-04-25 18:52 ` Yuan Fu
2022-04-25 19:07   ` Eli Zaretskii
2022-05-07  6:49     ` Yuan Fu
2022-05-07  7:11       ` Eli Zaretskii
2022-05-07  7:17         ` Yuan Fu
2022-04-25 19:08   ` Theodor Thornhill
2022-04-25 22:46     ` Yuan Fu
2022-04-26  6:38       ` Theodor Thornhill

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=87v8uzqddz.fsf@thornhill.no \
    --to=theo@thornhill.no \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).