Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created April 30, 2010 01:54
Show Gist options
  • Save bowbow99/384602 to your computer and use it in GitHub Desktop.
Save bowbow99/384602 to your computer and use it in GitHub Desktop.
;;; 文字コード指定を -*- coding: hoge -*- でもできるように
;;; .xyzzy にでも; 組み込み関数上書き注意報
(defun ed::find-file-auto-encoding (filename)
(unwind-protect
(let ((encoding
(progn
(ignore-errors (insert-file-contents filename t nil 4096))
(goto-char (point-min))
(dolist (x *auto-encoding-alist* nil)
(when (string-matchp (car x) filename)
(return (funcall (cdr x))))))))
(when (stringp encoding)
(setq encoding (gethash encoding *mime-charset-name-hash-table*)))
(if (char-encoding-p encoding)
encoding
(let ((params (ed::find-file-scan-params)))
(gethash (cdr (or (assoc "encoding" params :test #'string-equal)
(assoc "coding" params :test #'string-equal)))
*mime-charset-name-hash-table*))))
(erase-buffer (selected-buffer))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment