]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/ruby-mode.el (ruby-move-to-block): When we're at a
authorDmitry Gutov <dgutov@yandex.ru>
Wed, 3 Jul 2013 01:02:18 +0000 (05:02 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 3 Jul 2013 01:02:18 +0000 (05:02 +0400)
middle of block statement initially, lower the depth.  Remove
FIXME comment, not longer valid.  Remove middle of block statement
detection, no need to do that anymore since we've been using
`ruby-parse-region' here.

lisp/ChangeLog
lisp/progmodes/ruby-mode.el
test/automated/ruby-mode-tests.el

index 86a27f9b5bd4fb9b435fa71b3dcf83766a43aa89..9a5af5e31d2f12b7c2cbf844e6cc3ea66def03ae 100644 (file)
@@ -1,3 +1,11 @@
+2013-07-03  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * progmodes/ruby-mode.el (ruby-move-to-block): When we're at a
+       middle of block statement initially, lower the depth.  Remove
+       FIXME comment, not longer valid.  Remove middle of block statement
+       detection, no need to do that anymore since we've been using
+       `ruby-parse-region' here.
+
 2013-07-02  Jan Djärv  <jan.h.d@swipnet.se>
 
        * term/ns-win.el (display-format-alist): Use .* (Bug#14765).
index 0292e40b986aef0079fdcb1aa8afd7b1ad0cf1e5..f5f829ce0e8f0f9b5781e54e990a3edcbed2753d 100644 (file)
@@ -990,13 +990,14 @@ calculating indentation on the lines after it."
 (defun ruby-move-to-block (n)
   "Move to the beginning (N < 0) or the end (N > 0) of the
 current block, a sibling block, or an outer block.  Do that (abs N) times."
+  (back-to-indentation)
   (let ((signum (if (> n 0) 1 -1))
         (backward (< n 0))
-        (depth (or (nth 2 (ruby-parse-region (line-beginning-position)
-                                             (line-end-position)))
-                   0))
+        (depth (or (nth 2 (ruby-parse-region (point) (line-end-position))) 0))
         case-fold-search
         down done)
+    (when (looking-at ruby-block-mid-re)
+      (setq depth (+ depth signum)))
     (when (< (* depth signum) 0)
       ;; Moving end -> end or beginning -> beginning.
       (setq depth 0))
@@ -1033,22 +1034,16 @@ current block, a sibling block, or an outer block.  Do that (abs N) times."
             (unless (car state) ; Line ends with unfinished string.
               (setq depth (+ (nth 2 state) depth))))
           (cond
-           ;; Deeper indentation, we found a block.
-           ;; FIXME: We can't recognize empty blocks this way.
+           ;; Increased depth, we found a block.
            ((> (* signum depth) 0)
             (setq down t))
-           ;; Block found, and same indentation as when started, stop.
+           ;; We're at the same depth as when we started, and we've
+           ;; encountered a block before.  Stop.
            ((and down (zerop depth))
             (setq done t))
-           ;; Shallower indentation, means outer block, can stop now.
+           ;; Lower depth, means outer block, can stop now.
            ((< (* signum depth) 0)
-            (setq done t)))))
-        (if done
-            (save-excursion
-              (back-to-indentation)
-              ;; Not really at the first or last line of the block, move on.
-              (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
-                  (setq done nil))))))
+            (setq done t)))))))
     (back-to-indentation)))
 
 (defun ruby-beginning-of-block (&optional arg)
index a18899df02f65eb37667740bfbdf57bd2ca536ae..02582e8ad2d03d3fd22f212575c16152711cf5ac 100644 (file)
@@ -546,6 +546,17 @@ VALUES-PLIST is a list with alternating index and value elements."
       (ruby-beginning-of-block))
     (should (= 1 (line-number-at-pos)))))
 
+(ert-deftest ruby-move-to-block-moves-from-else-to-if ()
+  (ruby-with-temp-buffer (ruby-test-string
+                          "if true
+                          |  nested_block do
+                          |  end
+                          |else
+                          |end")
+    (goto-line 4)
+    (ruby-beginning-of-block)
+    (should (= 1 (line-number-at-pos)))))
+
 (ert-deftest ruby-beginning-of-defun-does-not-fold-case ()
   (ruby-with-temp-buffer
       (ruby-test-string