2007-04-26 08:54:01 +04:00
|
|
|
;;; -*- emacs-lisp -*-
|
|
|
|
;;; C/C++ mode style for Ruby.
|
|
|
|
|
|
|
|
(defun ruby-style-case-indent (x)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (cdr x))
|
2007-05-17 12:02:02 +04:00
|
|
|
(if (looking-at "\\<case\\|default\\>") '*)))
|
|
|
|
|
|
|
|
(defun ruby-style-label-indent (x)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (cdr x))
|
|
|
|
(backward-up-list)
|
|
|
|
(backward-sexp 2)
|
|
|
|
(if (looking-at "\\<switch\\>") '/)))
|
2007-04-26 08:54:01 +04:00
|
|
|
|
|
|
|
(require 'cc-styles)
|
|
|
|
(c-add-style
|
|
|
|
"ruby"
|
|
|
|
'("bsd"
|
|
|
|
(c-basic-offset . 4)
|
2007-05-17 12:02:02 +04:00
|
|
|
(tab-width . 8)
|
|
|
|
(indent-tabs-mode . t)
|
2007-04-26 08:54:01 +04:00
|
|
|
(c-offsets-alist
|
|
|
|
(case-label . *)
|
2007-05-17 12:02:02 +04:00
|
|
|
(label . (ruby-style-label-indent *))
|
2007-04-26 08:54:01 +04:00
|
|
|
(statement-case-intro . *)
|
|
|
|
(statement-case-open . *)
|
|
|
|
(statement-block-intro . (ruby-style-case-indent +))
|
|
|
|
(access-label /)
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun ruby-style-c-mode ()
|
|
|
|
(interactive)
|
|
|
|
(if (or (string-match "/ruby\\>" (buffer-file-name))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let ((head (progn (forward-line 100) (point)))
|
|
|
|
(case-fold-search nil))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(re-search-forward "Copyright (C) .* Yukihiro Matsumoto" head t))))
|
|
|
|
(setq c-file-style "ruby")))
|
|
|
|
|
|
|
|
(provide 'ruby-style)
|