summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-09 14:53:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-09 14:53:26 +0000
commit98520c482ebff98769c58608cdf448aa897ee4c2 (patch)
tree5b35bc382553737b5df1730bae2e794d4e4708b6 /misc
parent97ed063e6edb73e79658449c63e74d8dbb1339b2 (diff)
* misc/ruby-style.el (ruby-style-c-mode): buffer may not have file
name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@19731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc')
-rw-r--r--misc/ruby-style.el26
1 files changed, 18 insertions, 8 deletions
diff --git a/misc/ruby-style.el b/misc/ruby-style.el
index ef05ea004a..ceb960c0a0 100644
--- a/misc/ruby-style.el
+++ b/misc/ruby-style.el
@@ -7,6 +7,14 @@
;;; $Author: nobu $
;;; created at: Thu Apr 26 13:54:01 JST 2007
;;;
+;;; sets ruby style if it seems like a source of ruby.
+;;;
+;;; (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")
(defconst ruby-style-revision "$Revision: 15588 $"
"Ruby style revision string.")
@@ -19,22 +27,24 @@
(defun ruby-style-case-indent (x)
(save-excursion
+ (back-to-indentation)
(unless (progn (backward-up-list) (back-to-indentation)
- (> (point) (cdr x)))
+ (> (point) (cdr x)))
(goto-char (cdr x))
(if (looking-at "\\<case\\|default\\>") '*))))
(defun ruby-style-label-indent (x)
(save-excursion
+ (back-to-indentation)
(unless (progn (backward-up-list) (back-to-indentation)
- (>= (point) (cdr x)))
+ (>= (point) (cdr x)))
(goto-char (cdr x))
(condition-case ()
- (progn
- (backward-up-list)
- (backward-sexp 2)
- (if (looking-at "\\<switch\\>") '/))
- (error)))))
+ (progn
+ (backward-up-list)
+ (backward-sexp 2)
+ (if (looking-at "\\<switch\\>") '/))
+ (error)))))
(require 'cc-styles)
(c-add-style
@@ -54,7 +64,7 @@
(defun ruby-style-c-mode ()
(interactive)
- (if (or (string-match "/ruby\\>" (buffer-file-name))
+ (if (or (let ((name (buffer-file-name))) (and name (string-match "/ruby\\>" name)))
(save-excursion
(goto-char (point-min))
(let ((head (progn (forward-line 100) (point)))