From b68e29263fbe7c31a54c0dab55a0121701ad8ec3 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 11 Oct 2013 05:11:37 +0300 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie--implicit-semi-p): Split the cases of ? and =. (ruby-smie-rules): Simplify the "do" rule. The cases when the predicate would return nil are almost non-existent. (ruby-smie--redundant-do-p): Include "until" and "for" statements. --- lisp/ChangeLog | 6 ++++++ lisp/progmodes/ruby-mode.el | 25 +++++++------------------ test/indent/ruby.rb | 4 ++++ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 362447e651c..1c1a5701602 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2013-10-11 Dmitry Gutov + * progmodes/ruby-mode.el (ruby-smie--implicit-semi-p): Split the + cases of ? and =. + (ruby-smie-rules): Simplify the "do" rule. The cases when the + predicate would return nil are almost non-existent. + (ruby-smie--redundant-do-p): Include "until" and "for" statements. + * emacs-lisp/smie.el (smie--matching-block-data): Invalidate the cache also after commands that modify the buffer but don't move point. diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index f734dc50e47..2f922162586 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -292,10 +292,11 @@ Also ignores spaces after parenthesis when 'space." '(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\[ ?\( ?\{ ?\\)) ;; Make sure it's not the end of a regexp. (not (eq (car (syntax-after (1- (point)))) 7))) - (and (memq (char-before) '(?\? ?=)) - (let ((tok (save-excursion (ruby-smie--backward-token)))) - (or (equal tok "?") - (string-match "\\`\\s." tok)))) + (and (eq (char-before) ?\?) + (equal (save-excursion (ruby-smie--backward-token)) "?")) + (and (eq (char-before) ?=) + (string-match "\\`\\s." (save-excursion + (ruby-smie--backward-token)))) (and (eq (car (syntax-after (1- (point)))) 2) (equal (save-excursion (ruby-smie--backward-token)) "iuwu-mod")) @@ -306,7 +307,7 @@ Also ignores spaces after parenthesis when 'space." (defun ruby-smie--redundant-do-p (&optional skip) (save-excursion (if skip (backward-word 1)) - (member (nth 2 (smie-backward-sexp ";")) '("while")))) + (member (nth 2 (smie-backward-sexp ";")) '("while" "until" "for")))) (defun ruby-smie--opening-pipe-p () (save-excursion @@ -423,19 +424,7 @@ Also ignores spaces after parenthesis when 'space." (when (smie-rule-hanging-p) (smie-backward-sexp 'halfsexp) (smie-indent-virtual))) (`(:after . ,(or "=" "iuwu-mod")) 2) - (`(:before . "do") - (when (or (smie-rule-hanging-p) - (save-excursion - (forward-word 1) ;Skip "do" - (skip-chars-forward " \t") - (and (equal (save-excursion (ruby-smie--forward-token)) - "opening-|") - (save-excursion (forward-sexp 1) - (skip-chars-forward " \t") - (or (eolp) - (looking-at comment-start-skip)))))) - ;; `(column . ,(smie-indent-virtual)) - (smie-rule-parent))) + (`(:before . "do") (smie-rule-parent)) (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 0) (`(:before . ,(or `"when")) (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 48275ee3e31..b280ec93ce2 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -151,6 +151,10 @@ z = { foo if bar +if foo? + bar +end + # Examples below still fail with `ruby-use-smie' on: foo + -- 2.39.2