unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
@ 2023-11-10  7:42 Juri Linkov
  2023-11-25  9:25 ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-11-10  7:42 UTC (permalink / raw)
  To: 67036; +Cc: dmitry

[-- Attachment #1: Type: text/plain, Size: 98 bytes --]

X-Debbugs-Cc: dmitry@gutov.dev

Please try these 5 cases described in the comments of this diff:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ruby-ts-mode.patch --]
[-- Type: text/x-diff, Size: 1144 bytes --]

diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
index 81d0dfd75c9..abe6a0789b9 100644
--- a/test/lisp/progmodes/ruby-mode-resources/ruby.rb
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
@@ -123,6 +123,7 @@ def test2 (arg)
     puts "there"
   end
 
+  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else" like with { }
   if a == 2 then
     puts "hello"
   elsif a == 3
@@ -179,6 +180,7 @@ def test2 (arg)
     bar,
     :a
 
+# when point is after @, C-M-f should jump to the end of symbol
 zzz @abc,
     4
 
@@ -211,10 +213,16 @@ def test2 (arg)
 
 class C
   def foo
-    self.end
+    self.end # when point between 'e' and 'n', C-M-b should jump to "self"
     D.new.class
   end
 
+  class << self
+    def bar
+    end
+  end
+  # C-M-b at the end of "end" should jump to "class"
+
   def begin
   end
 end
@@ -522,6 +530,9 @@ def qux
   puts "Japanese translation: #{orig_text} => #{trans_text}"
 end
 
+# C-M-f on '[' doesn't jump to after ']'
+hash['key']
+
 # Tokenizing "**" and "|" separately.
 def resolve(**args)
   members = proc do |**args|

