Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | #!/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 Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 14 | # updated 2008 Jul 17 by Bram |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 15 | # |
| 16 | # Safe method for the temp file by Javier Fernández-Sanguino_Peña |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | |
| 18 | INFILE=$1 |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 19 | tmp="${TMPDIR-/tmp}" |
| 20 | OUTFILE=`mktemp -t vimspellXXXXXX || tempfile -p vimspell || echo none` |
| 21 | # If the standard commands failed then create the file |
| 22 | # since we cannot create a directory (we cannot remove it on exit) |
| 23 | # create a file in the safest way possible. |
| 24 | if test "$OUTFILE" = none; then |
| 25 | OUTFILE=$tmp/vimspell$$ |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 26 | [ -e $OUTFILE ] && { echo "Cannot use temporary file $OUTFILE, it already exists!"; exit 1 ; } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 27 | (umask 077; touch $OUTFILE) |
| 28 | fi |
| 29 | # Note the copy of vimspell cannot be deleted on exit since it is |
| 30 | # used by vim, otherwise it should do this: |
| 31 | # trap "rm -f $OUTFILE" 0 1 2 3 9 11 13 15 |
| 32 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | |
| 34 | # |
| 35 | # local spellings |
| 36 | # |
| 37 | LOCAL_DICT=${LOCAL_DICT-$HOME/local/lib/local_dict} |
| 38 | |
| 39 | if [ -f $LOCAL_DICT ] |
| 40 | then |
| 41 | SPELL_ARGS="+$LOCAL_DICT" |
| 42 | fi |
| 43 | |
| 44 | spell $SPELL_ARGS $INFILE | sort -u | |
| 45 | awk ' |
| 46 | { |
| 47 | printf "syntax match SpellErrors \"\\<%s\\>\"\n", $0 ; |
| 48 | } |
| 49 | |
| 50 | END { |
| 51 | printf "highlight link SpellErrors ErrorMsg\n\n" ; |
| 52 | } |
| 53 | ' > $OUTFILE |
| 54 | echo "!rm $OUTFILE" >> $OUTFILE |
| 55 | echo $OUTFILE |