Skip to content

Instantly share code, notes, and snippets.

@DeaR
Created June 29, 2012 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/3018087 to your computer and use it in GitHub Desktop.
Save DeaR/3018087 to your computer and use it in GitHub Desktop.
encodingマジックコメントで-dos等を何とかしてみた #xyzzy
(defun find-file-buffer-encoding (arg)
"エンコーディングの自動判定"
(let ((encoding (gethash (substitute-string arg "-\\(dos\\|mac\\|unix\\)$" "" :case-fold t)
*mime-charset-name-hash-table*))
(eol (cond ((string-matchp "-dos$" arg)
*eol-crlf*)
((string-matchp "-mac$" arg)
*eol-cr*)
((string-matchp "-unix$" arg)
*eol-lf*))))
(when encoding
(revert-buffer (if (and *find-file-auto-encoding-use-utf8n*
(eq encoding *encoding-utf8*))
*encoding-utf8n*
encoding)))
(when eol
(set-buffer-eol-code eol))))
(pushnew '("coding" . find-file-buffer-encoding) *auto-mode-parameter-alist* :test #'equal)
(pushnew '("encoding" . find-file-buffer-encoding) *auto-mode-parameter-alist* :test #'equal)
(defun find-file-buffer-eol (arg)
"改行コードの自動判定"
(let ((eol (cond ((or (string-equal "dos" arg)
(string-equal "crlf" arg))
*eol-crlf*)
((or (string-equal "mac" arg)
(string-equal "cr" arg))
*eol-cr*)
((or (string-equal "unix" arg)
(string-equal "lf" arg))
*eol-lf*))))
(when eol
(set-buffer-eol-code eol))))
(pushnew '("eol" . find-file-buffer-eol) *auto-mode-parameter-alist* :test #'equal)
@DeaR
Copy link
Author

DeaR commented Jun 29, 2012

ついでにeolマジックコメントも追加してあったりもする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment