blob: b405b7ad5938601c55954f278474c984e6dc0c42 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001#!/bin/sh
2#
3# Spell a file & generate the syntax statements necessary to
4# highlight in vim. Based on a program from Krishna Gadepalli
5# <krishna@stdavids.picker.com>.
6#
7# I use the following mappings (in .vimrc):
8#
9# noremap <F8> :so `vimspell.sh %`<CR><CR>
10# noremap <F7> :syntax clear SpellErrors<CR>
11#
12# Neil Schemenauer <nascheme@ucalgary.ca>
13# March 1999
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000014#
15# Safe method for the temp file by Javier Fernández-Sanguino_Peña
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
17INFILE=$1
Bram Moolenaar3a7c85b2005-02-05 21:39:53 +000018tmp="${TMPDIR-/tmp}"
19OUTFILE=`mktemp -t vimspellXXXXXX || tempfile -p vimspell || echo none`
20# If the standard commands failed then create the file
21# since we cannot create a directory (we cannot remove it on exit)
22# create a file in the safest way possible.
23if test "$OUTFILE" = none; then
24 OUTFILE=$tmp/vimspell$$
25 [ -e $OUTFILE ] && { echo "Cannot use temporary file $OUTFILE, it already exists!; exit 1 ; }
26 (umask 077; touch $OUTFILE)
27fi
28# Note the copy of vimspell cannot be deleted on exit since it is
29# used by vim, otherwise it should do this:
30# trap "rm -f $OUTFILE" 0 1 2 3 9 11 13 15
31
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33#
34# local spellings
35#
36LOCAL_DICT=${LOCAL_DICT-$HOME/local/lib/local_dict}
37
38if [ -f $LOCAL_DICT ]
39then
40 SPELL_ARGS="+$LOCAL_DICT"
41fi
42
43spell $SPELL_ARGS $INFILE | sort -u |
44awk '
45 {
46 printf "syntax match SpellErrors \"\\<%s\\>\"\n", $0 ;
47 }
48
49END {
50 printf "highlight link SpellErrors ErrorMsg\n\n" ;
51 }
52' > $OUTFILE
53echo "!rm $OUTFILE" >> $OUTFILE
54echo $OUTFILE