aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada2018-12-11 03:12:46 +0200
committerDmitry Gutov2018-12-11 03:14:35 +0200
commit3729a3f88fd7ce1d8a1a7f2ea61e8c4d05e954ab (patch)
tree0fe2191e9d64bbe41e3c9984fd0d8119c6d8a398
parent0054961acf319378a588bda1df7d32d2bc0f284d (diff)
downloademacs-3729a3f88fd7ce1d8a1a7f2ea61e8c4d05e954ab.tar.gz
emacs-3729a3f88fd7ce1d8a1a7f2ea61e8c4d05e954ab.zip
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.
-rw-r--r--lisp/progmodes/ruby-mode.el4
-rw-r--r--test/lisp/progmodes/ruby-mode-tests.el90
2 files changed, 94 insertions, 0 deletions
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'."
517 ((ruby-smie--opening-pipe-p) "opening-|") 517 ((ruby-smie--opening-pipe-p) "opening-|")
518 ((ruby-smie--closing-pipe-p) "closing-|") 518 ((ruby-smie--closing-pipe-p) "closing-|")
519 (t tok))) 519 (t tok)))
520 ((string-match "\\`[^|]+|\\'" tok)
521 (forward-char -1)
522 (substring tok 0 -1))
520 ((and (equal tok "") (looking-at "\\\\\n")) 523 ((and (equal tok "") (looking-at "\\\\\n"))
521 (goto-char (match-end 0)) (ruby-smie--forward-token)) 524 (goto-char (match-end 0)) (ruby-smie--forward-token))
522 ((equal tok "do") 525 ((equal tok "do")
@@ -559,6 +562,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
559 ((ruby-smie--opening-pipe-p) "opening-|") 562 ((ruby-smie--opening-pipe-p) "opening-|")
560 ((ruby-smie--closing-pipe-p) "closing-|") 563 ((ruby-smie--closing-pipe-p) "closing-|")
561 (t tok))) 564 (t tok)))
565 ((string-match-p "\\`[^|]+|\\'" tok) "closing-|")
562 ((string-match-p "\\`|[*&]\\'" tok) 566 ((string-match-p "\\`|[*&]\\'" tok)
563 (forward-char 1) 567 (forward-char 1)
564 (substring tok 1)) 568 (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."
718 (ruby-backward-sexp) 718 (ruby-backward-sexp)
719 (should (= 2 (line-number-at-pos))))) 719 (should (= 2 (line-number-at-pos)))))
720 720
721(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-no-args ()
722 (ruby-with-temp-buffer
723 (ruby-test-string
724 "proc do
725 |end")
726 (search-backward "do\n")
727 (ruby-forward-sexp)
728 (should (eobp))))
729
730(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-no-args ()
731 (ruby-with-temp-buffer
732 (ruby-test-string
733 "proc do
734 |end")
735 (goto-char (point-max))
736 (ruby-backward-sexp)
737 (should (looking-at "do$"))))
738
739(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-empty-args ()
740 (ruby-with-temp-buffer
741 (ruby-test-string
742 "proc do ||
743 |end")
744 (search-backward "do ")
745 (ruby-forward-sexp)
746 (should (eobp))))
747
748(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-empty-args ()
749 (ruby-with-temp-buffer
750 (ruby-test-string
751 "proc do ||
752 |end")
753 (goto-char (point-max))
754 (ruby-backward-sexp)
755 (should (looking-at "do "))))
756
757(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-args ()
758 (ruby-with-temp-buffer
759 (ruby-test-string
760 "proc do |a,b|
761 |end")
762 (search-backward "do ")
763 (ruby-forward-sexp)
764 (should (eobp))))
765
766(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-args ()
767 (ruby-with-temp-buffer
768 (ruby-test-string
769 "proc do |a,b|
770 |end")
771 (goto-char (point-max))
772 (ruby-backward-sexp)
773 (should (looking-at "do "))))
774
775(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-any-args ()
776 (ruby-with-temp-buffer
777 (ruby-test-string
778 "proc do |*|
779 |end")
780 (search-backward "do ")
781 (ruby-forward-sexp)
782 (should (eobp))))
783
784(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-expanded-one-arg ()
785 (ruby-with-temp-buffer
786 (ruby-test-string
787 "proc do |a,|
788 |end")
789 (search-backward "do ")
790 (ruby-forward-sexp)
791 (should (eobp))))
792
793(ert-deftest ruby-forward-sexp-jumps-do-end-block-with-one-and-any-args ()
794 (ruby-with-temp-buffer
795 (ruby-test-string
796 "proc do |a,*|
797 |end")
798 (search-backward "do ")
799 (ruby-forward-sexp)
800 (should (eobp))))
801
802(ert-deftest ruby-backward-sexp-jumps-do-end-block-with-one-and-any-args ()
803 (ruby-with-temp-buffer
804 (ruby-test-string
805 "proc do |a,*|
806 |end")
807 (goto-char (point-max))
808 (ruby-backward-sexp)
809 (should (looking-at "do "))))
810
721(ert-deftest ruby-toggle-string-quotes-quotes-correctly () 811(ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
722 (let ((pairs 812 (let ((pairs
723 '(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"") 813 '(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"")