From 15c307417f7bc13b27f06994dd931cb04873a26f Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 27 Jun 2016 07:26:46 +0300 Subject: [PATCH] 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. --- lisp/progmodes/ruby-mode.el | 4 ++-- test/lisp/progmodes/ruby-mode-tests.el | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index aa7c08c542..e7b37acc3d 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -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 diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el index 5dd34f8ee4..97f277bff4 100644 --- a/test/lisp/progmodes/ruby-mode-tests.el +++ b/test/lisp/progmodes/ruby-mode-tests.el @@ -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) -- 2.39.2