[-- Attachment #3: Type: text/plain, Size: 63 bytes --]


Is it possible to improve ruby-ts-mode to handle these cases?

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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-10  7:42 bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode Juri Linkov
@ 2023-11-25  9:25 ` Eli Zaretskii
  2023-11-26 16:12   ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-11-25  9:25 UTC (permalink / raw)
  To: Juri Linkov, Yuan Fu, dmitry; +Cc: 67036

Ping!  Yuan and Dmitry, can we please make some progress here?

> Cc: dmitry@gutov.dev
> From: Juri Linkov <juri@linkov.net>
> Date: Fri, 10 Nov 2023 09:42:17 +0200
> 
> Please try these 5 cases described in the comments of this diff:
> 
> diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
> index 81d0dfd75c9..abe6a0789b9 100644
> --- a/test/lisp/progmodes/ruby-mode-resources/ruby.rb
> +++ b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
> @@ -123,6 +123,7 @@ def test2 (arg)
>      puts "there"
>    end
>  
> +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else" like with { }
>    if a == 2 then
>      puts "hello"
>    elsif a == 3
> @@ -179,6 +180,7 @@ def test2 (arg)
>      bar,
>      :a
>  
> +# when point is after @, C-M-f should jump to the end of symbol
>  zzz @abc,
>      4
>  
> @@ -211,10 +213,16 @@ def test2 (arg)
>  
>  class C
>    def foo
> -    self.end
> +    self.end # when point between 'e' and 'n', C-M-b should jump to "self"
>      D.new.class
>    end
>  
> +  class << self
> +    def bar
> +    end
> +  end
> +  # C-M-b at the end of "end" should jump to "class"
> +
>    def begin
>    end
>  end
> @@ -522,6 +530,9 @@ def qux
>    puts "Japanese translation: #{orig_text} => #{trans_text}"
>  end
>  
> +# C-M-f on '[' doesn't jump to after ']'
> +hash['key']
> +
>  # Tokenizing "**" and "|" separately.
>  def resolve(**args)
>    members = proc do |**args|
> 
> Is it possible to improve ruby-ts-mode to handle these cases?





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-25  9:25 ` Eli Zaretskii
@ 2023-11-26 16:12   ` Dmitry Gutov
  2023-11-27 17:06     ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2023-11-26 16:12 UTC (permalink / raw)
  To: Eli Zaretskii, Juri Linkov, Yuan Fu; +Cc: 67036

I've pushed an update which improves some of these (commit 2ec4526b972).

On 25/11/2023 11:25, Eli Zaretskii wrote:
> Ping!  Yuan and Dmitry, can we please make some progress here?
> 
>> Cc: dmitry@gutov.dev
>> From: Juri Linkov <juri@linkov.net>
>> Date: Fri, 10 Nov 2023 09:42:17 +0200
>>
>> Please try these 5 cases described in the comments of this diff:
>>
>> diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
>> index 81d0dfd75c9..abe6a0789b9 100644
>> --- a/test/lisp/progmodes/ruby-mode-resources/ruby.rb
>> +++ b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
>> @@ -123,6 +123,7 @@ def test2 (arg)
>>       puts "there"
>>     end
>>   
>> +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else" like with { }
>>     if a == 2 then
>>       puts "hello"
>>     elsif a == 3
>> @@ -179,6 +180,7 @@ def test2 (arg)
>>       bar,
>>       :a

Try out the change referenced above, but it doesn't do exactly this. 
Because the tree-sitter parse tree doesn't match the intuition you 
described above.

>> +# when point is after @, C-M-f should jump to the end of symbol
>>   zzz @abc,
>>       4

This is something that would need to be changed somewhere inside 
treesit-forward-sexp (or treesit--navigate-thing). The default 
forward-sexp behaves differently when in the middle of a symbol.

Also, interactive forward-sexp never reports "No next sexp" when inside 
parens or begin...end. It will do forward-up-list instead.

>> @@ -211,10 +213,16 @@ def test2 (arg)
>>   
>>   class C
>>     def foo
>> -    self.end
>> +    self.end # when point between 'e' and 'n', C-M-b should jump to "self"
>>       D.new.class
>>     end

Same as above, although the point will jump to before "end" (after the 
period). And the next C-M-b will jump to before "self".

>> +  class << self
>> +    def bar
>> +    end
>> +  end
>> +  # C-M-b at the end of "end" should jump to "class"
>> +

Now fixed.

>>     def begin
>>     end
>>   end
>> @@ -522,6 +530,9 @@ def qux
>>     puts "Japanese translation: #{orig_text} => #{trans_text}"
>>   end
>>   
>> +# C-M-f on '[' doesn't jump to after ']'
>> +hash['key']
>> +

As discussed previously, there is no specific node which spans from [ to 
]. Some custom code could probably be written (there *are* leaf nodes 
for [ and ]), but the current capabilities of treesit-thing-settings 
don't offer a good way to plug that in.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-26 16:12   ` Dmitry Gutov
@ 2023-11-27 17:06     ` Juri Linkov
  2023-11-28 22:15       ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-11-27 17:06 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 67036, Yuan Fu

>>>   +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else"
>>>     if a == 2 then
>>>       puts "hello"
>>>     elsif a == 3
>
> Try out the change referenced above, but it doesn't do exactly
> this. Because the tree-sitter parse tree doesn't match the intuition you
> described above.

Thanks for adding "then" and "else" that works not bad.
Then "elsif" could be added as well.

>>> +# when point is after @, C-M-f should jump to the end of symbol
>>>   zzz @abc,
>>>       4
>
> This is something that would need to be changed somewhere inside
> treesit-forward-sexp (or treesit--navigate-thing). The default forward-sexp
> behaves differently when in the middle of a symbol.

Agreed, more general changes are needed when point is inside symbols,
strings, comments, etc.

> Also, interactive forward-sexp never reports "No next sexp" when inside
> parens or begin...end. It will do forward-up-list instead.

On the one hand, it's inconsistent with the default non-treesit behavior of
forward-sexp.  On the other hand, the default behavior is too annoying
when it screams all the time with "Containing expression ends prematurely!"
instead of doing something useful.

>>>     def foo
>>> -    self.end
>>> +    self.end # when point between 'e' and 'n', C-M-b should jump to "self"
>
> Same as above, although the point will jump to before "end" (after the
> period). And the next C-M-b will jump to before "self".

This looks right.

>>> +  class << self
>>> +    def bar
>>> +    end
>>> +  end
>>> +  # C-M-b at the end of "end" should jump to "class"
>>> +
>
> Now fixed.

Thanks, confirmed.

>>>     def begin
>>>     end
>>>   end
>>> @@ -522,6 +530,9 @@ def qux
>>>     puts "Japanese translation: #{orig_text} => #{trans_text}"
>>>   end
>>>   +# C-M-f on '[' doesn't jump to after ']'
>>> +hash['key']
>>> +
>
> As discussed previously, there is no specific node which spans from [ to
> ]. Some custom code could probably be written (there *are* leaf nodes for [
> and ]), but the current capabilities of treesit-thing-settings don't offer
> a good way to plug that in.

Like for point inside strings, this might require more general changes
that take into account syntax tables.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-27 17:06     ` Juri Linkov
@ 2023-11-28 22:15       ` Dmitry Gutov
  2023-11-29  7:04         ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2023-11-28 22:15 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, 67036, Yuan Fu

On 27/11/2023 19:06, Juri Linkov wrote:
>>>>    +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else"
>>>>      if a == 2 then
>>>>        puts "hello"
>>>>      elsif a == 3
>>
>> Try out the change referenced above, but it doesn't do exactly
>> this. Because the tree-sitter parse tree doesn't match the intuition you
>> described above.
> 
> Thanks for adding "then" and "else" that works not bad.
> Then "elsif" could be added as well.

You can try it and report back. My impression is that it made navigation 
worse: the "elsif" nodes are not siblings of one another, they are 
nested. So it doesn't exactly match your expectations.

>>>> +# when point is after @, C-M-f should jump to the end of symbol
>>>>    zzz @abc,
>>>>        4
>>
>> This is something that would need to be changed somewhere inside
>> treesit-forward-sexp (or treesit--navigate-thing). The default forward-sexp
>> behaves differently when in the middle of a symbol.
> 
> Agreed, more general changes are needed when point is inside symbols,
> strings, comments, etc.

This is regarding behavior "inside" a thing as understood by treesit. 
Unrelated to Emacs's syntactic entities.

>> Also, interactive forward-sexp never reports "No next sexp" when inside
>> parens or begin...end. It will do forward-up-list instead.
> 
> On the one hand, it's inconsistent with the default non-treesit behavior of
> forward-sexp.  On the other hand, the default behavior is too annoying
> when it screams all the time with "Containing expression ends prematurely!"
> instead of doing something useful.

Looks like I have been spoiled by Paredit's paredit-forward which 
catches such errors and does the appropriate thing. Might be nice to 
bring this behavior to Emacs as forward-sexp-command, for example.

>>>>      def begin
>>>>      end
>>>>    end
>>>> @@ -522,6 +530,9 @@ def qux
>>>>      puts "Japanese translation: #{orig_text} => #{trans_text}"
>>>>    end
>>>>    +# C-M-f on '[' doesn't jump to after ']'
>>>> +hash['key']
>>>> +
>>
>> As discussed previously, there is no specific node which spans from [ to
>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>> and ]), but the current capabilities of treesit-thing-settings don't offer
>> a good way to plug that in.
> 
> Like for point inside strings, this might require more general changes
> that take into account syntax tables.

Possibly, but I expect a solution that doesn't use the syntax table 
would be tried first.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-28 22:15       ` Dmitry Gutov
@ 2023-11-29  7:04         ` Juri Linkov
  2023-12-11  0:47           ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-11-29  7:04 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 67036, Yuan Fu

>>>>>    +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else"
>>>>>      if a == 2 then
>>>>>        puts "hello"
>>>>>      elsif a == 3
>>>
>>> Try out the change referenced above, but it doesn't do exactly
>>> this. Because the tree-sitter parse tree doesn't match the intuition you
>>> described above.
>> Thanks for adding "then" and "else" that works not bad.
>> Then "elsif" could be added as well.
>
> You can try it and report back. My impression is that it made navigation
> worse: the "elsif" nodes are not siblings of one another, they are
> nested. So it doesn't exactly match your expectations.

Now I tried and indeed it does wrong thing: jumps to the end of the
last "else" instead of the end of own block because they are nested.
But maybe possible to skip "condition" and jump to the end of its
"consequence" before "alternative"?

>>> Also, interactive forward-sexp never reports "No next sexp" when inside
>>> parens or begin...end. It will do forward-up-list instead.
>> On the one hand, it's inconsistent with the default non-treesit behavior
>> of
>> forward-sexp.  On the other hand, the default behavior is too annoying
>> when it screams all the time with "Containing expression ends prematurely!"
>> instead of doing something useful.
>
> Looks like I have been spoiled by Paredit's paredit-forward which catches
> such errors and does the appropriate thing. Might be nice to bring this
> behavior to Emacs as forward-sexp-command, for example.

Agreed, at least as opt-in.

>>>>> +# when point is after @, C-M-f should jump to the end of symbol
>>>>>    zzz @abc,
>>>>>        4
>>>
>>> This is something that would need to be changed somewhere inside
>>> treesit-forward-sexp (or treesit--navigate-thing). The default forward-sexp
>>> behaves differently when in the middle of a symbol.
>> Agreed, more general changes are needed when point is inside symbols,
>> strings, comments, etc.
>
> This is regarding behavior "inside" a thing as understood by
> treesit. Unrelated to Emacs's syntactic entities.

"Inside a thing" could be handled the same way as "inside strings/comments".

>>>>> +# C-M-f on '[' doesn't jump to after ']'
>>>>> +hash['key']
>>>>> +
>>>
>>> As discussed previously, there is no specific node which spans from [ to
>>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>>> and ]), but the current capabilities of treesit-thing-settings don't offer
>>> a good way to plug that in.
>> Like for point inside strings, this might require more general changes
>> that take into account syntax tables.
>
> Possibly, but I expect a solution that doesn't use the syntax table would
> be tried first.

Since there is no available information from treesit, handling
treesit-forward-sexp inside strings/comments could forward to the syntax table
like `prog-fill-reindent-defun' forwards to `fill-paragraph'.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-11-29  7:04         ` Juri Linkov
@ 2023-12-11  0:47           ` Dmitry Gutov
  2023-12-11 17:09             ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2023-12-11  0:47 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, 67036, Yuan Fu

On 29/11/2023 09:04, Juri Linkov wrote:
>>>>>>     +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else"
>>>>>>       if a == 2 then
>>>>>>         puts "hello"
>>>>>>       elsif a == 3
>>>>
>>>> Try out the change referenced above, but it doesn't do exactly
>>>> this. Because the tree-sitter parse tree doesn't match the intuition you
>>>> described above.
>>> Thanks for adding "then" and "else" that works not bad.
>>> Then "elsif" could be added as well.
>>
>> You can try it and report back. My impression is that it made navigation
>> worse: the "elsif" nodes are not siblings of one another, they are
>> nested. So it doesn't exactly match your expectations.
> 
> Now I tried and indeed it does wrong thing: jumps to the end of the
> last "else" instead of the end of own block because they are nested.
> But maybe possible to skip "condition" and jump to the end of its
> "consequence" before "alternative"?

With custom code? Like with other questions, I'm not sure where to plug 
it in.

I guess it's possible to set up a ruby-ts-mode specific wrapper for 
treesit-forward-sexp, but that may not be the most optimal way to do 
that. Anyway, I haven't studied this direction yet.

>>>> Also, interactive forward-sexp never reports "No next sexp" when inside
>>>> parens or begin...end. It will do forward-up-list instead.
>>> On the one hand, it's inconsistent with the default non-treesit behavior
>>> of
>>> forward-sexp.  On the other hand, the default behavior is too annoying
>>> when it screams all the time with "Containing expression ends prematurely!"
>>> instead of doing something useful.
>>
>> Looks like I have been spoiled by Paredit's paredit-forward which catches
>> such errors and does the appropriate thing. Might be nice to bring this
>> behavior to Emacs as forward-sexp-command, for example.
> 
> Agreed, at least as opt-in.

Sounds worth a separate bug-report/feature-request.

>>>>>> +# when point is after @, C-M-f should jump to the end of symbol
>>>>>>     zzz @abc,
>>>>>>         4
>>>>
>>>> This is something that would need to be changed somewhere inside
>>>> treesit-forward-sexp (or treesit--navigate-thing). The default forward-sexp
>>>> behaves differently when in the middle of a symbol.
>>> Agreed, more general changes are needed when point is inside symbols,
>>> strings, comments, etc.
>>
>> This is regarding behavior "inside" a thing as understood by
>> treesit. Unrelated to Emacs's syntactic entities.
> 
> "Inside a thing" could be handled the same way as "inside strings/comments".

IIUC, treesit knows about the bounds of said thing, it just chooses not 
to move in such situation. That just seems like a bug, not a fundamental 
limitaiton.

>>>>>> +# C-M-f on '[' doesn't jump to after ']'
>>>>>> +hash['key']
>>>>>> +
>>>>
>>>> As discussed previously, there is no specific node which spans from [ to
>>>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>>>> and ]), but the current capabilities of treesit-thing-settings don't offer
>>>> a good way to plug that in.
>>> Like for point inside strings, this might require more general changes
>>> that take into account syntax tables.
>>
>> Possibly, but I expect a solution that doesn't use the syntax table would
>> be tried first.
> 
> Since there is no available information from treesit, handling
> treesit-forward-sexp inside strings/comments could forward to the syntax table
> like `prog-fill-reindent-defun' forwards to `fill-paragraph'.

Maybe.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-12-11  0:47           ` Dmitry Gutov
@ 2023-12-11 17:09             ` Juri Linkov
  2024-04-14 16:25               ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2023-12-11 17:09 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 67036, Yuan Fu

>>>>>>>     +  # from "elsif" and "then" C-M-f should jump to next "elsif"/"else"
>>>>>>>       if a == 2 then
>>>>>>>         puts "hello"
>>>>>>>       elsif a == 3
>>>>>
>>>>> Try out the change referenced above, but it doesn't do exactly
>>>>> this. Because the tree-sitter parse tree doesn't match the intuition you
>>>>> described above.
>>>> Thanks for adding "then" and "else" that works not bad.
>>>> Then "elsif" could be added as well.
>>>
>>> You can try it and report back. My impression is that it made navigation
>>> worse: the "elsif" nodes are not siblings of one another, they are
>>> nested. So it doesn't exactly match your expectations.
>> Now I tried and indeed it does wrong thing: jumps to the end of the
>> last "else" instead of the end of own block because they are nested.
>> But maybe possible to skip "condition" and jump to the end of its
>> "consequence" before "alternative"?
>
> With custom code? Like with other questions, I'm not sure where to plug it
> in.
>
> I guess it's possible to set up a ruby-ts-mode specific wrapper for
> treesit-forward-sexp, but that may not be the most optimal way to do
> that. Anyway, I haven't studied this direction yet.

