Created
August 3, 2015 06:10
-
-
Save shimakyohsuke/30ad5ae5be9db79f7165 to your computer and use it in GitHub Desktop.
atom editor init.coffee
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
fs = require 'fs' | |
atom.workspace.onDidOpen -> | |
editor = atom.workspace.getActiveTextEditor() | |
try | |
filePath = editor.getPath() | |
console.log filePath | |
catch error | |
console.log "error" | |
return | |
return unless fs.existsSync(filePath) | |
jschardet = require 'jschardet' | |
iconv = require 'iconv-lite' | |
fs.readFile filePath, (error, buffer) => | |
return if error? | |
{encoding} = jschardet.detect(buffer) ? {} | |
encoding = 'utf8' if encoding is 'ascii' | |
return unless iconv.encodingExists(encoding) | |
encoding = encoding.toLowerCase().replace(/[^0-9a-z]|:\d{4}$/g, '') | |
editor.setEncoding(encoding) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment