[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-30 24f12bdd77e 2/2: Support the new option in ruby-ts-mode too
From: |
Dmitry Gutov |
Subject: |
emacs-30 24f12bdd77e 2/2: Support the new option in ruby-ts-mode too |
Date: |
Mon, 2 Sep 2024 14:57:55 -0400 (EDT) |
branch: emacs-30
commit 24f12bdd77ee3dd1f2254bdc6cb5cbf7be488c36
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>
Support the new option in ruby-ts-mode too
* 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.
---
etc/NEWS | 4 ++++
lisp/progmodes/ruby-ts-mode.el | 10 +++++++++
.../ruby-bracketed-args-indent.rb | 24 +++++++++++++++-------
test/lisp/progmodes/ruby-ts-mode-tests.el | 1 +
4 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index f2c999a3955..a61bdc4a7f3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1973,6 +1973,10 @@ By default it retains the previous behavior: read the
contents of
Gemfile and act accordingly. But you can also set it to t or nil to
skip the check.
+*** New user option 'ruby-bracketed-args-indent'.
+When it is set to nil, multiple consecutive open braces/brackets/parens
+result in only one additional indentation level.
+
** Thingatpt
---
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index 5f4e11e0b4c..adcdf15c7ad 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -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
diff --git
a/test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
b/test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
index ac7a73463bf..c1aaff78ac9 100644
--- a/test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
@@ -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:
diff --git a/test/lisp/progmodes/ruby-ts-mode-tests.el
b/test/lisp/progmodes/ruby-ts-mode-tests.el
index 61ef80eb610..05d98974acf 100644
--- a/test/lisp/progmodes/ruby-ts-mode-tests.el
+++ b/test/lisp/progmodes/ruby-ts-mode-tests.el
@@ -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)