On 7/15/06, Luis A. Florit <[EMAIL PROTECTED]> wrote:
* El 13/07/06 a las 20:54, Luis A. Florit chamullaba:> * El 12/07/06 a las 23:34, Stefan Karlsson chamullaba: > > > > Is there an easy way to autoselect language for the builtin > > > spell checker in vim 7.0? Vimspell plugin has this functionality: > > > the plugin looks for a specified number of lines and try to guess > > > which language should it use. > > > > > > > Set spelllang -- yes there is three "l" in that option :-) -- to a > > comma-separated list of the languages you're interested in. Vim will figure > > out which of them to use. > > > > For example, this is how I do it in my .vimrc (I want US English and Swedish): > > > > set spelllang=en_us,sv > > Oh... perfect!!!! > How I didn't find this in the manual? > I (think I) searched thoroughly... > Anyway, thanks a lot!!!! No, wait, there is a problem. If I put set spelllang=en,pt,es then vim ADDS this dictionaries!! So, something like "You want to go yo quiero ir eu quero ir" will be accepted without any error!! So, vim just add all the dictionaries and then this is not a good solution.
Indeed, it is documented so in :help spelllang: all listed dictionaries are used, not one of them. It is possible to write a plugin on top of existing spell functionality, a plugin that would automaticlly recognize a lanugage of the document out of the list of languages. The algorithm is below. Here is the idea, the algorithm, based on the spell-counting script that I posted to the list some time ago. That script counted number of spell-bad and spell-good words in the buffer. Now the algorithm: for every language in the list, spell the buffer with this lanugage. Count spell-bad and spell-good for this language. Out of all language in the list, select language with most spell-good and least spell-bad numbers. [If there is no clear winner, present a dialog so that user can choose manually.] I'd much rather leave the plugin writing to someone who himself uses multilanguage spelling often. To save his time, the CountMisspell() function is below. Yakov ---------------- countspell.vim ---------------------- " http://marc.theaimsgroup.com/?l=vim-dev&m=114634256230440&w=2 " count number of misspelled words, and ratio of bad/good words. map <F5> :call CountMisspell()<cr> func! CountMisspell() let save_cursor = getpos('.') norm gg set spell let total = 0 let bad = 0 let good = 0 let warn = 0 let flags='Wc' while search('\i\+', flags) let flags = 'W' let total += 1 let word = expand('<cword>') let list = spellbadword(word) if list[1] == '' let good += 1 elseif list[1] == 'bad' let bad += 1 else " rare, local, caps let warn += 1 endif endwh echo "Total words: " . good echo "Bad words: " . bad echo "Semi-bad words: " . warn if bad != 0 let ratio = (10000 * bad) / total let ratio = printf("%03d", ratio) let ratio = substitute(ratio, '\d\d$', '.&', '') else let ratio='0.00' endif echo "Bad words ratio: " . ratio . '%' call setpos('.', save_cursor ) endfu -------------------------------------------------------