Shouldn't treesit-forward-sexp provide a way for ts-modes to override
the default handling?  By default for all ts-modes such a hook could
check if point is inside strings/comments then to use syntax navigation.
And ruby-ts-mode could use such a hook to implement exceptions like
handling 'else'.

>>>>> Also, interactive forward-sexp never reports "No next sexp" when inside
>>>>> parens or begin...end. It will do forward-up-list instead.
>>>> On the one hand, it's inconsistent with the default non-treesit behavior of
>>>> forward-sexp.  On the other hand, the default behavior is too annoying
>>>> when it screams all the time with "Containing expression ends prematurely!"
>>>> instead of doing something useful.
>>>
>>> Looks like I have been spoiled by Paredit's paredit-forward which catches
>>> such errors and does the appropriate thing. Might be nice to bring this
>>> behavior to Emacs as forward-sexp-command, for example.
>> Agreed, at least as opt-in.
>
> Sounds worth a separate bug-report/feature-request.

Such option would be nice, but still need to investigate here
why "No next sexp" not reported inside begin/class/module.

>>>>>>> +# when point is after @, C-M-f should jump to the end of symbol
>>>>>>>     zzz @abc,
>>>>>>>         4
>>>>>
>>>>> This is something that would need to be changed somewhere inside
>>>>> treesit-forward-sexp (or treesit--navigate-thing). The default forward-sexp
>>>>> behaves differently when in the middle of a symbol.
>>>> Agreed, more general changes are needed when point is inside symbols,
>>>> strings, comments, etc.
>>>
>>> This is regarding behavior "inside" a thing as understood by
>>> treesit. Unrelated to Emacs's syntactic entities.
>> "Inside a thing" could be handled the same way as "inside
>> strings/comments".
>
> IIUC, treesit knows about the bounds of said thing, it just chooses not to
> move in such situation. That just seems like a bug, not a fundamental
> limitaiton.

