diff options
Diffstat (limited to 'misc/ruby-style.el')
| -rw-r--r-- | misc/ruby-style.el | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/misc/ruby-style.el b/misc/ruby-style.el index ceb960c0a0..03d0830d3a 100644 --- a/misc/ruby-style.el +++ b/misc/ruby-style.el @@ -4,23 +4,26 @@ ;;; ;;; C/C++ mode style for Ruby. ;;; -;;; $Author: nobu $ +;;; $Author$ ;;; created at: Thu Apr 26 13:54:01 JST 2007 ;;; -;;; sets ruby style if it seems like a source of ruby. +;;; Put this file under a directory contained in ``load-path'', and +;;; then load it. +;;; 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: ;;; ;;; (require 'ruby-style) ;;; (add-hook 'c-mode-hook 'ruby-style-c-mode) ;;; (add-hook 'c++-mode-hook 'ruby-style-c-mode) ;;; -;;; uses ruby style always. -;;; (setq-default c-file-style "ruby") +;;; Customize the c-default-style variable to set the default style +;;; for each CC major mode. -(defconst ruby-style-revision "$Revision: 15588 $" +(defconst ruby-style-revision "$Revision$" "Ruby style revision string.") (defconst ruby-style-version - (progn + (and (string-match "[0-9.]+" ruby-style-revision) (substring ruby-style-revision (match-beginning 0) (match-end 0))) "Ruby style version number.") @@ -52,7 +55,10 @@ '("bsd" (c-basic-offset . 4) (tab-width . 8) - (indent-tabs-mode . t) + (indent-tabs-mode . nil) + (show-trailing-whitespace . t) + (c-backslash-column . 1) + (c-backslash-max-column . 1) (c-offsets-alist (case-label . *) (label . (ruby-style-label-indent *)) @@ -62,6 +68,18 @@ (access-label /) ))) +(c-add-style + "prism" + '("bsd" + (c-basic-offset . 4) + (tab-width . 8) + (indent-tabs-mode . nil) + (show-trailing-whitespace . t) + (c-offsets-alist + (case-label . +) + ))) + +;;;###autoload (defun ruby-style-c-mode () (interactive) (if (or (let ((name (buffer-file-name))) (and name (string-match "/ruby\\>" name))) @@ -70,7 +88,20 @@ (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"))) + (re-search-forward "Copyright (C) .* Yukihiro Matsumoto" head t))) + (condition-case () + (with-temp-buffer + (when (= 0 (call-process "git" nil t nil "remote" "get-url" "origin")) + (goto-char (point-min)) + (looking-at ".*/ruby\\(\\.git\\)?$"))) + (error)) + (condition-case () + (with-temp-buffer + (when (= 0 (call-process "svn" nil t nil "info" "--xml")) + (goto-char (point-min)) + (search-forward-regexp "<root>.*/ruby</root>" nil))) + (error)) + nil) + (c-set-style "ruby"))) (provide 'ruby-style) |
