]> git.eshelyaron.com Git - emacs.git/commitdiff
Support the new option in ruby-ts-mode too
authorDmitry Gutov <dmitry@gutov.dev>
Mon, 2 Sep 2024 18:02:21 +0000 (21:02 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 8 Sep 2024 11:21:55 +0000 (13:21 +0200)
* etc/NEWS: Describe it here.

* lisp/progmodes/ruby-ts-mode.el (ruby-ts--parent-call-or-bol):
Support the option ruby-bracketed-args-indent here too (bug#60321).

* test/lisp/progmodes/ruby-ts-mode-tests.el: Include
ruby-bracketed-args-indent.rb as test examples.

* test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb:
Extend examples for better regression testing.

(cherry picked from commit 24f12bdd77ee3dd1f2254bdc6cb5cbf7be488c36)

lisp/progmodes/ruby-ts-mode.el
test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
test/lisp/progmodes/ruby-ts-mode-tests.el

index 5f4e11e0b4cc389f2430ba4f7affd64de7e57a72..adcdf15c7ad7fdfaacbdee28d8d28373210bbc0b 100644 (file)
@@ -842,6 +842,16 @@ a statement container is a node that matches
      ;; No paren/curly/brace found on the same line.
      ((< (treesit-node-start found) parent-bol)
       parent-bol)
+     ;; Nesting of brackets args.
+     ((and
+       (not (eq ruby-bracketed-args-indent t))
+       (string-match-p "\\`array\\|hash\\'" (treesit-node-type parent))
+       (equal (treesit-node-parent parent) found)
+       ;; Grandparent is not a parenless call.
+       (or (not (equal (treesit-node-type found) "argument_list"))
+           (equal (treesit-node-type (treesit-node-child found 0))
+                  "(")))
+      parent-bol)
      ;; Hash or array opener on the same line.
      ((string-match-p "\\`array\\|hash\\'" (treesit-node-type found))
       (save-excursion
index ac7a73463bfa76bfa3cd3f1162189b13c5db49e8..c1aaff78ac9887f062e866e1a6c7a3740798fc6d 100644 (file)
@@ -1,10 +1,11 @@
-update({
-  key => value,
-  other_key:
-}, {
-  key => value,
-  other_key:
-})
+foo
+  .update({
+    key => value,
+    other_key:
+  }, {
+    key => value,
+    other_key:
+  })
 
 update([
   1,
@@ -27,6 +28,15 @@ update(arg1, {
   2
 ], arg2)
 
+def foo
+  foo.update(
+    {
+      key => value,
+      other_key: foo
+    }
+  )
+end
+
 # Local Variables:
 # ruby-bracketed-args-indent: nil
 # End:
index 61ef80eb610eab477d95f4297108f07484bb395d..05d98974acfc1ac8ed0cf89f6377bb2eceb352de 100644 (file)
@@ -326,6 +326,7 @@ The whitespace before and including \"|\" on each line is removed."
 (ruby-ts-deftest-indent "ruby-method-call-indent.rb")
 (ruby-ts-deftest-indent "ruby-method-params-indent.rb")
 (ruby-ts-deftest-indent "ruby-parenless-call-arguments-indent.rb")
+(ruby-ts-deftest-indent "ruby-bracketed-args-indent.rb")
 
 (provide 'ruby-ts-mode-tests)