;;; ruby-additional.el --- ruby-mode extensions yet to be merged into Emacs ;; Authors: Yukihiro Matsumoto, Nobuyoshi Nakada, Akinori MUSHA ;; URL: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/misc/ ;; Created: 3 Sep 2012 ;; Package-Requires: ((ruby-mode "1.2")) ;; Keywords: ruby, languages ;;; Commentary: ;; ;; This package contains ruby-mode extensions yet to be merged into ;; the Emacs distribution. ;;; Code: (eval-when-compile (require 'ruby-mode)) (eval-after-load 'ruby-mode '(progn (define-key ruby-mode-map "\C-c\C-e" 'ruby-insert-end) (define-key ruby-mode-map "\C-c{" 'ruby-toggle-block) (defun ruby-insert-end () (interactive) (if (eq (char-syntax (preceding-char)) ?w) (insert " ")) (insert "end") (save-excursion (if (eq (char-syntax (following-char)) ?w) (insert " ")) (ruby-indent-line t) (end-of-line))) (defun ruby-brace-to-do-end () (when (looking-at "{") (let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))) (when (eq (preceding-char) ?\}) (delete-char -1) (if (eq (char-syntax (preceding-char)) ?w) (insert " ")) (insert "end") (if (eq (char-syntax (following-char)) ?w) (insert " ")) (goto-char orig) (delete-char 1) (if (eq (char-syntax (preceding-char)) ?w) (insert " ")) (insert "do") (when (looking-at "\\sw\\||") (insert " ") (backward-char)) t)))) (defun ruby-do-end-to-brace () (when (and (or (bolp) (not (memq (char-syntax (preceding-char)) '(?w ?_)))) (looking-at "\\