From 633cf770f0ec5aa3d44e46c6997c3939fec73eef Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 30 Mar 2011 13:55:50 +0000 Subject: * misc/ruby-mode.el (ruby-toggle-block): toggle do/end and {}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- misc/ruby-mode.el | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'misc') diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 3799541901..48d91836f2 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -172,6 +172,7 @@ (define-key ruby-mode-map "\t" 'ruby-indent-command) (define-key ruby-mode-map "\C-c\C-e" 'ruby-insert-end) (define-key ruby-mode-map "\C-j" 'ruby-reindent-then-newline-and-indent) + (define-key ruby-mode-map "\C-c{" 'ruby-toggle-block) (define-key ruby-mode-map "\C-c\C-u" 'uncomment-region)) (defvar ruby-mode-syntax-table nil @@ -1161,6 +1162,44 @@ balanced expression is found." (if mlist (concat mlist mname) mname) mlist))))) +(defun ruby-brace-to-do-end () + (when (looking-at "{") + (let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))) + (when (eq (char-before) ?\}) + (delete-char -1) + (if (eq (char-syntax (char-before)) ?w) + (insert " ")) + (insert "end") + (if (eq (char-syntax (char-after)) ?w) + (insert " ")) + (goto-char orig) + (delete-char 1) + (if (eq (char-syntax (char-before)) ?w) + (insert " ")) + (insert "do") + (if (eq (char-syntax (char-after)) ?w) + (insert " ")) + t)))) + +(defun ruby-do-end-to-brace () + (when (and (or (bolp) + (not (memq (char-syntax (char-before)) '(?w ?_)))) + (looking-at "\\