Created
October 15, 2010 20:52
-
-
Save fmoralesc/628930 to your computer and use it in GitHub Desktop.
a vim script for detecting the language of a text file and setting the spelling language automatically.
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
if (exists("g:loaded_detect_lang") && g:detect_lang) || &cp | |
finish | |
endif | |
let g:detect_lang = 1 | |
command! DetectLanguage exec('py detect_language()') | |
command! SetSpellLang exec('py detect_and_set_spelllang()') | |
python <<EOF | |
from glanguage import Translator | |
import vim | |
def detect_buffer_language(): | |
t = Translator() | |
return t.detect(unicode(vim.current.buffer[0:3])) | |
def detect_language(): | |
print detect_buffer_language().lang | |
def detect_and_set_spelllang(): | |
l = detect_buffer_language() | |
print "Document language is " + l.lang | |
vim.command("set spell") | |
vim.command("set spelllang=" + l.lang_code) | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment