summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--misc/ruby-additional.el41
2 files changed, 46 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index aa3bcf783c..18df509fed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Nov 7 11:48:14 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * misc/ruby-additional.el (ruby-mode-set-encoding): now encoding needs
+ to be set always explicitly actually. [Feature #6679]
+
Wed Nov 7 09:15:58 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* object.c (rb_mod_const_get): avoid inadvertent symbol creation.
diff --git a/misc/ruby-additional.el b/misc/ruby-additional.el
index aabf0a6888..32811728e3 100644
--- a/misc/ruby-additional.el
+++ b/misc/ruby-additional.el
@@ -56,4 +56,45 @@
(interactive)
(or (ruby-brace-to-do-end)
(ruby-do-end-to-brace)))
+
+ (defun ruby-mode-set-encoding ()
+ "Insert a magic comment header with the proper encoding always.
+Now encoding needs to be set always explicitly actually."
+ (save-excursion
+ (let ((coding-system))
+ (widen)
+ (goto-char (point-min))
+ (if (re-search-forward "[^\0-\177]" nil t)
+ (progn
+ (goto-char (point-min))
+ (set coding-system
+ (or coding-system-for-write
+ buffer-file-coding-system))
+ (if coding-system
+ (setq coding-system
+ (or (coding-system-get coding-system 'mime-charset)
+ (coding-system-change-eol-conversion coding-system nil))))
+ (setq coding-system
+ (if coding-system
+ (symbol-name
+ (or (and ruby-use-encoding-map
+ (cdr (assq coding-system ruby-encoding-map)))
+ coding-system))
+ "ascii-8bit")))
+ (setq coding-system "us-ascii"))
+ (if (looking-at "^#!") (beginning-of-line 2))
+ (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
+ (unless (string= (match-string 2) coding-system)
+ (goto-char (match-beginning 2))
+ (delete-region (point) (match-end 2))
+ (and (looking-at "-\*-")
+ (let ((n (skip-chars-backward " ")))
+ (cond ((= n 0) (insert " ") (backward-char))
+ ((= n -1) (insert " "))
+ ((forward-char)))))
+ (insert coding-system)))
+ ((looking-at "\\s *#.*coding\\s *[:=]"))
+ (t (when ruby-insert-encoding-magic-comment
+ (insert "# -*- coding: " coding-system " -*-\n")))))))
+
))