[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: VI and Ispell



Jack Morgan <j-morgan@gol.com> wrote:
JM> How cn i use Ispell in VI? I'm using VI as my editor for Mutt and want to be
JM> able to
JM> check my spelling. I'm a VI newbie so any help is greatly appreciated ;-)

Try to use this script author: Andrew Rodionoff <arnost@mail.ru> (need tcl support in vim)
.vimrc
-------------------------------
tclfile ~/.vimrc.ispell.tcl

command! -nargs=1 IspellDict tcl Ispell_Dict <args>
fun! IspellLine()
    tcl Ispell_Line [::vim::expr line(".")]
    return ""
endfun

hi IspellCombo gui=underline guifg=yellow guibg=none cterm=underline ctermfg=yellow ctermbg=none term=underline
hi IspellError gui=underline guifg=red guibg=none cterm=underline ctermfg=red ctermbg=none term=underline

fun! Ispell_on()
    inoremap <Space> <Space><C-R>=IspellLine()<CR>
endfun

fun! Ispell_off()
    if mapcheck("<Space>", "i") == " <C-R>=IspellLine()<CR>"
        iunmap <space>
    endif
endfun

augroup ispell
"   au!
"   au filetype mail call Ispell_on()
"   au filetype tex call Ispell_on()
"   au WinEnter,BufEnter * call Ispell_off()
    au WinEnter,BufEnter *.tex call Ispell_on()
    au WinEnter,BufEnter *.txt call Ispell_on()
augroup END
--------------------------------
.vimrc.ispell.tcl
--------------------------------
# This is on-the-fly spellchecking support module for Vim
# Author: Andrew Rodionoff <arnost@mail.ru> Copyleft (x) 2000
# Disclaimer: ->Insert your favourite disclaimer here<-
#
# TODO:
# Error-handling

set Ispell(dictionary) russian
set Ispell(binary) /usr/bin/ispell

proc Ispell_Dict {dictname} {
    global Ispell

    if {[info exists Ispell(pipe)]} {
        close $Ispell(pipe)
        set Ispell(dictionary) $dictname
        Ispell_start_server
    } else {
        set Ispell(dictionary) $dictname
    }
}

proc Ispell_start_server {} {
    global Ispell

    puts "Starting Ispell process..."
    if {[info exists Ispell(dictionary)]} {
        set dict_string "-d $Ispell(dictionary)"
    } else {
        set dict_string ""
    }
    set Ispell(pipe) [open "|$Ispell(binary) -a $dict_string" r+]
    set Ispell(version) [gets $Ispell(pipe)]
    if {$Ispell(version) == ""} {
        puts vimerr "Could not start ispell server. Check your dictionary name."
    }
    fconfigure $Ispell(pipe) -blocking off -buffering line
    fileevent $Ispell(pipe) readable Ispell_process_filter
}

proc Ispell_process_filter {} {
    global Ispell

    set Ispell(responce) [read $Ispell(pipe)]
    if {[string length $Ispell(responce)] <= 1} {
        return
    }
    switch -- [string index $Ispell(responce) 0] {
        \- {
            $::vim::current(buffer) command "syntax match IspellCombo \"\\<$Ispell(word)\\>\""
        }
        \& -
        \# {
            $::vim::current(buffer) command "syntax match IspellError \"\\<$Ispell(word)\\>\""
        }
        \+ -
        default { }
    }
}

proc Ispell_Word {word} {
    global Ispell

    if {![info exist Ispell(pipe)]} {
        Ispell_start_server
    }
    if {$word == ""} {
        return
    }
    set Ispell(word) $word
    puts $Ispell(pipe) $word
    vwait Ispell(responce)
}
proc Ispell_Line {line} {
    set words [split [$::vim::current(buffer) get $line] "<>~`'., \t!@#$%^&*()_|-=+\\\/\""]
    foreach w $words {
        Ispell_Word $w
    }
}
-----------------------------

JM> TIA
JM> --
JM> Jack Morgan   Debain GNU/Linux
JM> Email:    j-morgan@gol.com
JM> Web-site:   www.mandinka.org

-- 
Sed-off

e-mail: sedov@kak-sam.to



Reply to: