Re: VI and Ispell

2000-09-30 Thread Dmitry Sedov

Jack Morgan <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> (need tcl 
support in vim)
.vimrc
---
tclfile ~/.vimrc.ispell.tcl

command! -nargs=1 IspellDict tcl Ispell_Dict 
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  =IspellLine()
endfun

fun! Ispell_off()
if mapcheck("", "i") == " =IspellLine()"
iunmap 
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 <[EMAIL PROTECTED]> 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] "<>~`'., [EMAIL 
PROTECTED]&*()_|-=+\\\/\""]
foreach w $words {
Ispell_Word $w
}
}
-

JM> TIA
JM> --
JM> Jack Morgan   Debain GNU/Linux
JM> Email:[EMAIL PROTECTED]
JM> Web-site:   www.mandinka.org

-- 
Sed-off

e-mail: [EMAIL PROTECTED]



Re: VI and Ispell

2000-09-28 Thread Preben Randhol
Glyn Millington <[EMAIL PROTECTED]> wrote on 28/09/2000 (08:13) :
> On Thu, Sep 28, 2000 at 11:00:34AM +0900, thus spake Jack Morgan:
> > How cn i use Ispell in VI? I'm using VI as my editor for Mutt and want to 
> > be able to
> > check my spelling. I'm a VI newbie so any help is greatly appreciated ;-)
> 
> Are you using Vim?  If so, I've attached a good script by Claudio
> Fleiner which allows you to use Ispell from within Vim.  Source it
> from your .vimrc and then just hit  when you want to check
> the file you are working on.  This may work in plain Vi too,
> wouldn't know because I haven't tried.  Instruction are there in
> vimspell.vim.

I recommend that you use vim rather than vi. vimspell.vim can be found
at this address:

  http://www.fleiner.com/vim/spell.html

-- 
Preben Randhol - Ph. D student - http://www.pvv.org/~randhol/
"Violence is the last refuge of the incompetent", Isaac Asimov



Re: VI and Ispell

2000-09-28 Thread Glyn Millington
On Thu, Sep 28, 2000 at 11:00:34AM +0900, thus spake Jack Morgan:
> How cn i use Ispell in VI? I'm using VI as my editor for Mutt and want to be 
> able to
> check my spelling. I'm a VI newbie so any help is greatly appreciated ;-)

Are you using Vim?  If so, I've attached a good script by Claudio
Fleiner which allows you to use Ispell from within Vim.  Source it
from your .vimrc and then just hit  when you want to check
the file you are working on.  This may work in plain Vi too,
wouldn't know because I haven't tried.  Instruction are there in
vimspell.vim.

Good luck!




-- 
   **
   * "The soul is greater than the hum of its parts. "  *
   * Douglas Hoftstatder*
   **
" Use ispell to highlight spellig errors
" Author: Claudio Fleiner <[EMAIL PROTECTED]>
" F6 - write file, spell file & highlight spelling mistakes
" F6  - switch between german and american spelling
" F6- return to normal syntax coloring
" I - insert word under cursor into directory
" U - insert word under cursor as lowercase into directory
" A - accept word for this session only
" / - check for alternatives

:function! ProposeAlternatives()
:  let @_=CheckSpellLanguage()
:  let alter=system("echo ".expand("")." | ispell -a -d ".b:language." | 
sed -e '/^$/d' -e '/[EMAIL PROTECTED]/d' -e 's/.*: //' -e 's/,//g' | awk '{ 
for(i=1;i<=NF;i++) if(i<10) printf \"map %d :let r=SpellReplace(\\\"%s\\\") 
| echo \\\"%d: %s\\\" | \",i,$i,i,$i; }'")
:  if alter !=? ""
:echo "Checking ".expand("").": Type 0 for no change, r to replace 
or"
:exe alter
:map 0 :let r=SpellRemoveMappings()
:map r 0gewcw
:  else
:echo "no alternatives"
:  endif
:endfunction

:function! SpellRemoveMappings()
:  let counter=0
:  while counter<10
:exe "map ".counter." x"
:exe "unmap ".counter
:let counter=counter+1
:  endwhile
:  unmap r
:endfunction


:function! SpellReplace(s)
:  exe "normal gewcw".a:s."\"
:  let r=SpellRemoveMappings()
:endfunction

:function! ExitSpell()
:  unmap i
:  unmap u
:  unmap a
:  unmap n
:  unmap p
:  unmap 
:  unmap 
:  unmap 
:  unmap 
:  unmap 
:  unmap 
:  unmap 
:  syn match SpellErrors "x"
:  syn match SpellCorrected "x"
:  syn clear SpellErrors
:  syn clear SpellCorrected
:endfunction

:function! SpellCheck() 
:  syn case match
:  let @_=CheckSpellLanguage()
:  w
:  syn match SpellErrors "x"
:  syn clear SpellErrors
:  let b:spellerrors="\\<\\(nonexisitingwordinthisdociumnt"
:  let b:mappings=system("ispell -l -d ".b:language." < ".expand("%")." | sort 
-u | sed 's/\\(.*\\)/syntax match SpellErrors \"<\\1>\" 
".b:spell_options."| let 
b:spellerrors=b:spellerrors.\"|\\1\"/'")
:  exe b:mappings
:  let b:spellerrors=b:spellerrors."\\)\\>"
:  map i :let @_=system("echo \\\*".expand("")." \| ispell -a -d 
".b:language):syn case match:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map u :let @_=system("echo \\\&".expand("")." \| ispell -a -d 
".b:language):syn case ignore:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map a :syn case match:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map  :let @_=ExitSpell()
:  exe "map n /".b:spellerrors."\"
:  exe "map p ?".b:spellerrors."\"
:  map  :let @_=system("echo \\\*".expand("")." \| ispell -a -d 
".b:language):syn case match:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map  :let @_=system("echo \\\&".expand("")." \| ispell -a -d 
".b:language):syn case ignore:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map  :syn case match:exe "syn match SpellCorrected 
\"\\<".expand("")."\\>\" transparent contains=NONE 
".b:spell_options
:  map  :let @_=ExitSpell()
:  exe "map  /".b:spellerrors."\"
:  exe "map  ?".b:spellerrors."\"
:  syn cluster Spell contains=SpellErrors,SpellCorrected
:  hi link SpellErrors Error
:  exe "normal \"
:endfunction

:function! CheckSpellLanguage() 
:  if !exists("b:spell_options") 
:let b:spell_options=""
:  endif
:  if !exists("b:language")
:let b:language="american"
:  elseif b:language !=? "german"
:let b:language="american"
:  endif
:endfunction

:function! SpellLanguage()
:  if !exists("b:language")
:let b:language="german"
:  elseif b:language ==? "american"
:let b:language="german"
:  else
:let b:language="american"
:  endif
:  echo "Language: ".b:language
:endfunction

map  :let @_=SpellCheck()
map / :let @_=ProposeAlternatives()
map  :let @_=ProposeAlternatives()
map  :let @_=SpellLanguage()