]> git.eshelyaron.com Git - emacs.git/commitdiff
ruby-ts-mode: Do not treat parenless calls' args as separate sexp
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 11 Apr 2023 23:27:51 +0000 (02:27 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 11 Apr 2023 23:28:02 +0000 (02:28 +0300)
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--sexp-p): New function.
(ruby-ts-mode): Use it in treesit-sexp-type-regexp (bug#62086).

lisp/progmodes/ruby-ts-mode.el

index ddf2ee98c3bd84ff16c515e3345a2b7d484ae991..7a00977f14af15d02017549118e43b185fb0a39b 100644 (file)
@@ -1086,6 +1086,15 @@ leading double colon is not added."
            (put-text-property pos (1+ pos) 'syntax-table
                               (string-to-syntax "!"))))))))
 
+(defun ruby-ts--sexp-p (node)
+  ;; Skip parenless calls (implicit parens are both non-obvious to the
+  ;; user, and might take over when we want to just over some physical
+  ;; parens/braces).
+  (or (not (equal (treesit-node-type node)
+                  "argument_list"))
+      (equal (treesit-node-type (treesit-node-child node 0))
+             "(")))
+
 (defvar-keymap ruby-ts-mode-map
   :doc "Keymap used in Ruby mode"
   :parent prog-mode-map
@@ -1114,8 +1123,10 @@ leading double colon is not added."
   (setq-local treesit-defun-type-regexp ruby-ts--method-regex)
 
   (setq-local treesit-sexp-type-regexp
-              (rx bol
-                  (or "class"
+              (cons (rx
+                     bol
+                     (or
+                      "class"
                       "module"
                       "method"
                       "array"
@@ -1147,7 +1158,8 @@ leading double colon is not added."
                       "instance_variable"
                       "global_variable"
                       )
-                  eol))
+                     eol)
+                    #'ruby-ts--sexp-p))
 
   ;; AFAIK, Ruby can not nest methods
   (setq-local treesit-defun-prefer-top-level nil)