unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36756: 26.2; ruby-toggle-block does not chomp trailing whitespaces in block
@ 2019-07-22  1:52 Nobuyoshi Nakada
  2019-07-25 13:02 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Nobuyoshi Nakada @ 2019-07-22  1:52 UTC (permalink / raw)
  To: 36756

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

Current ruby-brace-to-do-end function does not remove trailing spaces at 
the end of the block.

This issue was originally reported at 
https://github.com/syl20bnr/spacemacs/issues/12548 and then 
https://bugs.ruby-lang.org/issues/16014.



[-- Attachment #2: 0001-Strip-trailing-whitespaces-at-the-end-of-converted-d.patch --]
[-- Type: text/plain, Size: 1834 bytes --]

From 5daa8f5946e50dd3c461079442452115f47e44a1 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
Date: Mon, 22 Jul 2019 10:14:01 +0900
Subject: [PATCH] Strip trailing whitespaces at the end of converted do block

* lisp/progmodes/ruby-mode.el (ruby-brace-to-do-end): Strip
trailing whitespaces at the end of converted do block.

https://bugs.ruby-lang.org/issues/16014
https://github.com/syl20bnr/spacemacs/issues/12548
---
 lisp/progmodes/ruby-mode.el            | 3 ++-
 test/lisp/progmodes/ruby-mode-tests.el | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 8eadf018..1fe832d9 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1690,7 +1690,8 @@ ruby-brace-to-do-end
     (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")
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el
index efbe0124..83fcdd8a 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -369,7 +369,11 @@ ruby-toggle-block-to-do-end
   (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 }")
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#36756: 26.2; ruby-toggle-block does not chomp trailing whitespaces in block
  2019-07-22  1:52 bug#36756: 26.2; ruby-toggle-block does not chomp trailing whitespaces in block Nobuyoshi Nakada
@ 2019-07-25 13:02 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2019-07-25 13:02 UTC (permalink / raw)
  To: Nobuyoshi Nakada, 36756-done

Version: 27.1

On 22.07.2019 4:52, Nobuyoshi Nakada wrote:
> Current ruby-brace-to-do-end function does not remove trailing spaces at 
> the end of the block.
> 
> This issue was originally reported at 
> https://github.com/syl20bnr/spacemacs/issues/12548 and then 
> https://bugs.ruby-lang.org/issues/16014.

Thank you, I've pushed the patch.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-25 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22  1:52 bug#36756: 26.2; ruby-toggle-block does not chomp trailing whitespaces in block Nobuyoshi Nakada
2019-07-25 13:02 ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).