From 238150c8ff55ab6d74f0fdcc7f163c8ee98c3749 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 9 Oct 2013 06:18:01 +0300 Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-smie-rules): Indent after hanging iuwu-mod token. (ruby-smie--implicit-semi-p): Prohibit implicit semicolon after hanging iuwu-mod token. (ruby-smie--forward-token): Do not include a dot after a token in that token. (ruby-smie--backward-token): Likewise. --- lisp/ChangeLog | 10 ++++++++++ lisp/progmodes/ruby-mode.el | 13 ++++++++----- test/automated/ruby-mode-tests.el | 7 +++++-- test/indent/ruby.rb | 8 ++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 14d7b4f344c..73bf12dfb4b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2013-10-09 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-smie-rules): Indent after hanging + iuwu-mod token. + (ruby-smie--implicit-semi-p): Prohibit implicit semicolon after + hanging iuwu-mod token. + (ruby-smie--forward-token): Do not include a dot after a token in + that token. + (ruby-smie--backward-token): Likewise. + 2013-10-08 Juri Linkov * isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t] diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index b34143dea17..f734dc50e47 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -296,6 +296,9 @@ Also ignores spaces after parenthesis when 'space." (let ((tok (save-excursion (ruby-smie--backward-token)))) (or (equal tok "?") (string-match "\\`\\s." tok)))) + (and (eq (car (syntax-after (1- (point)))) 2) + (equal (save-excursion (ruby-smie--backward-token)) + "iuwu-mod")) (save-excursion (forward-comment 1) (eq (char-after) ?.)))))) @@ -334,9 +337,6 @@ Also ignores spaces after parenthesis when 'space." (if (looking-at ":\\s.+") (progn (goto-char (match-end 0)) (match-string 0)) ;; bug#15208. (let ((tok (smie-default-forward-token))) - (when (eq ?. (char-after)) - (forward-char 1) - (setq tok (concat tok "." (ruby-smie--forward-id)))) (cond ((member tok '("unless" "if" "while" "until")) (if (save-excursion (forward-word -1) (ruby-smie--bosp)) @@ -375,7 +375,7 @@ Also ignores spaces after parenthesis when 'space." (let ((tok (smie-default-backward-token))) (when (eq ?. (char-before)) (forward-char -1) - (setq tok (concat (ruby-smie--backward-id) "." tok))) + (setq tok (concat "." tok))) (when (and (eq ?: (char-before)) (string-match "\\`\\s." tok)) (forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208. (cond @@ -394,6 +394,9 @@ Also ignores spaces after parenthesis when 'space." (line-end-position)) (ruby-smie--backward-token)) ;Fully redundant. (t ";"))) + ;; FIXME: We shouldn't merge the dot with preceding token here + ;; either, but not doing that breaks indentation of hanging + ;; method calls with dot on the first line. ((equal tok ".") (concat (ruby-smie--backward-id) tok)) (t tok))))))) @@ -419,7 +422,7 @@ Also ignores spaces after parenthesis when 'space." ;; when the opening statement is hanging. (when (smie-rule-hanging-p) (smie-backward-sexp 'halfsexp) (smie-indent-virtual))) - (`(:after . "=") 2) + (`(:after . ,(or "=" "iuwu-mod")) 2) (`(:before . "do") (when (or (smie-rule-hanging-p) (save-excursion diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index 861ab9b6125..86b123f9b14 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -594,6 +594,9 @@ VALUES-PLIST is a list with alternating index and value elements." | def foo | self.end | D.new.class + | [1, 2, 3].map do |i| + | i + 1 + | end.sum | end |end")) @@ -601,11 +604,11 @@ VALUES-PLIST is a list with alternating index and value elements." (ruby-with-temp-buffer ruby-sexp-test-example (goto-line 2) (ruby-forward-sexp) - (should (= 5 (line-number-at-pos))))) + (should (= 8 (line-number-at-pos))))) (ert-deftest ruby-backward-sexp-skips-method-calls-with-keyword-names () (ruby-with-temp-buffer ruby-sexp-test-example - (goto-line 5) + (goto-line 8) (end-of-line) (ruby-backward-sexp) (should (= 2 (line-number-at-pos))))) diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 2b2b95bf47b..48275ee3e31 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb @@ -148,10 +148,14 @@ z = { } } +foo if + bar + # Examples below still fail with `ruby-use-smie' on: foo + bar -foo if - bar +foo = [1, 2, 3].map do |i| + i + 1 +end -- 2.39.2