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
This commit is contained in:
nobu 2013-12-06 07:47:47 +00:00
Родитель 761e9c518f
Коммит 378d20f80d
2 изменённых файлов: 51 добавлений и 4 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Dec 6 16:47:45 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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 <ko1@atdot.net>
* gc.c (gc_start_internal): do not use rb_gc_start() and rb_gc().

Просмотреть файл

@ -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 "\\<do\\(\\s \\|$\\)"))
(let ((orig (point)) (end (progn (ruby-forward-sexp) (point))))
(let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))
first last)
(backward-char 3)
(when (looking-at ruby-block-end-re)
(delete-char 3)
(insert "}")
(setq last (and (eolp)
(progn (backward-char 1)
(skip-syntax-backward " ")
(bolp))
(1- (point-at-eol -1))))
(goto-char orig)
(delete-char 2)
(insert "{")
(setq orig (point))
(when (and last (<= last (point))
(not (search-forward "#" (setq first (point-at-eol)) t)))
(goto-char (- end 4))
(end-of-line 0)
(if (looking-at "\n\\s *")
(delete-char (- (match-end 0) (match-beginning 0))) t)
(goto-char first)
(if (looking-at "\n\\s *")
(delete-char (- (match-end 0) (match-beginning 0))) t))
(goto-char orig)
(if (looking-at "\\s +|")
(delete-char (- (match-end 0) (match-beginning 0) 1)))
t))))