diff options
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r-- | lisp/progmodes/ruby-mode.el | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index be8f96dcfd9..2389f742937 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -368,7 +368,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (exp (exp1) (exp "," exp) (exp "=" exp) (id " @ " exp)) (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) - (exp2 (exp3) (exp3 "." exp2)) + (exp2 (exp3) (exp3 "." exp3)) (exp3 ("def" insts "end") ("begin" insts-rescue-insts "end") ("do" insts "end") @@ -388,7 +388,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (cases (exp "then" insts) (cases "when" cases) (insts "else" insts)) (expseq (exp) );;(expseq "," expseq) - (hashvals (id "=>" exp1) (hashvals "," hashvals)) + (hashvals (exp1 "=>" exp1) (hashvals "," hashvals)) (insts-rescue-insts (insts) (insts-rescue-insts "rescue" insts-rescue-insts) (insts-rescue-insts "ensure" insts-rescue-insts)) @@ -406,17 +406,18 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." '((right "=") (right "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "<<=" ">>=" "&&=" "||=") - (left ".." "...") - (left "+" "-") - (left "*" "/" "%" "**") + (nonassoc ".." "...") (left "&&" "||") - (left "^" "&" "|") (nonassoc "<=>") - (nonassoc ">" ">=" "<" "<=") (nonassoc "==" "===" "!=") (nonassoc "=~" "!~") + (nonassoc ">" ">=" "<" "<=") + (left "^" "&" "|") (left "<<" ">>") - (right ".")))))) + (left "+" "-") + (left "*" "/" "%") + (left "**") + (assoc ".")))))) (defun ruby-smie--bosp () (save-excursion (skip-chars-backward " \t") @@ -443,8 +444,8 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (member (save-excursion (ruby-smie--backward-token)) '("iuwu-mod" "and" "or"))) (save-excursion - (forward-comment 1) - (eq (char-after) ?.)))))) + (forward-comment (point-max)) + (looking-at "&?\\.")))))) (defun ruby-smie--redundant-do-p (&optional skip) (save-excursion @@ -535,6 +536,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (line-end-position)) (ruby-smie--forward-token)) ;Fully redundant. (t ";"))) + ((equal tok "&.") ".") (t tok))))))))) (defun ruby-smie--backward-token () @@ -580,6 +582,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (line-end-position)) (ruby-smie--backward-token)) ;Fully redundant. (t ";"))) + ((equal tok "&.") ".") (t tok))))))) (defun ruby-smie--indent-to-stmt () @@ -627,19 +630,13 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." ;; because when `.' is inside the line, the ;; additional indentation from it looks out of place. ((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 (let ((parent (smie-indent--parent))) - (goto-char (cadr parent)) - (save-excursion - (unless (integerp (car parent)) (forward-char -1)) - (not (ruby-smie--bosp)))) - (progn - (setq smie--parent nil) - (smie-rule-parent-p ".")))) - (smie-rule-parent)))) + ;; Traverse up the call chain until the parent is not `.', + ;; or `.' at indentation, or at eol. + (while (and (not (ruby-smie--bosp)) + (equal (nth 2 (smie-backward-sexp ".")) ".") + (not (ruby-smie--bosp))) + (forward-char -1)) + (smie-indent-virtual)) (t (smie-rule-parent)))))) (`(:after . ,(or `"(" "[" "{")) ;; FIXME: Shouldn't this be the default behavior of @@ -659,7 +656,9 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (`(:before . ".") (if (smie-rule-sibling-p) (and ruby-align-chained-calls 0) - ruby-indent-level)) + (smie-backward-sexp ".") + (cons 'column (+ (current-column) + ruby-indent-level)))) (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) (smie-rule-parent)) (`(:before . "when") @@ -1375,7 +1374,7 @@ delimiter." (goto-char ruby-indent-point) (beginning-of-line) (skip-syntax-forward " ") - (if (looking-at "\\.[^.]") + (if (looking-at "\\.[^.]\\|&\\.") (+ indent ruby-indent-level) indent)))) |