unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: Eli Zaretskii <eliz@gnu.org>,
	67036@debbugs.gnu.org, Yuan Fu <casouri@gmail.com>
Subject: bug#67036: 30.0.50; treesit-forward-sexp not working properly in ruby-ts-mode
Date: Sun, 14 Apr 2024 19:25:11 +0300	[thread overview]
Message-ID: <864jc3ap3s.fsf@mail.linkov.net> (raw)
In-Reply-To: <867cllrln9.fsf@mail.linkov.net> (Juri Linkov's message of "Mon,  11 Dec 2023 19:09:54 +0200")

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

  reply	other threads:[~2024-04-14 16:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2024-05-02  6:29                 ` Juri Linkov

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=864jc3ap3s.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=67036@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    /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).