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.el28
1 files changed, 20 insertions, 8 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index cb5fe11ada6..87454cdbbb5 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -310,10 +310,10 @@ explicitly declared in magic comment."
310 ("unless" insts "end") 310 ("unless" insts "end")
311 ("if" if-body "end") 311 ("if" if-body "end")
312 ("case" cases "end")) 312 ("case" cases "end"))
313 (formal-params ("opening-|" exp "|")) 313 (formal-params ("opening-|" exp "closing-|"))
314 (for-body (for-head ";" insts)) 314 (for-body (for-head ";" insts))
315 (for-head (id "in" exp)) 315 (for-head (id "in" exp))
316 (cases (exp "then" insts) ;; FIXME: Ruby also allows (exp ":" insts). 316 (cases (exp "then" insts)
317 (cases "when" cases) (insts "else" insts)) 317 (cases "when" cases) (insts "else" insts))
318 (expseq (exp) );;(expseq "," expseq) 318 (expseq (exp) );;(expseq "," expseq)
319 (hashvals (id "=>" exp1) (hashvals "," hashvals)) 319 (hashvals (id "=>" exp1) (hashvals "," hashvals))
@@ -337,9 +337,8 @@ explicitly declared in magic comment."
337 (left ".." "...") 337 (left ".." "...")
338 (left "+" "-") 338 (left "+" "-")
339 (left "*" "/" "%" "**") 339 (left "*" "/" "%" "**")
340 ;; (left "|") ; FIXME: Conflicts with | after block parameters.
341 (left "&&" "||") 340 (left "&&" "||")
342 (left "^" "&") 341 (left "^" "&" "|")
343 (nonassoc "<=>") 342 (nonassoc "<=>")
344 (nonassoc ">" ">=" "<" "<=") 343 (nonassoc ">" ">=" "<" "<=")
345 (nonassoc "==" "===" "!=") 344 (nonassoc "==" "===" "!=")
@@ -365,7 +364,8 @@ explicitly declared in magic comment."
365 (string-match "\\`\\s." (save-excursion 364 (string-match "\\`\\s." (save-excursion
366 (ruby-smie--backward-token)))) 365 (ruby-smie--backward-token))))
367 (and (eq (char-before) ?|) 366 (and (eq (char-before) ?|)
368 (eq (char-before (1- (point))) ?|)) 367 (member (save-excursion (ruby-smie--backward-token))
368 '("|" "||")))
369 (and (eq (car (syntax-after (1- (point)))) 2) 369 (and (eq (car (syntax-after (1- (point)))) 2)
370 (member (save-excursion (ruby-smie--backward-token)) 370 (member (save-excursion (ruby-smie--backward-token))
371 '("iuwu-mod" "and" "or"))) 371 '("iuwu-mod" "and" "or")))
@@ -385,6 +385,12 @@ explicitly declared in magic comment."
385 (or (eq ?\{ (char-before)) 385 (or (eq ?\{ (char-before))
386 (looking-back "\\_<do" (- (point) 2))))) 386 (looking-back "\\_<do" (- (point) 2)))))
387 387
388(defun ruby-smie--closing-pipe-p ()
389 (save-excursion
390 (if (eq ?| (char-before)) (forward-char -1))
391 (and (re-search-backward "|" (line-beginning-position) t)
392 (ruby-smie--opening-pipe-p))))
393
388(defun ruby-smie--args-separator-p (pos) 394(defun ruby-smie--args-separator-p (pos)
389 (and 395 (and
390 (< pos (line-end-position)) 396 (< pos (line-end-position))
@@ -442,7 +448,10 @@ explicitly declared in magic comment."
442 ((string-match-p "\\`|[*&]?\\'" tok) 448 ((string-match-p "\\`|[*&]?\\'" tok)
443 (forward-char (- 1 (length tok))) 449 (forward-char (- 1 (length tok)))
444 (setq tok "|") 450 (setq tok "|")
445 (if (ruby-smie--opening-pipe-p) "opening-|" tok)) 451 (cond
452 ((ruby-smie--opening-pipe-p) "opening-|")
453 ((ruby-smie--closing-pipe-p) "closing-|")
454 (t tok)))
446 ((and (equal tok "") (looking-at "\\\\\n")) 455 ((and (equal tok "") (looking-at "\\\\\n"))
447 (goto-char (match-end 0)) (ruby-smie--forward-token)) 456 (goto-char (match-end 0)) (ruby-smie--forward-token))
448 ((equal tok "do") 457 ((equal tok "do")
@@ -482,7 +491,10 @@ explicitly declared in magic comment."
482 (if (ruby-smie--bosp) 491 (if (ruby-smie--bosp)
483 tok "iuwu-mod")) 492 tok "iuwu-mod"))
484 ((equal tok "|") 493 ((equal tok "|")
485 (if (ruby-smie--opening-pipe-p) "opening-|" tok)) 494 (cond
495 ((ruby-smie--opening-pipe-p) "opening-|")
496 ((ruby-smie--closing-pipe-p) "closing-|")
497 (t tok)))
486 ((string-match-p "\\`|[*&]\\'" tok) 498 ((string-match-p "\\`|[*&]\\'" tok)
487 (forward-char 1) 499 (forward-char 1)
488 (substring tok 1)) 500 (substring tok 1))
@@ -545,7 +557,7 @@ explicitly declared in magic comment."
545 (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level 557 (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level
546 (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&" 558 (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&"
547 "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>" 559 "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>"
548 "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" 560 "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|"
549 "<<=" ">>=" "&&=" "||=" "and" "or")) 561 "<<=" ">>=" "&&=" "||=" "and" "or"))
550 (if (smie-rule-parent-p ";" nil) ruby-indent-level)) 562 (if (smie-rule-parent-p ";" nil) ruby-indent-level))
551 (`(:before . "begin") 563 (`(:before . "begin")