[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-30 6c15b7710d4 1/2: Add new option ruby-bracketed-args-indent
From: |
Dmitry Gutov |
Subject: |
emacs-30 6c15b7710d4 1/2: Add new option ruby-bracketed-args-indent |
Date: |
Mon, 2 Sep 2024 14:57:55 -0400 (EDT) |
branch: emacs-30
commit 6c15b7710d4bfc201afbafd2daec74c2baec9102
Author: Aaron Jensen <aaronjensen@gmail.com>
Commit: Dmitry Gutov <dmitry@gutov.dev>
Add new option ruby-bracketed-args-indent
* lisp/progmodes/ruby-mode.el (ruby-bracketed-args-indent): New option.
(ruby-smie-rules): Use it (bug#60321).
* test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb:
New file.
* test/lisp/progmodes/ruby-mode-tests.el: Use it for new case.
---
lisp/progmodes/ruby-mode.el | 23 ++++++++++++++++
.../ruby-bracketed-args-indent.rb | 32 ++++++++++++++++++++++
test/lisp/progmodes/ruby-mode-tests.el | 1 +
3 files changed, 56 insertions(+)
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 3bcfa9ee7df..d953ec8b25c 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -472,6 +472,26 @@ Only has effect when `ruby-use-smie' is t."
:safe 'booleanp
:version "29.1")
+(defcustom ruby-bracketed-args-indent t
+ "Non-nil to align the contents of bracketed arguments with the brackets.
+
+Example:
+
+ qux({
+ foo => bar
+ })
+
+Set it to nil to align to the beginning of the statement:
+
+ qux({
+ foo => bar
+ })
+
+Only has effect when `ruby-use-smie' is t."
+ :type 'boolean
+ :safe 'booleanp
+ :version "30.1")
+
(defcustom ruby-deep-arglist t
"Deep indent lists in parenthesis when non-nil.
Also ignores spaces after parenthesis when `space'.
@@ -826,6 +846,9 @@ This only affects the output of the command
`ruby-toggle-block'."
))
(`(:before . ,(or "(" "[" "{"))
(cond
+ ((and (not (eq ruby-bracketed-args-indent t))
+ (smie-rule-prev-p "," "(" "["))
+ (cons 'column (current-indentation)))
((and (equal token "{")
(not (smie-rule-prev-p "(" "{" "[" "," "=>" "=" "return" ";" "do"))
(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
new file mode 100644
index 00000000000..ac7a73463bf
--- /dev/null
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby-bracketed-args-indent.rb
@@ -0,0 +1,32 @@
+update({
+ key => value,
+ other_key:
+}, {
+ key => value,
+ other_key:
+})
+
+update([
+ 1,
+ 2
+], [
+ 3,
+ 4
+])
+
+update([{
+ key: "value"
+}, {
+ key: "value"
+}])
+
+update(arg1, {
+ foo: "bar"
+}, [
+ 1,
+ 2
+], arg2)
+
+# Local Variables:
+# ruby-bracketed-args-indent: nil
+# End:
diff --git a/test/lisp/progmodes/ruby-mode-tests.el
b/test/lisp/progmodes/ruby-mode-tests.el
index 2b8506a7adc..c9cde791baa 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -992,6 +992,7 @@ VALUES-PLIST is a list with alternating index and value
elements."
(ruby-deftest-indent "ruby-method-call-indent.rb")
(ruby-deftest-indent "ruby-method-params-indent.rb")
(ruby-deftest-indent "ruby-parenless-call-arguments-indent.rb")
+(ruby-deftest-indent "ruby-bracketed-args-indent.rb")
(ert-deftest ruby--test-chained-indentation ()
(with-temp-buffer