* 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.
(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
(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)