]> git.eshelyaron.com Git - emacs.git/commitdiff
ruby-ts-mode: Fix the rules for hanging arrays and hashes
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 17 Jan 2023 21:46:41 +0000 (23:46 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 18 Jan 2023 01:27:37 +0000 (03:27 +0200)
* lisp/progmodes/ruby-ts-mode.el (ruby-ts--indent-rules):
Fix the rules for hanging arrays and hashes (to line up to
parent-bol instead of the opening brace).

* test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb:
New file with examples.

* test/lisp/progmodes/ruby-ts-mode-tests.el: Use it here.

lisp/progmodes/ruby-ts-mode.el
test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb [new file with mode: 0644]
test/lisp/progmodes/ruby-ts-mode-tests.el

index 939c054b041b455118c17eab3f4b4d2a733ea69a..19b766ceadb8c397cab3c704420032c4448ab76d 100644 (file)
@@ -749,20 +749,10 @@ i.e. expr of def foo(args) = expr is returned."
                  (not ruby-ts--same-line-hash-array-p))
             grand-parent ruby-indent-level)
 
-           ((n-p-gp "}" "hash" "assignment")  (ruby-ts--bol ruby-ts--grand-parent-node) 0)
-           ((n-p-gp nil "hash" "assignment")  (ruby-ts--bol ruby-ts--grand-parent-node) ruby-indent-level)
-           ((n-p-gp "]" "array" "assignment") (ruby-ts--bol ruby-ts--grand-parent-node) 0)
-           ((n-p-gp nil "array" "assignment") (ruby-ts--bol ruby-ts--grand-parent-node) ruby-indent-level)
-
-           ((n-p-gp "}" "hash" "argument_list")  first-sibling 0)
-           ((n-p-gp nil "hash" "argument_list")  first-sibling ruby-indent-level)
-           ((n-p-gp "]" "array" "argument_list") first-sibling 0)
-           ((n-p-gp nil "array" "argument_list") first-sibling ruby-indent-level)
-
-           ((match "}" "hash")  first-sibling 0)
-           ((parent-is "hash")  first-sibling ruby-indent-level)
-           ((match "]" "array") first-sibling 0)
-           ((parent-is "array") first-sibling ruby-indent-level)
+           ((match "}" "hash")  parent-bol 0)
+           ((parent-is "hash")  parent-bol ruby-indent-level)
+           ((match "]" "array") parent-bol 0)
+           ((parent-is "array") parent-bol ruby-indent-level)
 
            ;; If the previous method isn't finished yet, this will get
            ;; the next method indented properly.
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb b/test/lisp/progmodes/ruby-mode-resources/ruby-ts.rb
new file mode 100644 (file)
index 0000000..6b4107e
--- /dev/null
@@ -0,0 +1,23 @@
+variable = foo(
+  [
+    qwe
+  ], [
+    rty
+  ], {
+    a: 3
+  }
+)
+
+tee = [
+  qwe
+]
+
+qux = [1,
+       2]
+
+att = {a: 1,
+       b: 2}
+
+# Local Variables:
+# mode: ruby-ts
+# End:
index eaf6367a306f1ad139d1d3530cb26765a4019f51..d7b6258385b17e536a0450d7b0b6c84fc448abd7 100644 (file)
@@ -250,6 +250,7 @@ The whitespace before and including \"|\" on each line is removed."
                (should (equal (buffer-string) orig))))
          (kill-buffer buf)))))
 
+(ruby-ts-deftest-indent "ruby-ts.rb")
 (ruby-ts-deftest-indent "ruby-method-params-indent.rb")
 (ruby-ts-deftest-indent "ruby-block-indent.rb")