mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
764c486b84
commit
633cf770f0
2 changed files with 42 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
||||||
Wed Mar 30 22:54:24 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Mar 30 22:55:47 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-toggle-block): toggle do/end and {}.
|
||||||
|
|
||||||
* misc/ruby-mode.el (ruby-move-to-block): move to opening of
|
* misc/ruby-mode.el (ruby-move-to-block): move to opening of
|
||||||
block.
|
block.
|
||||||
|
|
|
@ -172,6 +172,7 @@
|
||||||
(define-key ruby-mode-map "\t" 'ruby-indent-command)
|
(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-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-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))
|
(define-key ruby-mode-map "\C-c\C-u" 'uncomment-region))
|
||||||
|
|
||||||
(defvar ruby-mode-syntax-table nil
|
(defvar ruby-mode-syntax-table nil
|
||||||
|
@ -1161,6 +1162,44 @@ balanced expression is found."
|
||||||
(if mlist (concat mlist mname) mname)
|
(if mlist (concat mlist mname) mname)
|
||||||
mlist)))))
|
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 "\\<do\\(\\s \\|$\\)"))
|
||||||
|
(let ((orig (point)) (end (progn (ruby-forward-sexp) (point))))
|
||||||
|
(backward-char 3)
|
||||||
|
(when (looking-at ruby-block-end-re)
|
||||||
|
(delete-char 3)
|
||||||
|
(insert "}")
|
||||||
|
(goto-char orig)
|
||||||
|
(delete-char 2)
|
||||||
|
(insert "{")
|
||||||
|
t))))
|
||||||
|
|
||||||
|
(defun ruby-toggle-block ()
|
||||||
|
(interactive)
|
||||||
|
(or (ruby-brace-to-do-end)
|
||||||
|
(ruby-do-end-to-brace)))
|
||||||
|
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(if (featurep 'font-lock)
|
(if (featurep 'font-lock)
|
||||||
(defmacro eval-when-font-lock-available (&rest args) (cons 'progn args))
|
(defmacro eval-when-font-lock-available (&rest args) (cons 'progn args))
|
||||||
|
|
Loading…
Reference in a new issue