]> code.delx.au - gnu-emacs/commitdiff
Also handle escaping when string begins with a quote
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 27 Jun 2016 04:26:46 +0000 (07:26 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 27 Jun 2016 04:31:52 +0000 (07:31 +0300)
* lisp/progmodes/ruby-mode.el (ruby-toggle-string-quotes):
Handle quoting of the first character in the string.

* test/lisp/progmodes/ruby-mode-tests.el
(ruby-toggle-string-quotes-quotes-correctly): Update.

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

index aa7c08c542f79dbcbf6e84ec72053fd6883213bf..e7b37acc3deb2855572ea5e277f51f1f8f6844e8 100644 (file)
@@ -1800,8 +1800,8 @@ If the result is do-end block, it will always be multiline."
             (buffer-substring-no-properties (1+ min) (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))))
+                (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\(\\`\\|[^\\\\]\\)'" "\\1\\\\'" content))
+              (replace-regexp-in-string "\\\\'" "'" (replace-regexp-in-string "\\(\\`\\|[^\\\\]\\)\"" "\\1\\\\\"" content))))
       (let ((orig-point (point)))
         (delete-region min max)
         (insert
index 5dd34f8ee415374d12b37e4c28bf1e6d9c9adf82..97f277bff41358d7a0a4aa709d350fa887585adf 100644 (file)
@@ -718,8 +718,8 @@ VALUES-PLIST is a list with alternating index and value elements."
 
 (ert-deftest ruby-toggle-string-quotes-quotes-correctly ()
   (let ((pairs
-         '(("puts 'foo\"\\''" . "puts \"foo\\\"'\"")
-           ("puts \"foo'\\\"\"" . "puts 'foo\\'\"'"))))
+         '(("puts '\"foo\"\\''" . "puts \"\\\"foo\\\"'\"")
+           ("puts \"'foo'\\\"\"" . "puts '\\'foo\\'\"'"))))
     (dolist (pair pairs)
       (ruby-with-temp-buffer (car pair)
         (beginning-of-line)