aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorDmitry Gutov2014-01-31 19:13:49 +0200
committerDmitry Gutov2014-01-31 19:13:49 +0200
commite2a67bd08ea194da1b338c69c4da6e539782cb14 (patch)
treec559f7d7caf622d491520698926e85387dabb4c5 /lisp/progmodes/ruby-mode.el
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
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el38
1 files changed, 31 insertions, 7 deletions
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))