r550 - in trunk/vim7/debian: . spell
Stefano Zacchiroli
zack at costa.debian.org
Tue Mar 28 18:12:04 UTC 2006
Author: zack
Date: 2006-03-28 18:12:03 +0000 (Tue, 28 Mar 2006)
New Revision: 550
Added:
trunk/vim7/debian/spell/
trunk/vim7/debian/spell/mkvimspell.sh
Log:
added script to generate Vim spell files from MySpell dictionaries using Vim's
:mkspell command
Added: trunk/vim7/debian/spell/mkvimspell.sh
===================================================================
--- trunk/vim7/debian/spell/mkvimspell.sh 2006-03-28 17:33:21 UTC (rev 549)
+++ trunk/vim7/debian/spell/mkvimspell.sh 2006-03-28 18:12:03 UTC (rev 550)
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+# Generate Vim spell files from (Debian's) MySpell dictionaries
+# Copyright (C) 2006: Stefano Zacchiroli <zack at debian.org>
+# License: GNU GPL, Version 2 or above
+# $Id$
+
+DICTDIR="/usr/share/myspell/dicts"
+
+# XXX according to the Vim manual, this function will break if more than 8
+# dictionaries are passed
+# args: DEST ENC DICTS
+# e.g. /tmp/en utf-8 en-US en-GB
+function myspell2vim () {
+ local dest="$1"
+ local enc="$2"
+ local dicts=""
+ shift 2
+ for d in $* ; do dicts="$dicts $DICTDIR/$d"; done
+ local tmp=`mktemp -t mkvimspell.XXXXXX`
+ trap "rm -f $tmp" EXIT
+ # Vim normalizes encoding names, the only way to know the actual name is used
+ # is to store it somewhere from inside vim. We use the same temp file used
+ # for the script
+ cat <<EOS > $tmp
+:set encoding=$enc
+:mkspell! $dest $dicts
+:call system("echo '$dest." . &encoding . ".spl' > $tmp")
+:q
+EOS
+ cat $tmp # debugging
+ echo "Processing dictionaries $dicts ..." 1>&2
+ vim -u NONE -s $tmp 1>&2
+ echo "Generation completed, the result is available in:" 1>&2
+ cat $tmp
+}
+
+function die_usage () {
+ cat <<EOH
+
+Usage: $0 ENC FILE DICT ...
+ $0 ENC DIR all
+
+E.g.: $0 utf-8 ~/.vim/spell/en en_US en_GB
+ $0 utf-8 tmp/vimspell/ all
+
+Generate Vim spell files from (Debian's) MySpell dictionaries.
+
+When invoked in the first form a Vim spell file named FILE.ENC.spl will
+be generated from a list of MySpell dictionaries. Dictionaries are
+specified using the XX_XX (language, region) convention. The
+corresponding .aff and .dic files are expected to exists in
+$DICTDIR/.
+
+Note that since Vim normalizes encoding names there is no guarantee that
+the ENC used in the name of the resulting file is the same you specified
+(e.g. if you specify 'utf8' the generated file will contain 'utf-8').
+For this reason the name of the generated file is returned on stdout
+(everything else, like progress information, is printed on stderr).
+
+When invoked in the second form Vim spell files will be generated for all
+available MySpell dictionaries (merging regions together) and stored under DIR.
+The list of generated Vim spell files is returned on stdout.
+
+EOH
+ exit 1
+}
+
+if [ -z "$1" ]; then die_usage; else enc="$1"; fi
+if [ -z "$2" ]; then die_usage; else dest="$2"; fi
+if [ -z "$3" ]; then die_usage; fi
+
+case "$3" in
+ all) # second form
+ dest=$(echo "$dest" | sed 's|/$||')
+ dictionaries=$(for f in $(find $DICTDIR -name '*_*.aff'); do echo $f | sed 's|^.*/\(.*\)\.aff$|\1|'; done)
+ languages=$(for d in $dictionaries; do echo $d | sed 's/_.*//'; done | sort | uniq)
+ for lang in $languages; do
+ dicts=$(for d in $dictionaries; do echo $d; done | grep "^$lang" | xargs)
+ myspell2vim "$dest/$lang" "$enc" $dicts
+ done
+ ;;
+ *) # first form
+ shift 2
+ myspell2vim "$dest" "$enc" $*
+ ;;
+esac
+
Property changes on: trunk/vim7/debian/spell/mkvimspell.sh
___________________________________________________________________
Name: svn:executable
+ *
More information about the pkg-vim-maintainers
mailing list