ruby-style.el
1 ;;; -*- emacs-lisp -*- 2 ;;; C/C++ mode style for Ruby. 3 4 (defun ruby-style-case-indent (x) 5 (save-excursion 6 (goto-char (cdr x)) 7 (if (looking-at "\\<case\\|default\\>") '*))) 8 9 (defun ruby-style-label-indent (x) 10 (save-excursion 11 (goto-char (cdr x)) 12 (backward-up-list) 13 (backward-sexp 2) 14 (if (looking-at "\\<switch\\>") '/))) 15 16 (require 'cc-styles) 17 (c-add-style 18 "ruby" 19 '("bsd" 20 (c-basic-offset . 4) 21 (tab-width . 8) 22 (indent-tabs-mode . t) 23 (c-offsets-alist 24 (case-label . *) 25 (label . (ruby-style-label-indent *)) 26 (statement-case-intro . *) 27 (statement-case-open . *) 28 (statement-block-intro . (ruby-style-case-indent +)) 29 (access-label /) 30 ))) 31 32 (defun ruby-style-c-mode () 33 (interactive) 34 (if (or (string-match "/ruby\\>" (buffer-file-name)) 35 (save-excursion 36 (goto-char (point-min)) 37 (let ((head (progn (forward-line 100) (point))) 38 (case-fold-search nil)) 39 (goto-char (point-min)) 40 (re-search-forward "Copyright (C) .* Yukihiro Matsumoto" head t)))) 41 (setq c-file-style "ruby"))) 42 43 (provide 'ruby-style)