[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 2b1fdbffcb 2/2: ruby-method-params-indent: New user option
From: |
Dmitry Gutov |
Subject: |
emacs-29 2b1fdbffcb 2/2: ruby-method-params-indent: New user option |
Date: |
Mon, 19 Dec 2022 14:07:28 -0500 (EST) |
branch: emacs-29
commit 2b1fdbffcb595bcd72fa9aa3db674c6985042bcb
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
ruby-method-params-indent: New user option
* lisp/progmodes/ruby-mode.el (ruby-method-params-indent):
New option (bug#60110).
(ruby-smie-rules): Use it.
* etc/NEWS: Mention it.
* test/lisp/progmodes/ruby-mode-resources/ruby.rb:
Ensure the var's value is default.
* test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb:
New file.
* test/lisp/progmodes/ruby-mode-tests.el (ruby-deftest-indent):
New macro, use it to run the indentation test using the new file.
Disable the :expensive-test tag, because neither runs for "longer
than some few seconds", both take significantly below 1s.
---
etc/NEWS | 3 +++
lisp/progmodes/ruby-mode.el | 26 +++++++++++++++++++---
.../ruby-method-params-indent.rb | 18 +++++++++++++++
test/lisp/progmodes/ruby-mode-resources/ruby.rb | 4 ++++
test/lisp/progmodes/ruby-mode-tests.el | 24 +++++++++++---------
5 files changed, 62 insertions(+), 13 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 017fd850b4..0e84459634 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2761,6 +2761,9 @@ project-dedicated or global) is specified by the new
---
*** Support for endless methods.
+---
+*** New user option 'ruby-method-params-indent'.
+
** Eshell
+++
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index d7efe98287..2b813dfcbc 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -268,6 +268,23 @@ Only has effect when `ruby-use-smie' is t."
:safe 'booleanp
:version "24.4")
+(defcustom ruby-method-params-indent t
+ "Indentation of multiline method parameters.
+
+When t, the parameters list is indented to the method name.
+
+When a number, indent the parameters list this many columns
+against the beginning of the method (the \"def\" keyword).
+
+The value nil means the same as 0.
+
+Only has effect when `ruby-use-smie' is t."
+ :type '(choice (const :tag "Indent to the method name" t)
+ (number :tag "Indent specified number of columns against def")
+ (const :tag "Indent to def" nil))
+ :safe (lambda (val) (or (memq val '(t nil)) (numberp val)))
+ :version 29.1)
+
(defcustom ruby-deep-arglist t
"Deep indent lists in parenthesis when non-nil.
Also ignores spaces after parenthesis when `space'.
@@ -660,9 +677,12 @@ This only affects the output of the command
`ruby-toggle-block'."
(unless (or (eolp) (forward-comment 1))
(cons 'column (current-column)))))
('(:before . " @ ")
- (save-excursion
- (skip-chars-forward " \t")
- (cons 'column (current-column))))
+ (if (or (eq ruby-method-params-indent t)
+ (not (smie-rule-parent-p "def" "def=")))
+ (save-excursion
+ (skip-chars-forward " \t")
+ (cons 'column (current-column)))
+ (smie-rule-parent (or ruby-method-params-indent 0))))
('(:before . "do") (ruby-smie--indent-to-stmt))
('(:before . ".")
(if (smie-rule-sibling-p)
diff --git
a/test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
b/test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
new file mode 100644
index 0000000000..2b66579739
--- /dev/null
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb
@@ -0,0 +1,18 @@
+class C
+ def self.foo(
+ baz,
+ bar
+ ) =
+ what
+
+ def foo=(
+ baz,
+ bar
+ )
+ hello
+ end
+end
+
+# Local Variables:
+# ruby-method-params-indent: 0
+# End:
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb
b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
index 2451edaee2..6a69d9db78 100644
--- a/test/lisp/progmodes/ruby-mode-resources/ruby.rb
+++ b/test/lisp/progmodes/ruby-mode-resources/ruby.rb
@@ -538,3 +538,7 @@ class Bar
baz
end
end
+
+# Local Variables:
+# ruby-method-params-indent: t
+# End:
diff --git a/test/lisp/progmodes/ruby-mode-tests.el
b/test/lisp/progmodes/ruby-mode-tests.el
index 9be01dc78f..560f780285 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -943,16 +943,20 @@ VALUES-PLIST is a list with alternating index and value
elements."
"Blub#bye"
"Blub#hiding")))))
-(ert-deftest ruby--indent/converted-from-manual-test ()
- :tags '(:expensive-test)
- ;; Converted from manual test.
- (let ((buf (find-file-noselect (ert-resource-file "ruby.rb"))))
- (unwind-protect
- (with-current-buffer buf
- (let ((orig (buffer-string)))
- (indent-region (point-min) (point-max))
- (should (equal (buffer-string) orig))))
- (kill-buffer buf))))
+(defmacro ruby-deftest-indent (file)
+ `(ert-deftest ,(intern (format "ruby-indent-test/%s" file)) ()
+ ;; :tags '(:expensive-test)
+ (let ((buf (find-file-noselect (ert-resource-file ,file))))
+ (unwind-protect
+ (with-current-buffer buf
+ (let ((orig (buffer-string)))
+ ;; Indent and check that we get the original text.
+ (indent-region (point-min) (point-max))
+ (should (equal (buffer-string) orig))))
+ (kill-buffer buf)))))
+
+(ruby-deftest-indent "ruby.rb")
+(ruby-deftest-indent "ruby-method-params-indent.rb")
(ert-deftest ruby--test-chained-indentation ()
(with-temp-buffer