annotate runtime/autoload/spellfile.vim @ 884:9f184758f277 v7.0.010

updated for version 7.0-010
author vimboss
date Sat, 13 May 2006 12:25:55 +0000
parents bc95c6c4bac1
children f03c3fae0a99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
1 " Vim script to download a missing spell file
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
2 " Maintainer: Bram Moolenaar <Bram@vim.org>
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
3 " Last Change: 2006 May 10
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
4
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
5 if !exists('g:spellfile_URL')
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
6 let g:spellfile_URL = 'ftp://ftp.vim.org/pub/vim/runtime/spell'
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
7 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
8 let s:spellfile_URL = '' " Start with nothing so that s:donedict is reset.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
9
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
10 " This function is used for the spellfile plugin.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
11 function! spellfile#LoadFile(lang)
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
12 " If the netrw plugin isn't loaded we silently skip everything.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
13 if !exists(":Nread")
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
14 if &verbose
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
15 echomsg 'spellfile#LoadFile(): Nread command is not available.'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
16 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
17 return
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
18 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
19
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
20 " If the URL changes we try all files again.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
21 if s:spellfile_URL != g:spellfile_URL
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
22 let s:donedict = {}
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
23 let s:spellfile_URL = g:spellfile_URL
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
24 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
25
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
26 " I will say this only once!
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
27 if has_key(s:donedict, a:lang . &enc)
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
28 if &verbose
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
29 echomsg 'spellfile#LoadFile(): Tried this language/encoding before.'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
30 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
31 return
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
32 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
33 let s:donedict[a:lang . &enc] = 1
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
34
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
35 " Find spell directories we can write in.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
36 let dirlist = []
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
37 let dirchoices = '&Cancel'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
38 for dir in split(globpath(&rtp, 'spell'), "\n")
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
39 if filewritable(dir) == 2
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
40 call add(dirlist, dir)
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
41 let dirchoices .= "\n&" . len(dirlist)
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
42 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
43 endfor
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
44 if len(dirlist) == 0
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
45 if &verbose
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
46 echomsg 'spellfile#LoadFile(): There is no writable spell directory.'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
47 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
48 return
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
49 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
50
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
51 let msg = 'Cannot find spell file for "' . a:lang . '" in ' . &enc
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
52 let msg .= "\nDo you want me to try downloading it?"
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
53 if confirm(msg, "&Yes\n&No", 2) == 1
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
54 let enc = &encoding
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
55 if enc == 'iso-8859-15'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
56 let enc = 'latin1'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
57 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
58 let fname = a:lang . '.' . enc . '.spl'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
59
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
60 " Split the window, read the file into a new buffer.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
61 new
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
62 setlocal bin
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
63 echo 'Downloading ' . fname . '...'
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
64 call spellfile#Nread(fname)
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
65 if getline(2) !~ 'VIMspell'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
66 " Didn't work, perhaps there is an ASCII one.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
67 g/^/d
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
68 let fname = a:lang . '.ascii.spl'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
69 echo 'Could not find it, trying ' . fname . '...'
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
70 call spellfile#Nread(fname)
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
71 if getline(2) !~ 'VIMspell'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
72 echo 'Sorry, downloading failed'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
73 bwipe!
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
74 return
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
75 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
76 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
77
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
78 " Delete the empty first line and mark the file unmodified.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
79 1d
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
80 set nomod
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
81
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
82 let msg = "In which directory do you want to write the file:"
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
83 for i in range(len(dirlist))
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
84 let msg .= "\n" . (i + 1) . '. ' . dirlist[i]
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
85 endfor
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
86 let dirchoice = confirm(msg, dirchoices) - 2
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
87 if dirchoice >= 0
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
88 exe "write " . escape(dirlist[dirchoice], ' ') . '/' . fname
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
89
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
90 " Also download the .sug file, if the user wants to.
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
91 let msg = "Do you want me to try getting the .sug file?\n"
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
92 let msg .= "This will improve making suggestions for spelling mistakes,\n"
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
93 let msg .= "but it uses quite a bit of memory."
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
94 if confirm(msg, "&No\n&Yes") == 2
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
95 g/^/d
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
96 let fname = substitute(fname, '\.spl$', '.sug', '')
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
97 echo 'Downloading ' . fname . '...'
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
98 call spellfile#Nread(fname)
651
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
99 if getline(2) !~ 'VIMsug'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
100 echo 'Sorry, downloading failed'
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
101 else
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
102 1d
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
103 exe "write " . escape(dirlist[dirchoice], ' ') . '/' . fname
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
104 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
105 set nomod
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
106 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
107 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
108
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
109 bwipe
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
110 endif
bc95c6c4bac1 updated for version 7.0191
vimboss
parents:
diff changeset
111 endfunc
884
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
112
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
113 " Read "fname" from the ftp server.
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
114 function! spellfile#Nread(fname)
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
115 let machine = substitute(g:spellfile_URL, 'ftp://\([^/]*\).*', '\1', '')
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
116 let dir = substitute(g:spellfile_URL, 'ftp://[^/]*/\(.*\)', '\1', '')
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
117 exe 'Nread "' . machine . ' anonymous vim7user ' . dir . '/' . a:fname . '"'
9f184758f277 updated for version 7.0-010
vimboss
parents: 651
diff changeset
118 endfunc