]> git.eshelyaron.com Git - emacs.git/commitdiff
Support Ruby block arguments ending with , or *
authorNobuyoshi Nakada <nobu@ruby-lang.org>
Tue, 11 Dec 2018 01:12:46 +0000 (03:12 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 11 Dec 2018 01:14:35 +0000 (03:14 +0200)
* lisp/progmodes/ruby-mode.el (ruby-smie--forward-token):
Recognize punctuation before "closing-|" as a separate token.
(ruby-smie--backward-token): Same (bug#33487).

* test/lisp/progmodes/ruby-mode-tests.el
(ruby-forward-sexp-jumps-do-end-block-with-no-args)
(ruby-backward-sexp-jumps-do-end-block-with-no-args)
(ruby-forward-sexp-jumps-do-end-block-with-empty-args)
(ruby-backward-sexp-jumps-do-end-block-with-empty-args)
(ruby-forward-sexp-jumps-do-end-block-with-args)
(ruby-backward-sexp-jumps-do-end-block-with-args)
(ruby-forward-sexp-jumps-do-end-block-with-any-args)
(ruby-forward-sexp-jumps-do-end-block-with-expanded-one-arg)
(ruby-forward-sexp-jumps-do-end-block-with-one-and-any-args)
(ruby-backward-sexp-jumps-do-end-block-with-one-and-any-args):
New tests.

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

index 2f68f004e7b10b76e4a45edd7a345e001e6ee424..d60899cf182386035b614e986637926f1d9cfa09 100644 (file)
@@ -517,6 +517,9 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
              ((ruby-smie--opening-pipe-p) "opening-|")
              ((ruby-smie--closing-pipe-p) "closing-|")
              (t tok)))
+           ((string-match "\\`[^|]+|\\'" tok)
+            (forward-char -1)
+            (substring tok 0 -1))
            ((and (equal tok "") (looking-at "\\\\\n"))
             (goto-char (match-end 0)) (ruby-smie--forward-token))
            ((equal tok "do")
@@ -559,6 +562,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
            ((ruby-smie--opening-pipe-p) "opening-|")
            ((ruby-smie--closing-pipe-p) "closing-|")
            (t tok)))
+         ((string-match-p "\\`[^|]+|\\'" tok) "closing-|")
          ((string-match-p "\\`|[*&]\\'" tok)
           (forward-char 1)
           (substring tok 1))
index 72d83affaef892e7a0f523b1134b2df0a7b599db..afd6d65c9d1446a2bd3e9f953698767cf96680cf 100644 (file)
@@ -718,6 +718,96 @@ VALUES-PLIST is a list with alternating index and value elements."
     (ruby-backward-sexp)
     (should (= 2 (line-number-at-pos)))))
 
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-no-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do
+     |end")
+    (search-backward "do\n")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-no-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do
+     |end")
+    (goto-char (point-max))
+    (ruby-backward-sexp)
+    (should (looking-at "do$"))))
+
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-empty-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do ||
+     |end")
+    (search-backward "do ")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-empty-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do ||
+     |end")
+    (goto-char (point-max))
+    (ruby-backward-sexp)
+    (should (looking-at "do "))))
+
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |a,b|
+     |end")
+    (search-backward "do ")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |a,b|
+     |end")
+    (goto-char (point-max))
+    (ruby-backward-sexp)
+    (should (looking-at "do "))))
+
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-any-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |*|
+     |end")
+    (search-backward "do ")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-expanded-one-arg ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |a,|
+     |end")
+    (search-backward "do ")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-one-and-any-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |a,*|
+     |end")
+    (search-backward "do ")
+    (ruby-forward-sexp)
+    (should (eobp))))
+
+(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-one-and-any-args ()
+  (ruby-with-temp-buffer
+    (ruby-test-string
+     "proc do |a,*|
+     |end")
+    (goto-char (point-max))
+    (ruby-backward-sexp)
+    (should (looking-at "do "))))
+
 (ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
   (let ((pairs
          '(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"")