+2014-01-31 Dmitry Gutov <dgutov@yandex.ru>
+
+ * 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.
+ (Bug#16593)
+
2014-01-31 Juri Linkov <juri@jurta.org>
* sort.el (delete-duplicate-lines): Remove `:weakness 'key'
:safe 'listp
:version "24.4")
+(defcustom ruby-align-chained-calls nil
+ "If non-nil, chained method calls on multiple lines will be
+aligned to the same column.
+
+Only has effect when `ruby-use-smie' is t."
+ :type 'boolean
+ :group 'ruby
+ :safe 'booleanp)
+
(defcustom ruby-deep-arglist t
"Deep indent lists in parenthesis when non-nil.
Also ignores spaces after parenthesis when `space'.
;; but avoids lots of conflicts:
(exp "and" exp) (exp "or" exp))
(exp (exp1) (exp "," exp) (exp "=" exp)
- (id " @ " exp)
- (exp "." id))
+ (id " @ " exp))
(exp1 (exp2) (exp2 "?" exp1 ":" exp1))
- (exp2 ("def" insts "end")
+ (exp2 (exp3) (exp3 "." exp2))
+ (exp3 ("def" insts "end")
("begin" insts-rescue-insts "end")
("do" insts "end")
("class" insts "end") ("module" insts "end")
(ielsei (itheni) (itheni "else" insts))
(if-body (ielsei) (if-body "elsif" if-body)))
'((nonassoc "in") (assoc ";") (right " @ ")
- (assoc ",") (right "=") (assoc "."))
+ (assoc ",") (right "="))
'((assoc "when"))
'((assoc "elsif"))
'((assoc "rescue" "ensure"))
(nonassoc ">" ">=" "<" "<=")
(nonassoc "==" "===" "!=")
(nonassoc "=~" "!~")
- (left "<<" ">>"))))))
+ (left "<<" ">>")
+ (right "."))))))
(defun ruby-smie--bosp ()
(save-excursion (skip-chars-backward " \t")
;; When after `.', let's always de-indent,
;; because when `.' is inside the line, the
;; additional indentation from it looks out of place.
- ((smie-rule-parent-p ".") (smie-rule-parent (- ruby-indent-level)))
+ ((smie-rule-parent-p ".")
+ (let (smie--parent)
+ (save-excursion
+ ;; Traverse up the parents until the parent is "." at
+ ;; indentation, or any other token.
+ (while (and (progn
+ (goto-char (1- (cadr (smie-indent--parent))))
+ (not (ruby-smie--bosp)))
+ (progn
+ (setq smie--parent nil)
+ (smie-rule-parent-p "."))))
+ (smie-rule-parent))))
(t (smie-rule-parent))))))
(`(:after . ,(or `"(" "[" "{"))
;; FIXME: Shouldn't this be the default behavior of
(unless (or (eolp) (forward-comment 1))
(cons 'column (current-column)))))
(`(:before . "do") (ruby-smie--indent-to-stmt))
- (`(:before . ".") ruby-indent-level)
+ (`(:before . ".")
+ (if (smie-rule-sibling-p)
+ (and ruby-align-chained-calls 0)
+ ruby-indent-level))
(`(:after . "=>") ruby-indent-level)
(`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure"))
(smie-rule-parent))