Also handle escaping when string begins with a quote

* 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.
This commit is contained in:
Dmitry Gutov 2016-06-27 07:26:46 +03:00
parent 7f02dedfca
commit 15c307417f
2 changed files with 4 additions and 4 deletions

View 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

View 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)