* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / misc / ruby-style.el
blob1915419056604e62ec36c15008954968a41204b5
1 ;;; -*- emacs-lisp -*-
2 ;;;
3 ;;; ruby-style.el -
4 ;;;
5 ;;; C/C++ mode style for Ruby.
6 ;;;
7 ;;; $Author$
8 ;;; created at: Thu Apr 26 13:54:01 JST 2007
9 ;;;
11 (defconst ruby-style-revision "$Revision$"
12 "Ruby style revision string.")
14 (defconst ruby-style-version
15 (progn
16 (string-match "[0-9.]+" ruby-style-revision)
17 (substring ruby-style-revision (match-beginning 0) (match-end 0)))
18 "Ruby style version number.")
20 (defun ruby-style-case-indent (x)
21 (save-excursion
22 (back-to-indentation)
23 (unless (progn (backward-up-list) (back-to-indentation)
24 (> (point) (cdr x)))
25 (goto-char (cdr x))
26 (if (looking-at "\\<case\\|default\\>") '*))))
28 (defun ruby-style-label-indent (x)
29 (save-excursion
30 (back-to-indentation)
31 (unless (progn (backward-up-list) (back-to-indentation)
32 (>= (point) (cdr x)))
33 (goto-char (cdr x))
34 (condition-case ()
35 (progn
36 (backward-up-list)
37 (backward-sexp 2)
38 (if (looking-at "\\<switch\\>") '/))
39 (error)))))
41 (require 'cc-styles)
42 (c-add-style
43 "ruby"
44 '("bsd"
45 (c-basic-offset . 4)
46 (tab-width . 8)
47 (indent-tabs-mode . t)
48 (c-offsets-alist
49 (case-label . *)
50 (label . (ruby-style-label-indent *))
51 (statement-case-intro . *)
52 (statement-case-open . *)
53 (statement-block-intro . (ruby-style-case-indent +))
54 (access-label /)
55 )))
57 (defun ruby-style-c-mode ()
58 (interactive)
59 (if (or (string-match "/ruby\\>" (buffer-file-name))
60 (save-excursion
61 (goto-char (point-min))
62 (let ((head (progn (forward-line 100) (point)))
63 (case-fold-search nil))
64 (goto-char (point-min))
65 (re-search-forward "Copyright (C) .* Yukihiro Matsumoto" head t))))
66 (setq c-file-style "ruby")))
68 (provide 'ruby-style)