diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-28 15:10:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-28 15:10:02 +0000 |
commit | f7ed47355e63926e212fe0a72e5d0b31873290d8 (patch) | |
tree | adc76f9ded60e642bbd950f89a74d3193c01ac3e /misc | |
parent | 4102378f791ca5549e97d0b2ce1db6854e5a4b65 (diff) | |
download | ruby-f7ed47355e63926e212fe0a72e5d0b31873290d8.tar.gz |
* misc/ruby-mode.el (ruby-mode-set-encoding): updates magic comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc')
-rw-r--r-- | misc/ruby-mode.el | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 20a81f26e1..59efd66f66 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -234,21 +234,34 @@ Also ignores spaces after parenthesis when 'space." (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t)) +(eval-when-compile + (unless (fboundp 'coding-system-to-mime-charset) + (defun coding-system-to-mime-charset (coding-system) + (coding-system-change-eol-conversion coding-system nil)))) + (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"))))) + (let ((coding-system + (coding-system-to-mime-charset + (or coding-system-for-write + buffer-file-coding-system)))) + (setq coding-system + (if coding-system + (symbol-name coding-system) + "ascii-8bit")) + (if (looking-at "^#![^\n]*ruby") (beginning-of-line 2)) + (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]+\\)") + (unless (string= (match-string 2) coding-system) + (goto-char (match-beginning 2)) + (delete-region (point) (match-end 2)) + (insert coding-system))) + ((looking-at "\\s *#.*coding\\s *[:=]")) + (t (insert "# -*- coding: " coding-system " -*-\n")) + ))))) ;;;###autoload (defun ruby-mode () |