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
|
|
|
|
;;;
|
2016-02-29 00:54:24 -05:00
|
|
|
;;; Put this file under a directory contained in ``load-path'', and
|
|
|
|
;;; then load it.
|
2009-06-23 22:41:57 -04:00
|
|
|
;;; To switch to the "ruby" style automatically if it looks like a
|
|
|
|
;;; source file of ruby, add ruby-style-c-mode to c-mode-hook:
|
2008-10-09 10:53:26 -04:00
|
|
|
;;;
|
|
|
|
;;; (require 'ruby-style)
|
|
|
|
;;; (add-hook 'c-mode-hook 'ruby-style-c-mode)
|
|
|
|
;;; (add-hook 'c++-mode-hook 'ruby-style-c-mode)
|
|
|
|
;;;
|
2009-06-23 22:41:57 -04:00
|
|
|
;;; Customize the c-default-style variable to set the default style
|
|
|
|
;;; for each CC major mode.
|
2007-09-20 15:58:41 -04:00
|
|
|
|
|
|
|
(defconst ruby-style-revision "$Revision$"
|
|
|
|
"Ruby style revision string.")
|
|
|
|
|
|
|
|
(defconst ruby-style-version
|
2010-05-25 03:37:41 -04:00
|
|
|
(and
|
2007-09-20 15:58:41 -04:00
|
|
|
(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)
|
2008-09-06 18:30:34 -04:00
|
|
|
(> (point) (cdr x)))
|
2007-10-26 02:00:52 -04:00
|
|
|
(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-09-06 18:30:34 -04:00
|
|
|
(>= (point) (cdr x)))
|
2007-10-26 02:00:52 -04:00
|
|
|
(goto-char (cdr x))
|
|
|
|
(condition-case ()
|
2008-09-06 18:30:34 -04:00
|
|
|
(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)
|
2011-01-07 07:57:34 -05:00
|
|
|
(setq show-trailing-whitespace 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 /)
|
|
|
|
)))
|
|
|
|
|
2013-09-03 05:29:22 -04:00
|
|
|
;;;###autoload
|
2007-04-26 00:54:01 -04:00
|
|
|
(defun ruby-style-c-mode ()
|
|
|
|
(interactive)
|
2008-10-09 10:53:26 -04:00
|
|
|
(if (or (let ((name (buffer-file-name))) (and name (string-match "/ruby\\>" name)))
|
2007-04-26 00:54:01 -04:00
|
|
|
(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))))
|
2009-06-23 22:41:57 -04:00
|
|
|
(c-set-style "ruby")))
|
2007-04-26 00:54:01 -04:00
|
|
|
|
|
|
|
(provide 'ruby-style)
|