From 3729a3f88fd7ce1d8a1a7f2ea61e8c4d05e954ab Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 11 Dec 2018 03:12:46 +0200 Subject: [PATCH] Support Ruby block arguments ending with , or * * 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 | 4 ++ test/lisp/progmodes/ruby-mode-tests.el | 90 ++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 2f68f004e7b..d60899cf182 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -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)) diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 72d83affaef..afd6d65c9d1 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el @@ -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\\\"'\"") -- 2.39.2