diff --git a/ChangeLog b/ChangeLog index c7752d3f3c..134ee661ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Dec 6 16:47:45 2013 Nobuyoshi Nakada + + * 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. + Fri Dec 6 16:16:30 2013 Koichi Sasada * gc.c (gc_start_internal): do not use rb_gc_start() and rb_gc(). 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 "\\