From f069bba87c15091288a3c89d8fbb5035e85e7c7f Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 29 Aug 2013 14:06:46 -0400 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for formal params of lambda expressions. (ruby-smie--implicit-semi-p): Refine rule. (ruby-smie--opening-pipe-p): New function. (ruby-smie--forward-token, ruby-smie--backward-token): Handle Ruby symbols and matched |...| for formal params. (ruby-smie-rules): Don't let the formal params of a "do" prevent it from being treated as hanging. Handle "rescue". Fixes: debbugs:15208 --- lisp/ChangeLog | 11 ++++++++++ lisp/progmodes/ruby-mode.el | 42 ++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ec6991504b..3f957874fc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-08-29 Stefan Monnier + + * progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for formal + params of lambda expressions. + (ruby-smie--implicit-semi-p): Refine rule (bug#15208). + (ruby-smie--opening-pipe-p): New function. + (ruby-smie--forward-token, ruby-smie--backward-token): Handle Ruby + symbols and matched |...| for formal params. + (ruby-smie-rules): Don't let the formal params of a "do" prevent it + from being treated as hanging. Handle "rescue". + 2013-08-29 Glenn Morris * progmodes/cc-engine.el (c-pull-open-brace): diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index c8fae7ba1e..7ecd207f4d 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -254,11 +254,13 @@ Also ignores spaces after parenthesis when 'space." ("for" for-body "end") ("[" expseq "]") ("{" hashvals "}") + ("{" insts "}") ("while" insts "end") ("until" insts "end") ("unless" insts "end") ("if" if-body "end") ("case" cases "end")) + (formal-params ("opening-|" exp "|")) (for-body (for-head ";" insts)) (for-head (id "in" exp)) (cases (exp "then" insts) ;; FIXME: Ruby also allows (exp ":" insts). @@ -285,10 +287,20 @@ Also ignores spaces after parenthesis when 'space." (save-excursion (skip-chars-backward " \t") (not (or (bolp) - (memq (char-before) '(?\; ?- ?+ ?* ?/ ?:)) + (and (memq (char-before) '(?\; ?- ?+ ?* ?/ ?: ?.)) + ;; Make sure it's not the end of a regexp. + (not (eq (car (syntax-after (1- (point)))) 7))) (and (memq (char-before) '(?\? ?=)) - (not (memq (char-syntax (char-before (1- (point)))) - '(?w ?_)))))))) + (let ((tok (ruby-smie--backward-token))) + (or (equal tok "?") + (string-match "\\`\\s." tok)))))))) + +(defun ruby-smie--opening-pipe-p () + (save-excursion + (if (eq ?| (char-before)) (forward-char -1)) + (skip-chars-backward " \t\n") + (or (eq ?\{ (char-before)) + (looking-back "\\_