Created
September 8, 2008 02:08
-
-
Save smtlaissezfaire/9359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun ruby-mode-set-encoding () | |
(save-excursion | |
(widen) | |
(goto-char (point-min)) | |
(when (re-search-forward "[^\0-\177]" nil t) | |
(goto-char (point-min)) | |
(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 | |
(or (and ruby-use-encoding-map | |
(cdr (assq coding-system ruby-encoding-map))) | |
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")) | |
))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment