unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Remove js--treesit-backward-up-list or fix it
       [not found]   ` <0849BE6B-B5B4-47E0-B4EA-F93F6947C2B7@gmail.com>
@ 2022-10-29 18:31     ` Theodor Thornhill via Emacs development discussions.
  2022-10-29 19:07       ` Yuan Fu
  2022-10-29 19:20       ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: Theodor Thornhill via Emacs development discussions. @ 2022-10-29 18:31 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel


(added back in emacs-devel)

Hi!

>> 
>> ```
>> const fooClient = new Foo(() => ({
>>                            | // <---- point is there  
>>                          })); 
>> ```
>> Which is not what we want.  If we can keep that correct behavior in any
>> case I say we remove the hack.  We could make an anchor helper named
>> something like 'parent-then-bol', but because there is no node here, we
>> cannot find the parent.
>> 
>> What do you think?

>
> I added a rule that fixes it. Actually, when there is no node at
> point, parent is set to the smaller node that spans point, kind of
> like the immediate “parent” of that point. I’ve added some explanation
> in the manual.
>

Yes, It's probably a remnant from when the semantics were a bit
different between the treesit-node-on and treesit-node-at.  I see it was
never there in ts-mode ;-)

>> 
>> However, there are some problems with the newest revisions.  During
>>      })
>>      .catch((r) => {
>>        if (r.status < 200 || r.status >= 300) {
>>          console.log(r);
>>        }
>>      });
>>  };
>> ```
>
> Yes, sorry. I was naive with my implementation. Now it should be fixed.
>

Absolutely!  Great work!

However... Try creating a js-mode buffer and type:

```
const foo = foo(() => {});
```

Because of all the stuff we set before we init tree sitter we get a
super unwanted behavior of the cursor jumping back to indentation for
every () {} etc. This is because of these settings, which are IMO pretty
bad defaults:
```
  (setq-local electric-indent-chars
	      (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
  (setq-local electric-layout-rules
	      '((?\; . after) (?\{ . after) (?\} . before)))
```

This could just be something forgotten in the indent implementation, but
in my book this is yet another example for why we shouldn't init like
this ;-)

-- 
Theo



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 18:31     ` Remove js--treesit-backward-up-list or fix it Theodor Thornhill via Emacs development discussions.
@ 2022-10-29 19:07       ` Yuan Fu
  2022-10-29 19:31         ` Theodor Thornhill via Emacs development discussions.
  2022-10-29 19:20       ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2022-10-29 19:07 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: emacs-devel



> On Oct 29, 2022, at 11:31 AM, Theodor Thornhill <theo@thornhill.no> wrote:
> 
> 
> (added back in emacs-devel)
> 
> Hi!
> 
>>> 
>>> ```
>>> const fooClient = new Foo(() => ({
>>>                           | // <---- point is there  
>>>                         })); 
>>> ```
>>> Which is not what we want.  If we can keep that correct behavior in any
>>> case I say we remove the hack.  We could make an anchor helper named
>>> something like 'parent-then-bol', but because there is no node here, we
>>> cannot find the parent.
>>> 
>>> What do you think?
> 
>> 
>> I added a rule that fixes it. Actually, when there is no node at
>> point, parent is set to the smaller node that spans point, kind of
>> like the immediate “parent” of that point. I’ve added some explanation
>> in the manual.
>> 
> 
> Yes, It's probably a remnant from when the semantics were a bit
> different between the treesit-node-on and treesit-node-at.  I see it was
> never there in ts-mode ;-)

That was actually deliberate semantic (which I forgot to document), I broke it when introducing the new semantic for treesit-node-at...

> 
>>> 
>>> However, there are some problems with the newest revisions.  During
>>>     })
>>>     .catch((r) => {
>>>       if (r.status < 200 || r.status >= 300) {
>>>         console.log(r);
>>>       }
>>>     });
>>> };
>>> ```
>> 
>> Yes, sorry. I was naive with my implementation. Now it should be fixed.
>> 
> 
> Absolutely!  Great work!
> 
> However... Try creating a js-mode buffer and type:
> 
> ```
> const foo = foo(() => {});
> ```
> 
> Because of all the stuff we set before we init tree sitter we get a
> super unwanted behavior of the cursor jumping back to indentation for
> every () {} etc. This is because of these settings, which are IMO pretty
> bad defaults:
> ```
>  (setq-local electric-indent-chars
> 	      (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
>  (setq-local electric-layout-rules
> 	      '((?\; . after) (?\{ . after) (?\} . before)))
> ```
> 
> This could just be something forgotten in the indent implementation, but
> in my book this is yet another example for why we shouldn't init like
> this ;-)

I don’t have anything intelligent to say about the init process (except that we definitely need a way for js2-mode to turn off tree-sitter setup made by js-mode even if it is enabled by the user), but I fixed the indent problem you observed :-)

Yuan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 18:31     ` Remove js--treesit-backward-up-list or fix it Theodor Thornhill via Emacs development discussions.
  2022-10-29 19:07       ` Yuan Fu
@ 2022-10-29 19:20       ` Stefan Monnier
  2022-10-29 19:30         ` Theodor Thornhill via Emacs development discussions.
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2022-10-29 19:20 UTC (permalink / raw)
  To: Theodor Thornhill via Emacs development discussions.
  Cc: Yuan Fu, Theodor Thornhill

