1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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

encoding magic comment.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-01-27 12:49:01 +00:00
parent 2ae9745aed
commit c9ca560ce8
2 changed files with 35 additions and 10 deletions

View file

@ -1,3 +1,8 @@
Sun Jan 27 21:48:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* misc/ruby-mode.el (ruby-mode-set-encoding): automatically insert
encoding magic comment.
Sun Jan 27 19:51:15 2008 Tanaka Akira <akr@fsij.org> Sun Jan 27 19:51:15 2008 Tanaka Akira <akr@fsij.org>
* string.c (rb_str_inspect): avoid exception by * string.c (rb_str_inspect): avoid exception by

View file

@ -5,40 +5,42 @@
;;; created at: Fri Feb 4 14:49:13 JST 1994 ;;; 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 (defconst ruby-mode-version
(progn (progn
(string-match "[0-9.]+" ruby-mode-revision) (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 (defconst ruby-block-beg-re
"class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do" "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 (defconst ruby-non-block-do-re
"\\(while\\|until\\|for\\|rescue\\)\\>[^_]" "\\(while\\|until\\|for\\|rescue\\)\\>[^_]"
) "Regexp to match")
(defconst ruby-indent-beg-re (defconst ruby-indent-beg-re
"\\(\\s *\\(class\\|module\\|def\\)\\)\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin" "\\(\\s *\\(class\\|module\\|def\\)\\)\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin"
) "Regexp to match where the indentation gets deeper.")
(defconst ruby-modifier-beg-re (defconst ruby-modifier-beg-re
"if\\|unless\\|while\\|until" "if\\|unless\\|while\\|until"
) "Regexp to match modifiers same as the beginning of blocks.")
(defconst ruby-modifier-re (defconst ruby-modifier-re
(concat ruby-modifier-beg-re "\\|rescue") (concat ruby-modifier-beg-re "\\|rescue")
) "Regexp to match modifiers.")
(defconst ruby-block-mid-re (defconst ruby-block-mid-re
"then\\|else\\|elsif\\|when\\|rescue\\|ensure" "then\\|else\\|elsif\\|when\\|rescue\\|ensure"
) "Regexp to match where the indentation gets shallower in middle of block statements.")
(defconst ruby-block-op-re (defconst ruby-block-op-re
"and\\|or\\|not" "and\\|or\\|not"
) "Regexp to match ")
(defconst ruby-block-hanging-re (defconst ruby-block-hanging-re
(concat ruby-modifier-beg-re "\\|" ruby-block-op-re) (concat ruby-modifier-beg-re "\\|" ruby-block-op-re)
@ -67,7 +69,7 @@
(defconst ruby-negative (defconst ruby-negative
(concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|" (concat "^[ \t]*\\(\\(" ruby-block-mid-re "\\)\\>\\|"
ruby-block-end-re "\\|}\\|\\]\\)") ruby-block-end-re "\\|}\\|\\]\\)")
) "Regexp to match where the indentation gets shallower.")
(defconst ruby-operator-chars "-,.+*/%&|^~=<>:") (defconst ruby-operator-chars "-,.+*/%&|^~=<>:")
(defconst ruby-operator-re (concat "[" ruby-operator-chars "]")) (defconst ruby-operator-re (concat "[" ruby-operator-chars "]"))
@ -232,6 +234,22 @@ Also ignores spaces after parenthesis when 'space."
(make-local-variable 'paragraph-ignore-fill-prefix) (make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)) (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 ;;;###autoload
(defun ruby-mode () (defun ruby-mode ()
"Major mode for editing ruby scripts. "Major mode for editing ruby scripts.
@ -254,6 +272,8 @@ The variable ruby-indent-level controls the amount of indentation.
(make-local-variable 'add-log-current-defun-function) (make-local-variable 'add-log-current-defun-function)
(setq add-log-current-defun-function 'ruby-add-log-current-method) (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)) (run-hooks 'ruby-mode-hook))
(defun ruby-current-indentation () (defun ruby-current-indentation ()