Skip to content
Browse files

Automatically add/remove escape string quotes.

  • Loading branch information...
1 parent 7705398 commit d665094e6e2e2852814e0e3cb481160ee1f471fa @rejeep committed
Showing with 32 additions and 0 deletions.
  1. +28 −0 features/string-conversion.feature
  2. +4 −0 ruby-tools.el
View
28 features/string-conversion.feature
@@ -57,3 +57,31 @@ Feature: String conversion
And I go to point "2"
And I press "C-'"
Then I should see "''"
+
+ Scenario: Turn single quote string with quotes to double quote string
+ When I insert "'foo \' bar'"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-""
+ Then I should see ""foo ' bar""
+
+ Scenario: Turn single quote string with double quote inside to double quote string
+ When I insert "'foo " bar'"
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-""
+ Then I should see ""foo \" bar""
+
+ Scenario: Turn double quote string with quotes to single quote string
+ When I insert ""foo \" bar""
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-'"
+ Then I should see "'foo " bar'"
+
+ Scenario: Turn double quote string with single quote inside to single quote string
+ When I insert ""foo ' bar""
+ And I turn on ruby-mode
+ And I go to point "2"
+ And I press "C-'"
+ Then I should see "'foo \' bar'"
View
4 ruby-tools.el
@@ -140,6 +140,10 @@
(max (nth 1 region))
(content
(buffer-substring-no-properties (1+ min) (if at-symbol max (1- max)))))
+ (setq content
+ (if (equal string-quote "'")
+ (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\([^\\\\]\\)'" "\\1\\\\'" content))
+ (replace-regexp-in-string "\\\\\'" "'" (replace-regexp-in-string "\\([^\\\\]\\)\"" "\\1\\\\\"" content))))
(delete-region min max)
(insert
(format "%s%s%s" string-quote content string-quote))))))

0 comments on commit d665094

Please sign in to comment.
Something went wrong with that request. Please try again.