]> git.eshelyaron.com Git - emacs.git/commitdiff
Strip trailing whitespaces at the end of converted do block
authorNobuyoshi Nakada <nobu@ruby-lang.org>
Mon, 22 Jul 2019 01:14:01 +0000 (10:14 +0900)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 25 Jul 2019 13:01:55 +0000 (16:01 +0300)
* lisp/progmodes/ruby-mode.el (ruby-brace-to-do-end):
Strip trailing whitespaces at the end of converted do block
(bug#36756).

https://bugs.ruby-lang.org/issues/16014
https://github.com/syl20bnr/spacemacs/issues/12548

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

index 8eadf018a674ca35853afcd7228b3791d96fc81a..340c689f02eb2711d1127ceabb148d5cfac413a1 100644 (file)
@@ -1690,7 +1690,8 @@ See `add-log-current-defun-function'."
     (when (eq (char-before) ?\})
       (delete-char -1)
       (when (save-excursion
-              (skip-chars-backward " \t")
+              (let ((n (skip-chars-backward " \t")))
+                (if (< n 0) (delete-char (- n))))
               (not (bolp)))
         (insert "\n"))
       (insert "end")
index efbe012427f2d58de70387b78e01d3dfdcf471d9..83fcdd8aa85c26d29a926a028bacb5b583b3f4d1 100644 (file)
@@ -369,7 +369,11 @@ VALUES-PLIST is a list with alternating index and value elements."
   (ruby-with-temp-buffer "foo {|b|\n}"
     (beginning-of-line)
     (ruby-toggle-block)
-    (should (string= "foo do |b|\nend" (buffer-string)))))
+    (should (string= "foo do |b|\nend" (buffer-string))))
+  (ruby-with-temp-buffer "foo {|b| b }"
+    (beginning-of-line)
+    (ruby-toggle-block)
+    (should (string= "foo do |b|\n  b\nend" (buffer-string)))))
 
 (ert-deftest ruby-toggle-block-to-brace ()
   (let ((pairs '((17 . "foo { |b| b + 2 }")