aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el49
1 files changed, 23 insertions, 26 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 36c1aed529e..972bf99145e 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'."
368 (exp (exp1) (exp "," exp) (exp "=" exp) 368 (exp (exp1) (exp "," exp) (exp "=" exp)
369 (id " @ " exp)) 369 (id " @ " exp))
370 (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) 370 (exp1 (exp2) (exp2 "?" exp1 ":" exp1))
371 (exp2 (exp3) (exp3 "." exp2)) 371 (exp2 (exp3) (exp3 "." exp3))
372 (exp3 ("def" insts "end") 372 (exp3 ("def" insts "end")
373 ("begin" insts-rescue-insts "end") 373 ("begin" insts-rescue-insts "end")
374 ("do" insts "end") 374 ("do" insts "end")
@@ -388,7 +388,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
388 (cases (exp "then" insts) 388 (cases (exp "then" insts)
389 (cases "when" cases) (insts "else" insts)) 389 (cases "when" cases) (insts "else" insts))
390 (expseq (exp) );;(expseq "," expseq) 390 (expseq (exp) );;(expseq "," expseq)
391 (hashvals (id "=>" exp1) (hashvals "," hashvals)) 391 (hashvals (exp1 "=>" exp1) (hashvals "," hashvals))
392 (insts-rescue-insts (insts) 392 (insts-rescue-insts (insts)
393 (insts-rescue-insts "rescue" insts-rescue-insts) 393 (insts-rescue-insts "rescue" insts-rescue-insts)
394 (insts-rescue-insts "ensure" insts-rescue-insts)) 394 (insts-rescue-insts "ensure" insts-rescue-insts))
@@ -406,17 +406,18 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
406 '((right "=") 406 '((right "=")
407 (right "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" 407 (right "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^="
408 "<<=" ">>=" "&&=" "||=") 408 "<<=" ">>=" "&&=" "||=")
409 (left ".." "...") 409 (nonassoc ".." "...")
410 (left "+" "-")
411 (left "*" "/" "%" "**")
412 (left "&&" "||") 410 (left "&&" "||")
413 (left "^" "&" "|")
414 (nonassoc "<=>") 411 (nonassoc "<=>")
415 (nonassoc ">" ">=" "<" "<=")
416 (nonassoc "==" "===" "!=") 412 (nonassoc "==" "===" "!=")
417 (nonassoc "=~" "!~") 413 (nonassoc "=~" "!~")
414 (nonassoc ">" ">=" "<" "<=")
415 (left "^" "&" "|")
418 (left "<<" ">>") 416 (left "<<" ">>")
419 (right ".")))))) 417 (left "+" "-")
418 (left "*" "/" "%")
419 (left "**")
420 (assoc "."))))))
420 421
421(defun ruby-smie--bosp () 422(defun ruby-smie--bosp ()
422 (save-excursion (skip-chars-backward " \t") 423 (save-excursion (skip-chars-backward " \t")
@@ -443,7 +444,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
443 (member (save-excursion (ruby-smie--backward-token)) 444 (member (save-excursion (ruby-smie--backward-token))
444 '("iuwu-mod" "and" "or"))) 445 '("iuwu-mod" "and" "or")))
445 (save-excursion 446 (save-excursion
446 (forward-comment 1) 447 (forward-comment (point-max))
447 (looking-at "&?\\.")))))) 448 (looking-at "&?\\."))))))
448 449
449(defun ruby-smie--redundant-do-p (&optional skip) 450(defun ruby-smie--redundant-do-p (&optional skip)
@@ -629,19 +630,13 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
629 ;; because when `.' is inside the line, the 630 ;; because when `.' is inside the line, the
630 ;; additional indentation from it looks out of place. 631 ;; additional indentation from it looks out of place.
631 ((smie-rule-parent-p ".") 632 ((smie-rule-parent-p ".")
632 (let (smie--parent) 633 ;; Traverse up the call chain until the parent is not `.',
633 (save-excursion 634 ;; or `.' at indentation, or at eol.
634 ;; Traverse up the parents until the parent is "." at 635 (while (and (not (ruby-smie--bosp))
635 ;; indentation, or any other token. 636 (equal (nth 2 (smie-backward-sexp ".")) ".")
636 (while (and (let ((parent (smie-indent--parent))) 637 (not (ruby-smie--bosp)))
637 (goto-char (cadr parent)) 638 (forward-char -1))
638 (save-excursion 639 (smie-indent-virtual))
639 (unless (integerp (car parent)) (forward-char -1))
640 (not (ruby-smie--bosp))))
641 (progn
642 (setq smie--parent nil)
643 (smie-rule-parent-p "."))))
644 (smie-rule-parent))))
645 (t (smie-rule-parent)))))) 640 (t (smie-rule-parent))))))
646 (`(:after . ,(or `"(" "[" "{")) 641 (`(:after . ,(or `"(" "[" "{"))
647 ;; FIXME: Shouldn't this be the default behavior of 642 ;; FIXME: Shouldn't this be the default behavior of
@@ -661,7 +656,9 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
661 (`(:before . ".") 656 (`(:before . ".")
662 (if (smie-rule-sibling-p) 657 (if (smie-rule-sibling-p)
663 (and ruby-align-chained-calls 0) 658 (and ruby-align-chained-calls 0)
664 ruby-indent-level)) 659 (smie-backward-sexp ".")
660 (cons 'column (+ (current-column)
661 ruby-indent-level))))
665 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 662 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure"))
666 (smie-rule-parent)) 663 (smie-rule-parent))
667 (`(:before . "when") 664 (`(:before . "when")
@@ -1377,7 +1374,7 @@ delimiter."
1377 (goto-char ruby-indent-point) 1374 (goto-char ruby-indent-point)
1378 (beginning-of-line) 1375 (beginning-of-line)
1379 (skip-syntax-forward " ") 1376 (skip-syntax-forward " ")
1380 (if (looking-at "\\.[^.]") 1377 (if (looking-at "\\.[^.]\\|&\\.")
1381 (+ indent ruby-indent-level) 1378 (+ indent ruby-indent-level)
1382 indent)))) 1379 indent))))
1383 1380
@@ -2176,7 +2173,7 @@ See `font-lock-syntax-table'.")
2176 'font-lock-string-face))) 2173 'font-lock-string-face)))
2177 ;; Perl-ish keywords. 2174 ;; Perl-ish keywords.
2178 "\\_<\\(?:BEGIN\\|END\\)\\_>\\|^__END__$" 2175 "\\_<\\(?:BEGIN\\|END\\)\\_>\\|^__END__$"
2179 ;; Variables. 2176 ;; Singleton objects.
2180 (,(concat ruby-font-lock-keyword-beg-re 2177 (,(concat ruby-font-lock-keyword-beg-re
2181 "\\_<\\(nil\\|true\\|false\\)\\_>") 2178 "\\_<\\(nil\\|true\\|false\\)\\_>")
2182 1 font-lock-constant-face) 2179 1 font-lock-constant-face)
@@ -2184,7 +2181,7 @@ See `font-lock-syntax-table'.")
2184 ("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" 2181 ("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>"
2185 (0 font-lock-builtin-face)) 2182 (0 font-lock-builtin-face))
2186 ;; Symbols. 2183 ;; Symbols.
2187 ("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?" 2184 ("\\(^\\|[^:]\\)\\(:@\\{0,2\\}\\(?:\\sw\\|\\s_\\)+\\)"
2188 (2 font-lock-constant-face) 2185 (2 font-lock-constant-face)
2189 (3 (unless (and (eq (char-before (match-end 3)) ?=) 2186 (3 (unless (and (eq (char-before (match-end 3)) ?=)
2190 (eq (char-after (match-end 3)) ?>)) 2187 (eq (char-after (match-end 3)) ?>))