> Because of all the stuff we set before we init tree sitter we get a
> super unwanted behavior of the cursor jumping back to indentation for
> every () {} etc. This is because of these settings, which are IMO pretty
> bad defaults:
> ```
>   (setq-local electric-indent-chars
> 	      (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
>   (setq-local electric-layout-rules
> 	      '((?\; . after) (?\{ . after) (?\} . before)))
> ```

While these may be bad defaults, they should provide reasonable
behavior, so if you get cursor jumping with such settings, then we
should fix that regardless if its the default.


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 19:20       ` Stefan Monnier
@ 2022-10-29 19:30         ` Theodor Thornhill via Emacs development discussions.
  0 siblings, 0 replies; 7+ messages in thread
From: Theodor Thornhill via Emacs development discussions. @ 2022-10-29 19:30 UTC (permalink / raw)
  To: Stefan Monnier,
	Theodor Thornhill via Emacs development discussions.
  Cc: Yuan Fu

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

>> Because of all the stuff we set before we init tree sitter we get a
>> super unwanted behavior of the cursor jumping back to indentation for
>> every () {} etc. This is because of these settings, which are IMO pretty
>> bad defaults:
>> ```
>>   (setq-local electric-indent-chars
>> 	      (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
>>   (setq-local electric-layout-rules
>> 	      '((?\; . after) (?\{ . after) (?\} . before)))
>> ```
>
> While these may be bad defaults, they should provide reasonable
> behavior, so if you get cursor jumping with such settings, then we
> should fix that regardless if its the default.
>

Yuan fixed it :-)

-- 
Theo



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 19:07       ` Yuan Fu
@ 2022-10-29 19:31         ` Theodor Thornhill via Emacs development discussions.
  2022-10-29 20:08           ` Yuan Fu
  0 siblings, 1 reply; 7+ messages in thread
From: Theodor Thornhill via Emacs development discussions. @ 2022-10-29 19:31 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel


>
> I don’t have anything intelligent to say about the init process
> (except that we definitely need a way for js2-mode to turn off
> tree-sitter setup made by js-mode even if it is enabled by the user),
> but I fixed the indent problem you observed :-)
>

Ah you were faster than me.  Well, you can disregard most of the patch I
just sent to bug-gnu-emacs, but we still need the fix in parent-bol.  We
need back-to-indentation+point, not current-indentation, don't we?

-- 
Theo



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 19:31         ` Theodor Thornhill via Emacs development discussions.
@ 2022-10-29 20:08           ` Yuan Fu
  2022-10-29 20:12             ` Theodor Thornhill via Emacs development discussions.
  0 siblings, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2022-10-29 20:08 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: emacs-devel



> On Oct 29, 2022, at 12:31 PM, Theodor Thornhill <theo@thornhill.no> wrote:
> 
> 
>> 
>> I don’t have anything intelligent to say about the init process
>> (except that we definitely need a way for js2-mode to turn off
>> tree-sitter setup made by js-mode even if it is enabled by the user),
>> but I fixed the indent problem you observed :-)
>> 
> 
> Ah you were faster than me.

A whip named shame was chasing after me.

>  Well, you can disregard most of the patch I
> just sent to bug-gnu-emacs, but we still need the fix in parent-bol.  We
> need back-to-indentation+point, not current-indentation, don't we?

Right. My brain is not having its best time today :-) I applied your change. Thanks!

Yuan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Remove js--treesit-backward-up-list or fix it
  2022-10-29 20:08           ` Yuan Fu
@ 2022-10-29 20:12             ` Theodor Thornhill via Emacs development discussions.
  0 siblings, 0 replies; 7+ messages in thread
From: Theodor Thornhill via Emacs development discussions. @ 2022-10-29 20:12 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel



On 29 October 2022 22:08:39 CEST, Yuan Fu <casouri@gmail.com> wrote:
>
>
>> On Oct 29, 2022, at 12:31 PM, Theodor Thornhill <theo@thornhill.no> wrote:
>> 
>> 
>>> 
>>> I don’t have anything intelligent to say about the init process
>>> (except that we definitely need a way for js2-mode to turn off
>>> tree-sitter setup made by js-mode even if it is enabled by the user),
>>> but I fixed the indent problem you observed :-)
>>> 
>> 
>> Ah you were faster than me.
>
>A whip named shame was chasing after me.
>

Hah! 

>>  Well, you can disregard most of the patch I
>> just sent to bug-gnu-emacs, but we still need the fix in parent-bol.  We
>> need back-to-indentation+point, not current-indentation, don't we?
>
>Right. My brain is not having its best time today :-) I applied your change. Thanks!
>
>

:-)

No worries!

Theo



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-29 20:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <8B978AF7-B1CA-4C8A-9E89-84D0DEC7884C@gmail.com>
     [not found] ` <87h6znxkr0.fsf@thornhill.no>
     [not found]   ` <0849BE6B-B5B4-47E0-B4EA-F93F6947C2B7@gmail.com>
2022-10-29 18:31     ` Remove js--treesit-backward-up-list or fix it Theodor Thornhill via Emacs development discussions.
2022-10-29 19:07       ` Yuan Fu
2022-10-29 19:31         ` Theodor Thornhill via Emacs development discussions.
2022-10-29 20:08           ` Yuan Fu
2022-10-29 20:12             ` Theodor Thornhill via Emacs development discussions.
2022-10-29 19:20       ` Stefan Monnier
2022-10-29 19:30         ` Theodor Thornhill via Emacs development discussions.

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).