This could be fixed like described above.

>>>>>>> +# C-M-f on '[' doesn't jump to after ']'
>>>>>>> +hash['key']
>>>>>>> +
>>>>>
>>>>> As discussed previously, there is no specific node which spans from [ to
>>>>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>>>>> and ]), but the current capabilities of treesit-thing-settings don't offer
>>>>> a good way to plug that in.
>>>> Like for point inside strings, this might require more general changes
>>>> that take into account syntax tables.
>>>
>>> Possibly, but I expect a solution that doesn't use the syntax table would
>>> be tried first.
>> Since there is no available information from treesit, handling
>> treesit-forward-sexp inside strings/comments could forward to the syntax table
>> like `prog-fill-reindent-defun' forwards to `fill-paragraph'.
>
> Maybe.

Idem.





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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2023-12-11 17:09             ` Juri Linkov
@ 2024-04-14 16:25               ` Juri Linkov
  2024-05-02  6:29                 ` Juri Linkov
  0 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2024-04-14 16:25 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 67036, Yuan Fu

[-- Attachment #1: Type: text/plain, Size: 1228 bytes --]

>>>>>>>> +# C-M-f on '[' doesn't jump to after ']'
>>>>>>>> +hash['key']
>>>>>>>> +
>>>>>>
>>>>>> As discussed previously, there is no specific node which spans from [ to
>>>>>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>>>>>> and ]), but the current capabilities of treesit-thing-settings don't offer
>>>>>> a good way to plug that in.
>>>>> Like for point inside strings, this might require more general changes
>>>>> that take into account syntax tables.
>>>>
>>>> Possibly, but I expect a solution that doesn't use the syntax table would
>>>> be tried first.
>>> Since there is no available information from treesit, handling
>>> treesit-forward-sexp inside strings/comments could forward to the syntax table
>>> like `prog-fill-reindent-defun' forwards to `fill-paragraph'.
>
> Shouldn't treesit-forward-sexp provide a way for ts-modes to override
> the default handling?  By default for all ts-modes such a hook could
> check if point is inside strings/comments then to use syntax navigation.

This is now implemented in bug#68993.  So here is the patch that 
handles such cases as C-M-f jumping from '[' to ']' in

  hash[:key]
  hash['key']

and from '{' to '}' in

  "abc #{ghi} def"


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ruby-ts-mode-text.patch --]
[-- Type: text/x-diff, Size: 1370 bytes --]

diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 7133cb0b5b0..098cca2cb56 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1171,7 +1171,20 @@ ruby-ts-mode
                                 "global_variable"
                                 )
                                eol)
-                              #'ruby-ts--sexp-p)))))
+                              #'ruby-ts--sexp-p))
+                 (text ,(lambda (node)
+                          (or (member (treesit-node-type node)
+                                      '("comment" "string_content"))
+                              (and (member (treesit-node-text node)
+                                           '("[" "]"))
+                                   (equal (treesit-node-type
+                                           (treesit-node-parent node))
+                                          "element_reference"))
+                              (and (member (treesit-node-text node)
+                                           '("#{" "}"))
+                                   (equal (treesit-node-type
+                                           (treesit-node-parent node))
+                                          "interpolation"))))))))
 
   ;; AFAIK, Ruby can not nest methods
   (setq-local treesit-defun-prefer-top-level nil)

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

* bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
  2024-04-14 16:25               ` Juri Linkov
@ 2024-05-02  6:29                 ` Juri Linkov
  0 siblings, 0 replies; 10+ messages in thread
From: Juri Linkov @ 2024-05-02  6:29 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 67036

close 67036 30.0.50
thanks

>>>>>>>>> +# C-M-f on '[' doesn't jump to after ']'
>>>>>>>>> +hash['key']
>>>>>>>>> +
>>>>>>>
>>>>>>> As discussed previously, there is no specific node which spans from [ to
>>>>>>> ]. Some custom code could probably be written (there *are* leaf nodes for [
>>>>>>> and ]), but the current capabilities of treesit-thing-settings don't offer
>>>>>>> a good way to plug that in.
>>>>>> Like for point inside strings, this might require more general changes
>>>>>> that take into account syntax tables.
>>>>>
>>>>> Possibly, but I expect a solution that doesn't use the syntax table would
>>>>> be tried first.
>>>> Since there is no available information from treesit, handling
>>>> treesit-forward-sexp inside strings/comments could forward to the syntax table
>>>> like `prog-fill-reindent-defun' forwards to `fill-paragraph'.
>>
>> Shouldn't treesit-forward-sexp provide a way for ts-modes to override
>> the default handling?  By default for all ts-modes such a hook could
>> check if point is inside strings/comments then to use syntax navigation.
>
> This is now implemented in bug#68993.  So here is the patch that 
> handles such cases as C-M-f jumping from '[' to ']' in
>
>   hash[:key]
>   hash['key']
>
> and from '{' to '}' in
>
>   "abc #{ghi} def"
>
> diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el

I guess this patch was ok.  So I pushed it to master, and closed.
Anything could be adjusted later if needed.





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

end of thread, other threads:[~2024-05-02  6:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10  7:42 bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode Juri Linkov
2023-11-25  9:25 ` Eli Zaretskii
2023-11-26 16:12   ` Dmitry Gutov
2023-11-27 17:06     ` Juri Linkov
2023-11-28 22:15       ` Dmitry Gutov
2023-11-29  7:04         ` Juri Linkov
2023-12-11  0:47           ` Dmitry Gutov
2023-12-11 17:09             ` Juri Linkov
2024-04-14 16:25               ` Juri Linkov
2024-05-02  6:29                 ` Juri Linkov

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