GNU bug report logs - #67036
30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Fri, 10 Nov 2023 07:53:02 UTC

Severity: normal

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


Message #29 received at 67036 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 67036 <at> debbugs.gnu.org,
 Yuan Fu <casouri <at> gmail.com>
Subject: Re: bug#67036: 30.0.50; treesit-forward-sexp not working properly
 in ruby-ts-mode
Date: Sun, 14 Apr 2024 19:25:11 +0300
[Message part 1 (text/plain, inline)]
>>>>>>>> +# 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"

[ruby-ts-mode-text.patch (text/x-diff, inline)]
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)

This bug report was last modified 1 year and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.