" Script Name: zpspell.vim " Version: 0.0.2 " Last Change: February 27, 2006 " Author: A. Murat Eren " " Description: a little script to highlight misspelled words " - only for Turkish users working on Pardus Linux.. " - marker code forked from Yuheng Xie's marker suite.. " " Todo: - suggest corrections.. " - handle exceptions (we are handling nothing now).. " " nmap :ZspellLine " nmap :ZspellAll " command! -nargs=0 ZspellLine call s:ZspellLine() command! -nargs=0 ZspellAll call s:ZspellAll() let s:save_cpo = &cpo set cpo&vim function! s:ZspellLine() let g:Data = getline(".") let g:Data = s:Clean() call s:Zspell() endfunction function! s:ZspellAll() call s:GetTotalLineNumber() let l:i = 1 let g:Data = "" while 1 let l:line = getline(l:i) let g:Data = g:Data . " " . l:line let l:i = l:i + 1 if l:i > g:totalLine break endif endwhile let g:Data = s:Clean() call s:Zspell() endfunction function! s:Zspell() if !executable("zpspell") echohl WarningMsg | echo "zpspell bulunamadı, imla denetimi mümkün değil." | echohl None return endif let wordList = system("python -c \"import os; import sys; exclude = ['<', '>', '[', ']']; words = sys.argv[1].split(); words = [x for x in words if not [t for t in exclude if x.find(t) > -1]]; sys.stdout.write(' '.join(set([x for x in words if not os.popen('zpspell %s' % x).readlines()[0].find('doğru') > -1])) + ' ')\" '" . g:Data . "'") let l:length = strlen(wordList) if l:length == 0 return endif let l:offset = 0 let l:next = 0 while l:next > -1 let l:next = match(wordList, ' ', l:offset) let w = strpart(wordList, l:offset, l:next - l:offset) call s:DoMark('\<' . w . '\>') let l:offset = l:next + 1 endwhile echohl Title if wordList != ' ' echomsg "Hatalı kelimeler: " . wordList else echomsg "Hatalı kelime yok." endif echohl None endfunction function! s:Clean() let l:line = substitute(g:Data, "'", " ", "g") let l:line = substitute(l:line, "(", " ", "g") let l:line = substitute(l:line, ")", " ", "g") let l:line = substitute(l:line, '"', " ", "g") let l:line = substitute(l:line, '`', " ", "g") let l:line = substitute(l:line, '´', " ", "g") let l:line = substitute(l:line, '-', " ", "g") let l:line = substitute(l:line, '\,', " ", "g") let l:line = substitute(l:line, '\.', " ", "g") let l:line = substitute(l:line, '\:', " ", "g") return l:line endfunction let maxC = 24 let i = 1 while i <= maxC execute "hi MarkWord" . i . " ctermbg=Magenta ctermfg=Black guibg=#FFB3FF guifg=Black" let i = i + 1 endwhile function! s:GetTotalLineNumber() let g:totalLine = 0 let curline = 0 let i = 1 while 1 call cursor(i, 1) let curline = line(".") if g:totalLine == curline break endif let g:totalLine = curline let i = i + 1 endwhile endfunction function! s:InitMarkVariables() if !exists("g:mwHistAdd") let g:mwHistAdd = "/@" endif if !exists("g:mwCycleMax") let i = 1 while hlexists("MarkWord" . i) let i = i + 1 endwhile let g:mwCycleMax = i - 1 endif if !exists("b:mwCycle") let b:mwCycle = 1 endif let i = 1 while i <= g:mwCycleMax if !exists("b:mwWord" . i) let b:mwWord{i} = "" endif let i = i + 1 endwhile endfunction function! s:DoMark(...) call s:InitMarkVariables() let regexp = "" if a:0 > 0 let regexp = a:1 endif if regexp == "" let i = 1 while i <= g:mwCycleMax if b:mwWord{i} != "" let b:mwWord{i} = "" exe "syntax clear MarkWord" . i endif let i = i + 1 endwhile return 0 endif let i = 1 while i <= g:mwCycleMax if regexp == b:mwWord{i} let b:mwWord{i} = "" exe "syntax clear MarkWord" . i return 0 endif let i = i + 1 endwhile if stridx(g:mwHistAdd, "/") >= 0 call histadd("/", regexp) endif if stridx(g:mwHistAdd, "@") >= 0 call histadd("@", regexp) endif let quote = "/?~!@#$%^&*+-=,.:" let i = 0 while i < strlen(quote) if stridx(regexp, quote[i]) < 0 let quoted_regexp = quote[i] . regexp . quote[i] break endif let i = i + 1 endwhile if i >= strlen(quote) return -1 endif let i = 1 while i <= g:mwCycleMax if b:mwWord{i} == "" let b:mwWord{i} = regexp if i < g:mwCycleMax let b:mwCycle = i + 1 else let b:mwCycle = 1 endif exe "syntax clear MarkWord" . i exe "syntax match MarkWord" . i . " " . quoted_regexp . " containedin=ALL" return i endif let i = i + 1 endwhile let i = 1 while i <= g:mwCycleMax if b:mwCycle == i let b:mwWord{i} = regexp if i < g:mwCycleMax let b:mwCycle = i + 1 else let b:mwCycle = 1 endif exe "syntax clear MarkWord" . i exe "syntax match MarkWord" . i . " " . quoted_regexp . " containedin=ALL" return i endif let i = i + 1 endwhile endfunction let &cpo = s:save_cpo