From: Dmitry Gutov Date: Wed, 3 Jul 2013 01:02:18 +0000 (+0400) Subject: * lisp/progmodes/ruby-mode.el (ruby-move-to-block): When we're at a X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1946 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3086ca2e2cf739cc7fd667b16c676522aecf4112;p=emacs.git * lisp/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. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 86a27f9b5bd..9a5af5e31d2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-07-03 Dmitry Gutov + + * 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 * term/ns-win.el (display-format-alist): Use .* (Bug#14765). diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 0292e40b986..f5f829ce0e8 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -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) diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el index a18899df02f..02582e8ad2d 100644 --- a/test/automated/ruby-mode-tests.el +++ b/test/automated/ruby-mode-tests.el @@ -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