From 378d20f80d74a142aa30c27e1f7412d48c650f84 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 6 Dec 2013 07:47:47 +0000 Subject: ruby-mode.el: expand/unexpand block * misc/ruby-mode.el (ruby-brace-to-do-end): split single line block. * misc/ruby-mode.el (ruby-do-end-to-brace): shrink single line block to one line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- misc/ruby-mode.el | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'misc') diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index e244ae4827..553591f3c9 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -1198,11 +1198,17 @@ balanced expression is found." (defun ruby-brace-to-do-end () (when (looking-at "{") - (let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))) + (let ((orig (point)) (end (progn (ruby-forward-sexp) (point))) + oneline (end (make-marker))) + (setq oneline (and (eolp) (<= (point-at-bol) orig))) (when (eq (char-before) ?\}) (delete-char -1) - (if (eq (char-syntax (preceding-char)) ?w) - (insert " ")) + (cond + (oneline + (insert "\n") + (set-marker end (point))) + ((eq (char-syntax (preceding-char)) ?w) + (insert " "))) (insert "end") (if (eq (char-syntax (following-char)) ?w) (insert " ")) @@ -1214,20 +1220,54 @@ balanced expression is found." (when (looking-at "\\sw\\||") (insert " ") (backward-char)) + (when oneline + (setq orig (point)) + (when (cond + ((looking-at "\\s *|") + (goto-char (match-end 0)) + (and (search-forward "|" (point-at-eol) 'move) + (not (eolp)))) + (t)) + (while (progn + (insert "\n") + (ruby-forward-sexp) + (looking-at "\\s *;\\s *")) + (delete-char (- (match-end 0) (match-beginning 0)))) + (goto-char orig) + (beginning-of-line 2) + (indent-region (point) end)) + (goto-char orig)) t)))) (defun ruby-do-end-to-brace () (when (and (or (bolp) (not (memq (char-syntax (preceding-char)) '(?w ?_)))) (looking-at "\\