2007-04-26 00:54:01 -04:00
|
|
|
;;; -*- emacs-lisp -*-
|
2007-09-20 15:58:41 -04:00
|
|
|
;;;
|
|
|
|
;;; ruby-style.el -
|
|
|
|
;;;
|
2007-04-26 00:54:01 -04:00
|
|
|
;;; C/C++ mode style for Ruby.
|
2007-09-20 15:58:41 -04:00
|
|
|
;;;
|
|
|
|
;;; $Author$
|
|
|
|
;;; created at: Thu Apr 26 13:54:01 JST 2007
|
|
|
|
;;;
|
|
|
|
|
|
|
|
(defconst ruby-style-revision "$Revision$"
|
|
|
|
"Ruby style revision string.")
|
|
|
|
|
|
|
|
(defconst ruby-style-version
|
|
|
|
(progn
|
|
|
|
(string-match "[0-9.]+" ruby-style-revision)
|
|
|
|
(substring ruby-style-revision (match-beginning 0) (match-end 0)))
|
|
|
|
"Ruby style version number.")
|
2007-04-26 00:54:01 -04:00
|
|
|
|
|
|
|
(defun ruby-style-case-indent (x)
|
|
|
|
(save-excursion
|
2008-04-22 09:15:56 -04:00
|
|
|
(back-to-indentation)
|
2007-10-26 02:00:52 -04:00
|
|
|
(unless (progn (backward-up-list) (back-to-indentation)
|
|
|
|
(> (point) (cdr x)))
|
|
|
|
(goto-char (cdr x))
|
|
|
|
(if (looking-at "\\<case\\|default\\>") '*))))
|
2007-05-17 04:02:02 -04:00
|
|
|
|
|
|
|
(defun ruby-style-label-indent (x)
|
|
|
|
(save-excursion
|
2008-04-22 09:15:56 -04:00
|
|
|
(back-to-indentation)
|
2007-10-26 02:00:52 -04:00
|
|
|
(unless (progn (backward-up-list) (back-to-indentation)
|
2008-02-23 15:09:46 -05:00
|
|
|
(>= (point) (cdr x)))
|
2007-10-26 02:00:52 -04:00
|
|
|
(goto-char (cdr x))
|
|
|
|
(condition-case ()
|
|
|
|
(progn
|
|
|
|
(backward-up-list)
|
|
|
|
(backward-sexp 2)
|
|
|
|
(if (looking-at "\\<switch\\>") '/))
|
|
|
|
(error)))))
|
2007-04-26 00:54:01 -04:00
|
|
|
|
|
|
|
(require 'cc-styles)
|
|
|
|
(c-add-style
|
|
|
|
"ruby"
|
|
|
|
'("bsd"
|
|
|
|
(c-basic-offset . 4)
|
2007-05-17 04:02:02 -04:00
|
|
|
(tab-width . 8)
|
|
|
|
(indent-tabs-mode . t)
|
2007-04-26 00:54:01 -04:00
|
|
|
(c-offsets-alist
|
|
|
|
(case-label . *)
|
2007-05-17 04:02:02 -04:00
|
|
|
(label . (ruby-style-label-indent *))
|
2007-04-26 00: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)
|