From 7b08f97e71cea0fde24d9a81a8ca2e8366ff110f Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 12 Nov 2013 16:15:14 +0200 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between binary "|" operator and closing block args delimiter. Remove FIXME comment referring to Ruby 1.8-only syntax. (ruby-smie--implicit-semi-p): Not after "|" operator. (ruby-smie--closing-pipe-p): New function. (ruby-smie--forward-token, ruby-smie--backward-token): Use it. (ruby-smie-rules): Indent after "|". --- lisp/ChangeLog | 10 ++++++++++ lisp/progmodes/ruby-mode.el | 28 ++++++++++++++++++++-------- 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 @@ +2013-11-12 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-smie-grammar): Disambiguate between + binary "|" operator and closing block args delimiter. Remove + FIXME comment referring to Ruby 1.8-only syntax. + (ruby-smie--implicit-semi-p): Not after "|" operator. + (ruby-smie--closing-pipe-p): New function. + (ruby-smie--forward-token, ruby-smie--backward-token): Use it. + (ruby-smie-rules): Indent after "|". + 2013-11-12 Glenn Morris * 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." ("unless" insts "end") ("if" if-body "end") ("case" cases "end")) - (formal-params ("opening-|" exp "|")) + (formal-params ("opening-|" exp "closing-|")) (for-body (for-head ";" insts)) (for-head (id "in" exp)) - (cases (exp "then" insts) ;; FIXME: Ruby also allows (exp ":" insts). + (cases (exp "then" insts) (cases "when" cases) (insts "else" insts)) (expseq (exp) );;(expseq "," expseq) (hashvals (id "=>" exp1) (hashvals "," hashvals)) @@ -337,9 +337,8 @@ explicitly declared in magic comment." (left ".." "...") (left "+" "-") (left "*" "/" "%" "**") - ;; (left "|") ; FIXME: Conflicts with | after block parameters. (left "&&" "||") - (left "^" "&") + (left "^" "&" "|") (nonassoc "<=>") (nonassoc ">" ">=" "<" "<=") (nonassoc "==" "===" "!=") @@ -365,7 +364,8 @@ explicitly declared in magic comment." (string-match "\\`\\s." (save-excursion (ruby-smie--backward-token)))) (and (eq (char-before) ?|) - (eq (char-before (1- (point))) ?|)) + (member (save-excursion (ruby-smie--backward-token)) + '("|" "||"))) (and (eq (car (syntax-after (1- (point)))) 2) (member (save-excursion (ruby-smie--backward-token)) '("iuwu-mod" "and" "or"))) @@ -385,6 +385,12 @@ explicitly declared in magic comment." (or (eq ?\{ (char-before)) (looking-back "\\_" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>" - "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" + "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|" "<<=" ">>=" "&&=" "||=" "and" "or")) (if (smie-rule-parent-p ";" nil) ruby-indent-level)) (`(: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 end end +foo | + bar + foo || begin bar -- 2.11.4.GIT