* lisp/progmodes/ruby-mode.el (ruby-smie-rules): Indent after hanging
authorDmitry Gutov <dgutov@yandex.ru>
Wed, 9 Oct 2013 03:18:01 +0000 (06:18 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 9 Oct 2013 03:18:01 +0000 (06:18 +0300)
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
lisp/progmodes/ruby-mode.el
test/automated/ruby-mode-tests.el
test/indent/ruby.rb

index 14d7b4f..73bf12d 100644 (file)
@@ -1,3 +1,13 @@
+2013-10-09  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * 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  <juri@jurta.org>
 
        * isearch.el (isearch-help-map, isearch-mode-map): Don't bind [t]
index b34143d..f734dc5 100644 (file)
@@ -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
index 861ab9b..86b123f 100644 (file)
@@ -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)))))
index 2b2b95b..48275ee 100644 (file)
@@ -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