[前][次][番号順一覧][スレッド一覧]

ruby-changes:3785

From: ko1@a...
Date: Sun, 27 Jan 2008 21:49:14 +0900 (JST)
Subject: [ruby-changes:3785] nobu - Ruby:r15274 (trunk): * misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert

nobu	2008-01-27 21:49:01 +0900 (Sun, 27 Jan 2008)

  New Revision: 15274

  Modified files:
    trunk/ChangeLog
    trunk/misc/ruby-mode.el

  Log:
    * misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert
      encoding magic comment.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/misc/ruby-mode.el?r1=15274&r2=15273&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15274&r2=15273&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15273)
+++ ChangeLog	(revision 15274)
@@ -1,3 +1,8 @@
+Sun Jan 27 21:48:59 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert
+	  encoding magic comment.
+
 Sun Jan 27 19:51:15 2008  Tanaka Akira  <akr@f...>
 
 	* string.c (rb_str_inspect): avoid exception by
Index: misc/ruby-mode.el
===================================================================
--- misc/ruby-mode.el	(revision 15273)
+++ misc/ruby-mode.el	(revision 15274)
@@ -5,40 +5,42 @@
 ;;;  created at: Fri Feb  4 14:49:13 JST 1994
 ;;;
 
-(defconst ruby-mode-revision "$Revision$")
+(defconst ruby-mode-revision "$Revision$"
+  "Ruby mode revision string.")
 
 (defconst ruby-mode-version
   (progn
    (string-match "[0-9.]+" ruby-mode-revision)
-   (substring ruby-mode-revision (match-beginning 0) (match-end 0))))
+   (substring ruby-mode-revision (match-beginning 0) (match-end 0)))
+  "Ruby mode version number.")
 
 (defconst ruby-block-beg-re
   "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do"
-  )
+  "Regexp to match the beginning of blocks in ruby-mode.")
 
 (defconst ruby-non-block-do-re
   "\\(while\\|until\\|for\\|rescue\\)\\>[^_]"
-  )
+  "Regexp to match")
 
 (defconst ruby-indent-beg-re
   "\\(\\s *\\(class\\|module\\|def\\)\\)\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin"
-    )
+  "Regexp to match where the indentation gets deeper.")
 
 (defconst ruby-modifier-beg-re
   "if\\|unless\\|while\\|until"
-  )
+  "Regexp to match modifiers same as the beginning of blocks.")
 
 (defconst ruby-modifier-re
   (concat ruby-modifier-beg-re "\\|rescue")
-  )
+  "Regexp to match modifiers.")
 
 (defconst ruby-block-mid-re
   "then\\|else\\|elsif\\|when\\|rescue\\|ensure"
-  )
+  "Regexp to match where the indentation gets shallower in middle of block statements.")
 
 (defconst ruby-block-op-re
   "and\\|or\\|not"
-  )
+  "Regexp to match ")
 
 (defconst ruby-block-hanging-re
   (concat ruby-modifier-beg-re "\\|" ruby-block-op-re)
@@ -67,7 +69,7 @@
 (defconst ruby-negative
   (concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|"
 	    ruby-block-end-re "\\|}\\|\\]\\)")
-  )
+  "Regexp to match where the indentation gets shallower.")
 
 (defconst ruby-operator-chars "-,.+*/%&|^~=<>:")
 (defconst ruby-operator-re (concat "[" ruby-operator-chars "]"))
@@ -232,6 +234,22 @@
   (make-local-variable 'paragraph-ignore-fill-prefix)
   (setq paragraph-ignore-fill-prefix t))
 
+(defun ruby-mode-set-encoding ()
+  (save-excursion
+    (widen)
+    (goto-char (point-min))
+    (when (re-search-forward "[^\0-\177]" nil t)
+      (goto-char (point-min))
+      (if (looking-at "^#![^\n]*ruby") (beginning-of-line 2))
+      (unless (looking-at "\s*#\.*coding\s*[:=]")
+	(insert "# -*- coding: "
+		(let ((coding-system (coding-system-to-mime-charset (or coding-system-for-write
+									buffer-file-coding-system))))
+		  (if coding-system
+		      (symbol-name coding-system)
+		    "ascii-8bit"))
+		" -*-\n")))))
+
 ;;;###autoload
 (defun ruby-mode ()
   "Major mode for editing ruby scripts.
@@ -254,6 +272,8 @@
   (make-local-variable 'add-log-current-defun-function)
   (setq add-log-current-defun-function 'ruby-add-log-current-method)
 
+  (add-hook 'before-save-hook 'ruby-mode-set-encoding)
+
   (run-hooks 'ruby-mode-hook))
 
 (defun ruby-current-indentation ()

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]