diff options
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 28 | ||||
| -rw-r--r-- | test/indent/ruby.rb | 3 |
3 files changed, 33 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5deb1c96dc3..a0446324f66 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2013-11-12 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between | ||
| 4 | binary "|" operator and closing block args delimiter. Remove | ||
| 5 | FIXME comment referring to Ruby 1.8-only syntax. | ||
| 6 | (ruby-smie--implicit-semi-p): Not after "|" operator. | ||
| 7 | (ruby-smie--closing-pipe-p): New function. | ||
| 8 | (ruby-smie--forward-token, ruby-smie--backward-token): Use it. | ||
| 9 | (ruby-smie-rules): Indent after "|". | ||
| 10 | |||
| 1 | 2013-11-12 Glenn Morris <rgm@gnu.org> | 11 | 2013-11-12 Glenn Morris <rgm@gnu.org> |
| 2 | 12 | ||
| 3 | * ps-print.el (ps-face-attribute-list): | 13 | * ps-print.el (ps-face-attribute-list): |
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") |
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 1d2eb08db94..a3ab73bcfb5 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb | |||
| @@ -285,6 +285,9 @@ bar 1 do | |||
| 285 | end | 285 | end |
| 286 | end | 286 | end |
| 287 | 287 | ||
| 288 | foo | | ||
| 289 | bar | ||
| 290 | |||
| 288 | foo || | 291 | foo || |
| 289 | begin | 292 | begin |
| 290 | bar | 293 | bar |