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 | 40d82c9aec42883cb194917b41e2bf56f299ac0e (patch) | |
tree | adc76f9ded60e642bbd950f89a74d3193c01ac3e /misc/ruby-mode.el | |
parent | cf3dfd0b40873cbaff8b581f9aac587c66929af6 (diff) | |
download | ruby-40d82c9aec42883cb194917b41e2bf56f299ac0e.tar.gz ruby-40d82c9aec42883cb194917b41e2bf56f299ac0e.tar.xz ruby-40d82c9aec42883cb194917b41e2bf56f299ac0e.zip |
* misc/ruby-mode.el (ruby-mode-set-encoding): updates magic comment.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc/ruby-mode.el')
-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 20a81f26e..59efd66f6 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 () |