aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2014-01-31 19:13:49 +0200
committerDmitry Gutov2014-01-31 19:13:49 +0200
commite2a67bd08ea194da1b338c69c4da6e539782cb14 (patch)
treec559f7d7caf622d491520698926e85387dabb4c5
parentec80e689331728b22f34a797ec06354ac4595b4a (diff)
downloademacs-e2a67bd08ea194da1b338c69c4da6e539782cb14.tar.gz
emacs-e2a67bd08ea194da1b338c69c4da6e539782cb14.zip
Implement user option ruby-align-chained-calls
* lisp/progmodes/ruby-mode.el (ruby-align-chained-calls): New option. (ruby-smie-grammar): Make "." right-associative. Make its priority lower than the ternary and all binary operators. (ruby-smie-rules): Indent "(" relative to the first non-"." parent, or the first "." parent at indentation. Use `ruby-align-chained-calls' for indentation of "." tokens. * test/automated/ruby-mode-tests.el (ruby-align-chained-calls): New test. Fixes: debbugs:16593
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/ruby-mode.el38
-rw-r--r--test/ChangeLog5
-rw-r--r--test/automated/ruby-mode-tests.el14
-rw-r--r--test/indent/ruby.rb8
5 files changed, 64 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0a609682d62..90c00963ad4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12014-01-31 Dmitry Gutov <dgutov@yandex.ru>
2
3 * progmodes/ruby-mode.el (ruby-align-chained-calls): New option.
4 (ruby-smie-grammar): Make "." right-associative. Make its priority
5 lower than the ternary and all binary operators.
6 (ruby-smie-rules): Indent "(" relative to the first non-"."
7 parent, or the first "." parent at indentation. Use
8 `ruby-align-chained-calls' for indentation of "." tokens.
9 (Bug#16593)
10
12014-01-31 Juri Linkov <juri@jurta.org> 112014-01-31 Juri Linkov <juri@jurta.org>
2 12
3 * sort.el (delete-duplicate-lines): Remove `:weakness 'key' 13 * sort.el (delete-duplicate-lines): Remove `:weakness 'key'
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index f0a9da80ea4..17e16217ccb 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -264,6 +264,15 @@ Only has effect when `ruby-use-smie' is t.
264 :safe 'listp 264 :safe 'listp
265 :version "24.4") 265 :version "24.4")
266 266
267(defcustom ruby-align-chained-calls nil
268 "If non-nil, chained method calls on multiple lines will be
269aligned to the same column.
270
271Only has effect when `ruby-use-smie' is t."
272 :type 'boolean
273 :group 'ruby
274 :safe 'booleanp)
275
267(defcustom ruby-deep-arglist t 276(defcustom ruby-deep-arglist t
268 "Deep indent lists in parenthesis when non-nil. 277 "Deep indent lists in parenthesis when non-nil.
269Also ignores spaces after parenthesis when `space'. 278Also ignores spaces after parenthesis when `space'.
@@ -350,10 +359,10 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
350 ;; but avoids lots of conflicts: 359 ;; but avoids lots of conflicts:
351 (exp "and" exp) (exp "or" exp)) 360 (exp "and" exp) (exp "or" exp))
352 (exp (exp1) (exp "," exp) (exp "=" exp) 361 (exp (exp1) (exp "," exp) (exp "=" exp)
353 (id " @ " exp) 362 (id " @ " exp))
354 (exp "." id))
355 (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) 363 (exp1 (exp2) (exp2 "?" exp1 ":" exp1))
356 (exp2 ("def" insts "end") 364 (exp2 (exp3) (exp3 "." exp2))
365 (exp3 ("def" insts "end")
357 ("begin" insts-rescue-insts "end") 366 ("begin" insts-rescue-insts "end")
358 ("do" insts "end") 367 ("do" insts "end")
359 ("class" insts "end") ("module" insts "end") 368 ("class" insts "end") ("module" insts "end")
@@ -380,7 +389,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
380 (ielsei (itheni) (itheni "else" insts)) 389 (ielsei (itheni) (itheni "else" insts))
381 (if-body (ielsei) (if-body "elsif" if-body))) 390 (if-body (ielsei) (if-body "elsif" if-body)))
382 '((nonassoc "in") (assoc ";") (right " @ ") 391 '((nonassoc "in") (assoc ";") (right " @ ")
383 (assoc ",") (right "=") (assoc ".")) 392 (assoc ",") (right "="))
384 '((assoc "when")) 393 '((assoc "when"))
385 '((assoc "elsif")) 394 '((assoc "elsif"))
386 '((assoc "rescue" "ensure")) 395 '((assoc "rescue" "ensure"))
@@ -399,7 +408,8 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
399 (nonassoc ">" ">=" "<" "<=") 408 (nonassoc ">" ">=" "<" "<=")
400 (nonassoc "==" "===" "!=") 409 (nonassoc "==" "===" "!=")
401 (nonassoc "=~" "!~") 410 (nonassoc "=~" "!~")
402 (left "<<" ">>")))))) 411 (left "<<" ">>")
412 (right "."))))))
403 413
404(defun ruby-smie--bosp () 414(defun ruby-smie--bosp ()
405 (save-excursion (skip-chars-backward " \t") 415 (save-excursion (skip-chars-backward " \t")
@@ -609,7 +619,18 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
609 ;; When after `.', let's always de-indent, 619 ;; When after `.', let's always de-indent,
610 ;; because when `.' is inside the line, the 620 ;; because when `.' is inside the line, the
611 ;; additional indentation from it looks out of place. 621 ;; additional indentation from it looks out of place.
612 ((smie-rule-parent-p ".") (smie-rule-parent (- ruby-indent-level))) 622 ((smie-rule-parent-p ".")
623 (let (smie--parent)
624 (save-excursion
625 ;; Traverse up the parents until the parent is "." at
626 ;; indentation, or any other token.
627 (while (and (progn
628 (goto-char (1- (cadr (smie-indent--parent))))
629 (not (ruby-smie--bosp)))
630 (progn
631 (setq smie--parent nil)
632 (smie-rule-parent-p "."))))
633 (smie-rule-parent))))
613 (t (smie-rule-parent)))))) 634 (t (smie-rule-parent))))))
614 (`(:after . ,(or `"(" "[" "{")) 635 (`(:after . ,(or `"(" "[" "{"))
615 ;; FIXME: Shouldn't this be the default behavior of 636 ;; FIXME: Shouldn't this be the default behavior of
@@ -622,7 +643,10 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
622 (unless (or (eolp) (forward-comment 1)) 643 (unless (or (eolp) (forward-comment 1))
623 (cons 'column (current-column))))) 644 (cons 'column (current-column)))))
624 (`(:before . "do") (ruby-smie--indent-to-stmt)) 645 (`(:before . "do") (ruby-smie--indent-to-stmt))
625 (`(:before . ".") ruby-indent-level) 646 (`(:before . ".")
647 (if (smie-rule-sibling-p)
648 (and ruby-align-chained-calls 0)
649 ruby-indent-level))
626 (`(:after . "=>") ruby-indent-level) 650 (`(:after . "=>") ruby-indent-level)
627 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 651 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure"))
628 (smie-rule-parent)) 652 (smie-rule-parent))
diff --git a/test/ChangeLog b/test/ChangeLog
index 50ffd7c3957..5afc9890aff 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
12014-01-31 Dmitry Gutov <dgutov@yandex.ru>
2
3 * automated/ruby-mode-tests.el (ruby-align-chained-calls):
4 New test.
5
12014-01-27 Michael Albinus <michael.albinus@gmx.de> 62014-01-27 Michael Albinus <michael.albinus@gmx.de>
2 7
3 * automated/file-notify-tests.el (file-notify--deftest-remote): 8 * automated/file-notify-tests.el (file-notify--deftest-remote):
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index aa8032bb870..f6fddb5ef4c 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -333,6 +333,20 @@ VALUES-PLIST is a list with alternating index and value elements."
333 | 42 333 | 42
334 | end"))) 334 | end")))
335 335
336(ert-deftest ruby-align-chained-calls ()
337 (let ((ruby-align-chained-calls t))
338 (ruby-should-indent-buffer
339 "one.two.three
340 | .four
341 |
342 |my_array.select { |str| str.size > 5 }
343 | .map { |str| str.downcase }"
344 "one.two.three
345 | .four
346 |
347 |my_array.select { |str| str.size > 5 }
348 | .map { |str| str.downcase }")))
349
336(ert-deftest ruby-move-to-block-stops-at-indentation () 350(ert-deftest ruby-move-to-block-stops-at-indentation ()
337 (ruby-with-temp-buffer "def f\nend" 351 (ruby-with-temp-buffer "def f\nend"
338 (beginning-of-line) 352 (beginning-of-line)
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb
index a0116fef18e..49ed92f8fdc 100644
--- a/test/indent/ruby.rb
+++ b/test/indent/ruby.rb
@@ -257,8 +257,8 @@ foo ^
257 bar 257 bar
258 258
259foo_bar_tee(1, 2, 3) 259foo_bar_tee(1, 2, 3)
260 .qux 260 .qux.bar
261 .bar 261 .tee
262 262
263foo do 263foo do
264 bar 264 bar
@@ -338,7 +338,7 @@ end
338%^abc^ 338%^abc^
339ddd 339ddd
340 340
341qux = foo ? 341qux = foo.fee ?
342 bar : 342 bar :
343 tee 343 tee
344 344
@@ -348,7 +348,7 @@ zoo.keep.bar!(
348 348
349zoo 349zoo
350 .lose( 350 .lose(
351 q, p) 351 q, p)
352 352
353foo(bar: 353foo(bar:
354 tee) 354 tee)