diff options
| author | Dmitry Gutov | 2022-12-19 21:01:27 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2022-12-19 21:06:07 +0200 |
| commit | 2b1fdbffcb595bcd72fa9aa3db674c6985042bcb (patch) | |
| tree | d096889d882ed2d06cf548bbadb4bdea294440f4 | |
| parent | b9e813f79f2d7afb5f14caad17a865e66af17f15 (diff) | |
| download | emacs-2b1fdbffcb595bcd72fa9aa3db674c6985042bcb.tar.gz emacs-2b1fdbffcb595bcd72fa9aa3db674c6985042bcb.zip | |
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.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 26 | ||||
| -rw-r--r-- | test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb | 18 | ||||
| -rw-r--r-- | test/lisp/progmodes/ruby-mode-resources/ruby.rb | 4 | ||||
| -rw-r--r-- | test/lisp/progmodes/ruby-mode-tests.el | 24 |
5 files changed, 62 insertions, 13 deletions
| @@ -2761,6 +2761,9 @@ project-dedicated or global) is specified by the new | |||
| 2761 | --- | 2761 | --- |
| 2762 | *** Support for endless methods. | 2762 | *** Support for endless methods. |
| 2763 | 2763 | ||
| 2764 | --- | ||
| 2765 | *** New user option 'ruby-method-params-indent'. | ||
| 2766 | |||
| 2764 | ** Eshell | 2767 | ** Eshell |
| 2765 | 2768 | ||
| 2766 | +++ | 2769 | +++ |
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index d7efe982870..2b813dfcbcc 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." | |||
| 268 | :safe 'booleanp | 268 | :safe 'booleanp |
| 269 | :version "24.4") | 269 | :version "24.4") |
| 270 | 270 | ||
| 271 | (defcustom ruby-method-params-indent t | ||
| 272 | "Indentation of multiline method parameters. | ||
| 273 | |||
| 274 | When t, the parameters list is indented to the method name. | ||
| 275 | |||
| 276 | When a number, indent the parameters list this many columns | ||
| 277 | against the beginning of the method (the \"def\" keyword). | ||
| 278 | |||
| 279 | The value nil means the same as 0. | ||
| 280 | |||
| 281 | Only has effect when `ruby-use-smie' is t." | ||
| 282 | :type '(choice (const :tag "Indent to the method name" t) | ||
| 283 | (number :tag "Indent specified number of columns against def") | ||
| 284 | (const :tag "Indent to def" nil)) | ||
| 285 | :safe (lambda (val) (or (memq val '(t nil)) (numberp val))) | ||
| 286 | :version 29.1) | ||
| 287 | |||
| 271 | (defcustom ruby-deep-arglist t | 288 | (defcustom ruby-deep-arglist t |
| 272 | "Deep indent lists in parenthesis when non-nil. | 289 | "Deep indent lists in parenthesis when non-nil. |
| 273 | Also ignores spaces after parenthesis when `space'. | 290 | Also ignores spaces after parenthesis when `space'. |
| @@ -660,9 +677,12 @@ This only affects the output of the command `ruby-toggle-block'." | |||
| 660 | (unless (or (eolp) (forward-comment 1)) | 677 | (unless (or (eolp) (forward-comment 1)) |
| 661 | (cons 'column (current-column))))) | 678 | (cons 'column (current-column))))) |
| 662 | ('(:before . " @ ") | 679 | ('(:before . " @ ") |
| 663 | (save-excursion | 680 | (if (or (eq ruby-method-params-indent t) |
| 664 | (skip-chars-forward " \t") | 681 | (not (smie-rule-parent-p "def" "def="))) |
| 665 | (cons 'column (current-column)))) | 682 | (save-excursion |
| 683 | (skip-chars-forward " \t") | ||
| 684 | (cons 'column (current-column))) | ||
| 685 | (smie-rule-parent (or ruby-method-params-indent 0)))) | ||
| 666 | ('(:before . "do") (ruby-smie--indent-to-stmt)) | 686 | ('(:before . "do") (ruby-smie--indent-to-stmt)) |
| 667 | ('(:before . ".") | 687 | ('(:before . ".") |
| 668 | (if (smie-rule-sibling-p) | 688 | (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 00000000000..2b665797397 --- /dev/null +++ b/test/lisp/progmodes/ruby-mode-resources/ruby-method-params-indent.rb | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | class C | ||
| 2 | def self.foo( | ||
| 3 | baz, | ||
| 4 | bar | ||
| 5 | ) = | ||
| 6 | what | ||
| 7 | |||
| 8 | def foo=( | ||
| 9 | baz, | ||
| 10 | bar | ||
| 11 | ) | ||
| 12 | hello | ||
| 13 | end | ||
| 14 | end | ||
| 15 | |||
| 16 | # Local Variables: | ||
| 17 | # ruby-method-params-indent: 0 | ||
| 18 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-resources/ruby.rb b/test/lisp/progmodes/ruby-mode-resources/ruby.rb index 2451edaee22..6a69d9db78a 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 | |||
| 538 | baz | 538 | baz |
| 539 | end | 539 | end |
| 540 | end | 540 | end |
| 541 | |||
| 542 | # Local Variables: | ||
| 543 | # ruby-method-params-indent: t | ||
| 544 | # End: | ||
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 9be01dc78f9..560f780285a 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." | |||
| 943 | "Blub#bye" | 943 | "Blub#bye" |
| 944 | "Blub#hiding"))))) | 944 | "Blub#hiding"))))) |
| 945 | 945 | ||
| 946 | (ert-deftest ruby--indent/converted-from-manual-test () | 946 | (defmacro ruby-deftest-indent (file) |
| 947 | :tags '(:expensive-test) | 947 | `(ert-deftest ,(intern (format "ruby-indent-test/%s" file)) () |
| 948 | ;; Converted from manual test. | 948 | ;; :tags '(:expensive-test) |
| 949 | (let ((buf (find-file-noselect (ert-resource-file "ruby.rb")))) | 949 | (let ((buf (find-file-noselect (ert-resource-file ,file)))) |
| 950 | (unwind-protect | 950 | (unwind-protect |
| 951 | (with-current-buffer buf | 951 | (with-current-buffer buf |
| 952 | (let ((orig (buffer-string))) | 952 | (let ((orig (buffer-string))) |
| 953 | (indent-region (point-min) (point-max)) | 953 | ;; Indent and check that we get the original text. |
| 954 | (should (equal (buffer-string) orig)))) | 954 | (indent-region (point-min) (point-max)) |
| 955 | (kill-buffer buf)))) | 955 | (should (equal (buffer-string) orig)))) |
| 956 | (kill-buffer buf))))) | ||
| 957 | |||
| 958 | (ruby-deftest-indent "ruby.rb") | ||
| 959 | (ruby-deftest-indent "ruby-method-params-indent.rb") | ||
| 956 | 960 | ||
| 957 | (ert-deftest ruby--test-chained-indentation () | 961 | (ert-deftest ruby--test-chained-indentation () |
| 958 | (with-temp-buffer | 962 | (with-temp-buffer |