Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ruby-additional.el: set encoding

* misc/ruby-additional.el (ruby-mode-set-encoding): now encoding needs
  to be set always explicitly actually.  [Feature #6679]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 1c5104ac9c0803c476b54d751b0ec4579a1828af 1 parent bd9b31e
@nobu nobu authored
Showing with 46 additions and 0 deletions.
  1. +5 −0 ChangeLog
  2. +41 −0 misc/ruby-additional.el
View
5 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.
View
41 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")))))))
+
))
Please sign in to comment.
Something went wrong with that request. Please try again.