aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2013-07-03 05:02:18 +0400
committerDmitry Gutov2013-07-03 05:02:18 +0400
commit3086ca2e2cf739cc7fd667b16c676522aecf4112 (patch)
treee49bfa18fae35f17ed64096e8d9d2c02e5e84de5
parent9bd3668269180bb28ee33ded00010ab1f5ae6dd6 (diff)
downloademacs-3086ca2e2cf739cc7fd667b16c676522aecf4112.tar.gz
emacs-3086ca2e2cf739cc7fd667b16c676522aecf4112.zip
* 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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/ruby-mode.el23
-rw-r--r--test/automated/ruby-mode-tests.el11
3 files changed, 28 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 86a27f9b5bd..9a5af5e31d2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-07-03 Dmitry Gutov <dgutov@yandex.ru>
2
3 * progmodes/ruby-mode.el (ruby-move-to-block): When we're at a
4 middle of block statement initially, lower the depth. Remove
5 FIXME comment, not longer valid. Remove middle of block statement
6 detection, no need to do that anymore since we've been using
7 `ruby-parse-region' here.
8
12013-07-02 Jan Djärv <jan.h.d@swipnet.se> 92013-07-02 Jan Djärv <jan.h.d@swipnet.se>
2 10
3 * term/ns-win.el (display-format-alist): Use .* (Bug#14765). 11 * 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."
990(defun ruby-move-to-block (n) 990(defun ruby-move-to-block (n)
991 "Move to the beginning (N < 0) or the end (N > 0) of the 991 "Move to the beginning (N < 0) or the end (N > 0) of the
992current block, a sibling block, or an outer block. Do that (abs N) times." 992current block, a sibling block, or an outer block. Do that (abs N) times."
993 (back-to-indentation)
993 (let ((signum (if (> n 0) 1 -1)) 994 (let ((signum (if (> n 0) 1 -1))
994 (backward (< n 0)) 995 (backward (< n 0))
995 (depth (or (nth 2 (ruby-parse-region (line-beginning-position) 996 (depth (or (nth 2 (ruby-parse-region (point) (line-end-position))) 0))
996 (line-end-position)))
997 0))
998 case-fold-search 997 case-fold-search
999 down done) 998 down done)
999 (when (looking-at ruby-block-mid-re)
1000 (setq depth (+ depth signum)))
1000 (when (< (* depth signum) 0) 1001 (when (< (* depth signum) 0)
1001 ;; Moving end -> end or beginning -> beginning. 1002 ;; Moving end -> end or beginning -> beginning.
1002 (setq depth 0)) 1003 (setq depth 0))
@@ -1033,22 +1034,16 @@ current block, a sibling block, or an outer block. Do that (abs N) times."
1033 (unless (car state) ; Line ends with unfinished string. 1034 (unless (car state) ; Line ends with unfinished string.
1034 (setq depth (+ (nth 2 state) depth)))) 1035 (setq depth (+ (nth 2 state) depth))))
1035 (cond 1036 (cond
1036 ;; Deeper indentation, we found a block. 1037 ;; Increased depth, we found a block.
1037 ;; FIXME: We can't recognize empty blocks this way.
1038 ((> (* signum depth) 0) 1038 ((> (* signum depth) 0)
1039 (setq down t)) 1039 (setq down t))
1040 ;; Block found, and same indentation as when started, stop. 1040 ;; We're at the same depth as when we started, and we've
1041 ;; encountered a block before. Stop.
1041 ((and down (zerop depth)) 1042 ((and down (zerop depth))
1042 (setq done t)) 1043 (setq done t))
1043 ;; Shallower indentation, means outer block, can stop now. 1044 ;; Lower depth, means outer block, can stop now.
1044 ((< (* signum depth) 0) 1045 ((< (* signum depth) 0)
1045 (setq done t))))) 1046 (setq done t)))))))
1046 (if done
1047 (save-excursion
1048 (back-to-indentation)
1049 ;; Not really at the first or last line of the block, move on.
1050 (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
1051 (setq done nil))))))
1052 (back-to-indentation))) 1047 (back-to-indentation)))
1053 1048
1054(defun ruby-beginning-of-block (&optional arg) 1049(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."
546 (ruby-beginning-of-block)) 546 (ruby-beginning-of-block))
547 (should (= 1 (line-number-at-pos))))) 547 (should (= 1 (line-number-at-pos)))))
548 548
549(ert-deftest ruby-move-to-block-moves-from-else-to-if ()
550 (ruby-with-temp-buffer (ruby-test-string
551 "if true
552 | nested_block do
553 | end
554 |else
555 |end")
556 (goto-line 4)
557 (ruby-beginning-of-block)
558 (should (= 1 (line-number-at-pos)))))
559
549(ert-deftest ruby-beginning-of-defun-does-not-fold-case () 560(ert-deftest ruby-beginning-of-defun-does-not-fold-case ()
550 (ruby-with-temp-buffer 561 (ruby-with-temp-buffer
551 (ruby-test-string 562 (ruby-test-string