blob: d3058c55dd82ea36c570fa14c49e6cad3c2a08ff [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" netrw.vim: (global plugin) Handles file transfer across a network
2" Last Change: Jun 04, 2004
3" Maintainer: Charles E. Campbell, Jr. PhD <drchipNOSPAM at campbellfamily.biz>
4" Version: 44
5" License: Vim License (see vim's :help license)
6"
7" But be doers of the word, and not only hearers, deluding your own selves
8" (James 1:22 RSV)
9" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
10
11" Exit quickly when already loaded or when 'compatible' is set.
12if exists("loaded_netrw") || &cp
13 finish
14endif
15let loaded_netrw = "v44"
16let s:save_cpo = &cpo
17set cpo&vim
18
19" ---------------------------------------------------------------------
20" Default values for global netrw variables {{{1
21if !exists("g:netrw_ftpmode")
22 let g:netrw_ftpmode= "binary"
23endif
24if !exists("g:netrw_win95ftp")
25 let g:netrw_win95ftp= 1
26endif
27if !exists("g:netrw_cygwin")
28 if has("win32")
29 let g:netrw_cygwin= 1
30 else
31 let g:netrw_cygwin= 0
32 endif
33endif
34
35" ---------------------------------------------------------------------
36" Default values for global protocol variables {{{1
37if !exists("g:netrw_rcp_cmd")
38 let g:netrw_rcp_cmd = "rcp"
39endif
40if !exists("g:netrw_ftp_cmd")
41 let g:netrw_ftp_cmd = "ftp"
42endif
43if !exists("g:netrw_scp_cmd")
44 let g:netrw_scp_cmd = "scp -q"
45endif
46if !exists("g:netrw_sftp_cmd")
47 let g:netrw_sftp_cmd = "sftp"
48endif
49if !exists("g:netrw_http_cmd")
50 if executable("wget")
51 let g:netrw_http_cmd = "wget -q -O"
52 elseif executable("fetch")
53 let g:netrw_http_cmd = "fetch -o"
54 else
55 let g:netrw_http_cmd = ""
56 endif
57endif
58if !exists("g:netrw_dav_cmd")
59 let g:netrw_dav_cmd = "cadaver"
60endif
61if !exists("g:netrw_rsync_cmd")
62 let g:netrw_rsync_cmd = "rsync"
63endif
64if !exists("g:netrw_fetch_cmd")
65 if executable("fetch")
66 let g:netrw_fetch_cmd = "fetch -o"
67 else
68 let g:netrw_fetch_cmd = ""
69 endif
70endif
71
72if has("win32")
73 \ && exists("g:netrw_use_nt_rcp")
74 \ && g:netrw_use_nt_rcp
75 \ && executable( $SystemRoot .'/system32/rcp.exe')
76 let s:netrw_has_nt_rcp = 1
77 let s:netrw_rcpmode = '-b'
78 else
79 let s:netrw_has_nt_rcp = 0
80 let s:netrw_rcpmode = ''
81endif
82
83" ---------------------------------------------------------------------
84" Transparency Support: {{{1
85" Auto-detection for ftp://*, rcp://*, scp://*, sftp://*, http://*, dav://*,
86" and rsync://*
87" Should make file transfers across networks transparent. Currently I haven't
88" supported appends. Hey, gotta leave something for a future <netrw.vim>!
89if version >= 600
90 augroup Network
91 au!
92 if has("win32")
93 au BufReadCmd file://* exe "doau BufReadPre ".expand("<afile>")|exe 'e '.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
94 else
95 au BufReadCmd file:///* exe "doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
96 au BufReadCmd file://localhost/* exe "doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "doau BufReadPost ".expand("<afile>")
97 endif
98 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "doau BufReadPre ".expand("<afile>")|exe "Nread 0r ".expand("<afile>")|exe "doau BufReadPost ".expand("<afile>")
99 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "doau BufReadPre ".expand("<afile>")|exe "Nread " .expand("<afile>")|exe "doau BufReadPost ".expand("<afile>")
100 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "Nwrite " .expand("<afile>")|call <SID>NetRestorePosn()
101 augroup END
102endif
103
104" ------------------------------------------------------------------------
105" Commands: :Nread, :Nwrite, and :NetUserPass {{{1
106com! -nargs=* Nread call <SID>NetSavePosn()<bar>call <SID>NetRead(<f-args>)<bar>call <SID>NetRestorePosn()
107com! -range=% -nargs=* Nwrite call <SID>NetSavePosn()<bar><line1>,<line2>call <SID>NetWrite(<f-args>)<bar>call <SID>NetRestorePosn()
108com! -nargs=* NetUserPass call NetUserPass(<f-args>)
109
110" ------------------------------------------------------------------------
111" NetSavePosn: saves position of cursor on screen {{{1
112fun! s:NetSavePosn()
113" call Dfunc("NetSavePosn()")
114 " Save current line and column
115 let s:netrw_winnr= winnr()
116 let s:netrw_line = line(".")
117 let s:netrw_col = virtcol(".")
118
119 " Save top-of-screen line
120 norm! H0
121 let s:netrw_hline= line(".")
122
123 call s:NetRestorePosn()
124" call Dret("NetSavePosn : winnr=".s:netrw_winnr." line=".s:netrw_line." col=".s:netrw_col." hline=".s:netrw_hline)
125endfun
126
127" ------------------------------------------------------------------------
128" NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{1
129fun! <SID>NetRestorePosn()
130" call Dfunc("NetRestorePosn() winnr=".s:netrw_winnr." line=".s:netrw_line." col=".s:netrw_col." hline=".s:netrw_hline)
131
132 exe "silent! ".s:netrw_winnr."wincmd w"
133 if v:shell_error == 0
134 " as suggested by Bram M: redraw on no error
135 " allows protocol error messages to remain visible
136 redraw!
137 endif
138 " restore top-of-screen line
139 exe "norm! ".s:netrw_hline."G0z\<CR>"
140 " restore position
141 exe "norm! ".s:netrw_line."G0".s:netrw_col."\<bar>"
142
143" call Dret("NetRestorePosn")
144endfun
145
146" ------------------------------------------------------------------------
147" NetRead: responsible for reading a file over the net {{{1
148fun! s:NetRead(...)
149" call Dfunc("NetRead(a:1<".a:1.">)")
150
151 " save options
152 call s:NetOptionSave()
153
154 " get name of a temporary file
155 let tmpfile= tempname()
156
157 " Special Exception: if a file is named "0r", then
158 " "0r" will be used to read the
159 " following files instead of "r"
160 if a:0 == 0
161 let readcmd= "r"
162 let ichoice= 0
163 elseif a:1 == "0r"
164 let readcmd = "0r"
165 let ichoice = 2
166 else
167 let readcmd = "r"
168 let ichoice = 1
169 endif
170
171 while ichoice <= a:0
172
173 " attempt to repeat with previous host-file-etc
174 if exists("b:netrw_lastfile") && a:0 == 0
175" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
176 let choice = b:netrw_lastfile
177 let ichoice= ichoice + 1
178
179 else
180 exe "let choice= a:" . ichoice
181" call Decho("NetRead1: choice<" . choice . ">")
182
183 " Reconstruct Choice if choice starts with '"'
184 if match(choice,"?") == 0
185 echo 'NetRead Usage:'
186 echo ':Nread machine:path uses rcp'
187 echo ':Nread "machine path" uses ftp with <.netrc>'
188 echo ':Nread "machine id password path" uses ftp'
189 echo ':Nread dav://machine[:port]/path uses cadaver'
190 echo ':Nread fetch://machine/path uses fetch'
191 echo ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
192 echo ':Nread http://[user@]machine/path uses http wget'
193 echo ':Nread rcp://[user@]machine/path uses rcp'
194 echo ':Nread rsync://machine[:port]/path uses rsync'
195 echo ':Nread scp://[user@]machine[[:#]port]/path uses scp'
196 echo ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
197 break
198 elseif match(choice,"^\"") != -1
199" call Decho("reconstructing choice")
200 if match(choice,"\"$") != -1
201 " case "..."
202 let choice=strpart(choice,1,strlen(choice)-2)
203 else
204 " case "... ... ..."
205 let choice = strpart(choice,1,strlen(choice)-1)
206 let wholechoice = ""
207
208 while match(choice,"\"$") == -1
209 let wholechoice = wholechoice . " " . choice
210 let ichoice = ichoice + 1
211 if ichoice > a:0
212 echoerr "Unbalanced string in filename '". wholechoice ."'"
213" call Dret("NetRead")
214 return
215 endif
216 let choice= a:{ichoice}
217 endwhile
218 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
219 endif
220 endif
221 endif
222" call Decho("NetRead2: choice<" . choice . ">")
223 let ichoice= ichoice + 1
224
225 " fix up windows urls
226 if has("win32")
227 let choice = substitute(choice,'\\','/','ge')
228" call Decho("fixing up windows url to <".choice.">")
229 exe 'lcd ' . fnamemodify(tmpfile,':h')
230 let tmpfile = fnamemodify(tmpfile,':t')
231 endif
232
233 " Determine method of read (ftp, rcp, etc)
234 call s:NetMethod(choice)
235
236 " ============
237 " Perform Read
238 " ============
239
240 ".........................................
241 " rcp: Method #1
242 if b:netrw_method == 1 " read with rcp
243" call Decho("read via rcp (method #1)")
244 " ER: noting done with g:netrw_uid yet?
245 " ER: on Win2K" rcp machine[.user]:file tmpfile
246 " ER: if machine contains '.' adding .user is required (use $USERNAME)
247 " ER: the tmpfile is full path: rcp sees C:\... as host C
248 if s:netrw_has_nt_rcp == 1
249 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
250 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
251 else
252 " Any way needed it machine contains a '.'
253 let uid_machine = g:netrw_machine .'.'. $USERNAME
254 endif
255 else
256 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
257 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
258 else
259 let uid_machine = g:netrw_machine
260 endif
261 endif
262" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
263 exe "!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
264 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
265 let b:netrw_lastfile = choice
266
267 ".........................................
268 " ftp + <.netrc>: Method #2
269 elseif b:netrw_method == 2 " read with ftp + <.netrc>
270" call Decho("read via ftp+.netrc (method #2)")
271 let netrw_fname= b:netrw_fname
272 new
273 set ff=unix
274 exe "put ='".g:netrw_ftpmode."'"
275 exe "put ='get ".netrw_fname." ".tmpfile."'"
276 if exists("g:netrw_port") && g:netrw_port != ""
277" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
278 exe "%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
279 else
280" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
281 exe "%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
282 endif
283 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
284 if getline(1) !~ "^$"
285 echoerr getline(1)
286 endif
287 bd!
288 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
289 let b:netrw_lastfile = choice
290
291 ".........................................
292 " ftp + machine,id,passwd,filename: Method #3
293 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
294 " Construct execution string (four lines) which will be passed through filter
295" call Decho("read via ftp+mipf (method #3)")
296 let netrw_fname= b:netrw_fname
297 new
298 set ff=unix
299 if exists("g:netrw_port") && g:netrw_port != ""
300 put ='open '.g:netrw_machine.' '.g:netrw_port
301 else
302 put ='open '.g:netrw_machine
303 endif
304
305 if exists("g:netrw_ftp") && g:netrw_ftp == 1
306 put =g:netrw_uid
307 put =g:netrw_passwd
308 else
309 put ='user '.g:netrw_uid.' '.g:netrw_passwd
310 endif
311
312 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
313 put =g:netrw_ftpmode
314 endif
315 put ='get '.netrw_fname.' '.tmpfile
316
317 " perform ftp:
318 " -i : turns off interactive prompting from ftp
319 " -n unix : DON'T use <.netrc>, even though it exists
320 " -n win32: quit being obnoxious about password
321" call Decho('performing ftp -i -n')
322 norm 1Gdd
323" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
324 exe "%!".g:netrw_ftp_cmd." -i -n"
325 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
326 if getline(1) !~ "^$"
327 echoerr getline(1)
328 endif
329 bd!
330 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
331 let b:netrw_lastfile = choice
332
333 ".........................................
334 " scp: Method #4
335 elseif b:netrw_method == 4 " read with scp
336" call Decho("read via scp (method #4)")
337 if exists("g:netrw_port") && g:netrw_port != ""
338 let useport= " -P ".g:netrw_port
339 else
340 let useport= ""
341 endif
342 if g:netrw_cygwin == 1
343 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
344" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
345 exe "!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
346 else
347" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
348 exe "!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
349 endif
350 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
351 let b:netrw_lastfile = choice
352
353 ".........................................
354 elseif b:netrw_method == 5 " read with http (wget)
355" call Decho("read via http (method #5)")
356 if g:netrw_http_cmd == ""
357 echoerr "neither wget nor fetch command is available"
358 exit
359 endif
360
361 if match(b:netrw_fname,"#") == -1
362 " simple wget
363" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&'))
364 exe "!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&')
365 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
366
367 else
368 " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
369 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
370 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
371" call Decho("netrw_html<".netrw_html.">")
372" call Decho("netrw_tag <".netrw_tag.">")
373" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html)
374 exe "!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html
375 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
376" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
377 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
378 endif
379 let b:netrw_lastfile = choice
380
381 ".........................................
382 " cadaver: Method #6
383 elseif b:netrw_method == 6 " read with cadaver
384" call Decho("read via cadaver (method #6)")
385
386 " Construct execution string (four lines) which will be passed through filter
387 let netrw_fname= b:netrw_fname
388 new
389 set ff=unix
390 if exists("g:netrw_port") && g:netrw_port != ""
391 put ='open '.g:netrw_machine.' '.g:netrw_port
392 else
393 put ='open '.g:netrw_machine
394 endif
395 put ='user '.g:netrw_uid.' '.g:netrw_passwd
396
397 if g:netrw_cygwin == 1
398 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
399 put ='get '.netrw_fname.' '.cygtmpfile
400 else
401 put ='get '.netrw_fname.' '.tmpfile
402 endif
403
404 " perform cadaver operation:
405 norm 1Gdd
406" call Decho("executing: %!".g:netrw_dav_cmd)
407 exe "%!".g:netrw_dav_cmd
408 bd!
409 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
410 let b:netrw_lastfile = choice
411
412 ".........................................
413 " rsync: Method #7
414 elseif b:netrw_method == 7 " read with rsync
415" call Decho("read via rsync (method #7)")
416 if g:netrw_cygwin == 1
417 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
418" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
419 exe "!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
420 else
421" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
422 exe "!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
423 endif
424 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
425 let b:netrw_lastfile = choice
426
427 ".........................................
428 " fetch: Method #8
429 " fetch://[user@]host[:http]/path
430 elseif b:netrw_method == 8 " read with fetch
431 if g:netrw_fetch_cmd == ""
432 echoerr "fetch command not available"
433 exit
434 endif
435 if exists("g:netrw_option") && g:netrw_option == ":http"
436 let netrw_option= "http"
437 else
438 let netrw_option= "ftp"
439 endif
440" call Decho("read via fetch for ".netrw_option)
441
442 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != ""
443" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&'))
444 exe "!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&')
445 else
446" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&'))
447 exe "!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&')
448 endif
449
450 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
451 let b:netrw_lastfile = choice
452
453 ".........................................
454 " sftp: Method #9
455 elseif b:netrw_method == 9 " read with sftp
456" call Decho("read via sftp (method #4)")
457 if g:netrw_cygwin == 1
458 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
459" call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
460" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
461 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
462 else
463" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
464 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
465 endif
466 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
467 let b:netrw_lastfile = choice
468
469 ".........................................
470 else " Complain
471 echo "***warning*** unable to comply with your request<" . choice . ">"
472 endif
473 endwhile
474
475 " cleanup
476" call Decho("cleanup")
477 if exists("b:netrw_method")
478 unlet b:netrw_method
479 unlet g:netrw_machine
480 unlet b:netrw_fname
481 endif
482 call s:NetOptionRestore()
483
484" call Dret("NetRead")
485endfun
486" end of NetRead
487
488" ------------------------------------------------------------------------
489" NetGetFile: Function to read file "fname" with command "readcmd". {{{1
490fun! s:NetGetFile(readcmd, fname, method)
491" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,fname<".a:fname."> method<".a:method.">)")
492
493 if exists("*NetReadFixup")
494 " for the use of NetReadFixup (not otherwise used internally)
495 let line2= line("$")
496 endif
497
498 " transform paths from / to \ for Windows, unless the shell is bash
499 if &term == "win32"
500 if &shell == "bash"
501 let fname=a:fname
502" call Decho("(win32 && bash) fname<".fname.">")
503 else
504 let fname=substitute(a:fname,'/','\\\\','ge')
505" call Decho("(win32 && !bash) fname<".fname.">")
506 endif
507 else
508 let fname= a:fname
509" call Decho("(copied) fname<".fname.">")
510 endif
511
512 " get the file, but disable undo when reading a new buffer
513 if a:readcmd[0] == '0'
514 let use_e_cmd = 0 " 1 when using ':edit'
515 let delline = 0 " 1 when have to delete empty last line
516 if line("$") == 1 && getline(1) == ""
517 " Now being asked to 0r a file into an empty file.
518 " Safe to :e it instead, unless there is another window on the same buffer.
519 let curbufnr = bufnr("%")
520 let use_e_cmd = 1
521 let delline = 1
522 " Loop over all windows,
523 " reset use_e_cmd when another one is editing the current buffer.
524 let i = 1
525 while 1
526 if i != winnr() && winbufnr(i) == curbufnr
527 let use_e_cmd = 0
528 break
529 endif
530 let i = i + 1
531 if winbufnr(i) < 0
532 break
533 endif
534 endwhile
535 endif
536
537 if use_e_cmd > 0
538 " ':edit' the temp file, wipe out the old buffer and rename the buffer
539 let curfilename = expand("%")
540
541 let binlocal = &l:bin
542 let binglobal = &g:bin
543 if binlocal
544 setglobal bin " Need to set 'bin' globally for ":e" command.
545 endif
546 silent exe "e! ".v:cmdarg." ".fname
547 if binlocal && !binglobal
548 setglobal nobin
549 setlocal bin
550 endif
551
552 exe curbufnr . "bwipe!"
553 exe "f ".curfilename
554 " the ":f newname" apparently leaves the temporary file as the alternate
555 " file in the buffer list (see :ls!). The following command wipes it out.
556 exe bufnr("#")."bwipe!"
557 else
558 let oldul= &ul
559 set ul=-1
560 exe a:readcmd." ".v:cmdarg." ".fname
561 if delline > 0
562 " wipe out last line, which should be a blank line anyway
563 $del
564 endif
565 let &ul= oldul
566 endif
567 else
568 exe a:readcmd." ".v:cmdarg." ".fname
569 endif
570
571 " User-provided (ie. optional) fix-it-up command
572 if exists("*NetReadFixup")
573 let line1= line(".")
574 if a:readcmd == "r"
575 let line2= line("$") - line2 + line1
576 else
577 let line2= line("$") - line2
578 endif
579" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
580 call NetReadFixup(a:method, line1, line2)
581 endif
582" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> fname<".a:fname."> readable=".filereadable(a:fname))
583
584" insure that we have the right filetype and that its being displayed
585 filetype detect
586 redraw!
587" call Dret("NetGetFile")
588endfun
589
590" ------------------------------------------------------------------------
591" NetWrite: responsible for writing a file over the net {{{1
592fun! s:NetWrite(...) range
593" call Dfunc("NetWrite(a:0=".a:0.")")
594
595 " option handling
596 let mod= 0
597 call s:NetOptionSave()
598
599 " Get Temporary Filename
600 let tmpfile= tempname()
601
602 if a:0 == 0
603 let ichoice = 0
604 else
605 let ichoice = 1
606 endif
607
608 " write (selected portion of) file to temporary
609 silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
610
611 while ichoice <= a:0
612
613 " attempt to repeat with previous host-file-etc
614 if exists("b:netrw_lastfile") && a:0 == 0
615" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
616 let choice = b:netrw_lastfile
617 let ichoice= ichoice + 1
618 else
619 exe "let choice= a:" . ichoice
620
621 " Reconstruct Choice if choice starts with '"'
622 if match(choice,"?") == 0
623 echo 'NetWrite Usage:"'
624 echo ':Nwrite machine:path uses rcp'
625 echo ':Nwrite "machine path" uses ftp with <.netrc>'
626 echo ':Nwrite "machine id password path" uses ftp'
627 echo ':Nwrite dav://[user@]machine/path uses cadaver'
628 echo ':Nwrite fetch://[user@]machine/path uses fetch'
629 echo ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
630 echo ':Nwrite rcp://machine/path uses rcp'
631 echo ':Nwrite rsync://[user@]machine/path uses rsync'
632 echo ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
633 echo ':Nwrite sftp://[user@]machine/path uses sftp'
634 break
635
636 elseif match(choice,"^\"") != -1
637 if match(choice,"\"$") != -1
638 " case "..."
639 let choice=strpart(choice,1,strlen(choice)-2)
640 else
641 " case "... ... ..."
642 let choice = strpart(choice,1,strlen(choice)-1)
643 let wholechoice = ""
644
645 while match(choice,"\"$") == -1
646 let wholechoice= wholechoice . " " . choice
647 let ichoice = ichoice + 1
648 if choice > a:0
649 echoerr "Unbalanced string in filename '". wholechoice ."'"
650" call Dret("NetWrite")
651 return
652 endif
653 let choice= a:{ichoice}
654 endwhile
655 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
656 endif
657 endif
658 endif
659" call Decho("choice<" . choice . ">")
660 let ichoice= ichoice + 1
661
662 " fix up windows urls
663 if has("win32")
664 let choice= substitute(choice,'\\','/','ge')
665 "ER: see NetRead()
666 exe 'lcd ' . fnamemodify(tmpfile,':h')
667 let tmpfile = fnamemodify(tmpfile,':t')
668 endif
669
670 " Determine method of read (ftp, rcp, etc)
671 call s:NetMethod(choice)
672
673 " =============
674 " Perform Write
675 " =============
676
677 ".........................................
678 " rcp: Method #1
679 if b:netrw_method == 1 " write with rcp
680" Decho "write via rcp (method #1)"
681 if s:netrw_has_nt_rcp == 1
682 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
683 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
684 else
685 let uid_machine = g:netrw_machine .'.'. $USERNAME
686 endif
687 else
688 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
689 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
690 else
691 let uid_machine = g:netrw_machine
692 endif
693 endif
694" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&'))
695 exe "!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&')
696 let b:netrw_lastfile = choice
697
698 ".........................................
699 " ftp + <.netrc>: Method #2
700 elseif b:netrw_method == 2 " write with ftp + <.netrc>
701 let netrw_fname = b:netrw_fname
702 new
703 set ff=unix
704 exe "put ='".g:netrw_ftpmode."'"
705" call Decho(" NetWrite: put ='".g:netrw_ftpmode."'")
706 exe "put ='put ".tmpfile." ".netrw_fname."'"
707" call Decho("put ='put ".tmpfile." ".netrw_fname."'")
708 if exists("g:netrw_port") && g:netrw_port != ""
709" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
710 exe "%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
711 else
712" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
713 exe "%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
714 endif
715 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
716 if getline(1) !~ "^$"
717 echoerr getline(1)
718 let mod=1
719 endif
720 bd!
721 let b:netrw_lastfile = choice
722
723 ".........................................
724 " ftp + machine, id, passwd, filename: Method #3
725 elseif b:netrw_method == 3 " write with ftp + machine, id, passwd, and fname
726 let netrw_fname= b:netrw_fname
727 new
728 set ff=unix
729 if exists("g:netrw_port") && g:netrw_port != ""
730 put ='open '.g:netrw_machine.' '.g:netrw_port
731 else
732 put ='open '.g:netrw_machine
733 endif
734 if exists("g:netrw_ftp") && g:netrw_ftp == 1
735 put =g:netrw_uid
736 put =g:netrw_passwd
737 else
738 put ='user '.g:netrw_uid.' '.g:netrw_passwd
739 endif
740 put ='put '.tmpfile.' '.netrw_fname
741 " save choice/id/password for future use
742 let b:netrw_lastfile = choice
743
744 " perform ftp:
745 " -i : turns off interactive prompting from ftp
746 " -n unix : DON'T use <.netrc>, even though it exists
747 " -n win32: quit being obnoxious about password
748" call Decho('performing ftp -i -n')
749 norm 1Gdd
750" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
751 exe "%!".g:netrw_ftp_cmd." -i -n"
752 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
753 if getline(1) !~ "^$"
754 echoerr getline(1)
755 let mod=1
756 endif
757 bd!
758
759 ".........................................
760 " scp: Method #4
761 elseif b:netrw_method == 4 " write with scp
762 if exists("g:netrw_port") && g:netrw_port != ""
763 let useport= " -P ".g:netrw_port
764 else
765 let useport= ""
766 endif
767 if g:netrw_cygwin == 1
768 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
769" call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
770 exe "!".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
771 else
772" call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
773 exe "!".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
774 endif
775 let b:netrw_lastfile = choice
776
777 ".........................................
778 " http: Method #5
779 elseif b:netrw_method == 5
780 echoerr "***warning*** currently <netrw.vim> does not support writing using http:"
781
782 ".........................................
783 " dav: Method #6
784 elseif b:netrw_method == 6 " write with cadaver
785" call Decho("write via cadaver (method #6)")
786
787 " Construct execution string (four lines) which will be passed through filter
788 let netrw_fname= b:netrw_fname
789 new
790 set ff=unix
791 if exists("g:netrw_port") && g:netrw_port != ""
792 put ='open '.g:netrw_machine.' '.g:netrw_port
793 else
794 put ='open '.g:netrw_machine
795 endif
796 put ='user '.g:netrw_uid.' '.g:netrw_passwd
797
798 if g:netrw_cygwin == 1
799 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
800 put ='put '.cygtmpfile.' '.netrw_fname
801 else
802 put ='put '.tmpfile.' '.netrw_fname
803 endif
804
805 " perform cadaver operation:
806 norm 1Gdd
807" call Decho("executing: %!".g:netrw_dav_cmd)
808 exe "%!".g:netrw_dav_cmd
809 bd!
810 let b:netrw_lastfile = choice
811
812 ".........................................
813 " rsync: Method #7
814 elseif b:netrw_method == 7 " write with rsync
815 if g:netrw_cygwin == 1
816 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
817" call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
818 exe "!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
819 else
820" call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
821 exe "!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
822 endif
823 let b:netrw_lastfile = choice
824
825 ".........................................
826 " scp: Method #9
827 elseif b:netrw_method == 9 " write with sftp
828 let netrw_fname= b:netrw_fname
829 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
830 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
831 else
832 let uid_machine = g:netrw_machine
833 endif
834 new
835 set ff=unix
836 put ='put '.tmpfile.' '.netrw_fname
837 norm 1Gdd
838" call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine)
839 exe "%!".g:netrw_sftp_cmd.' '.uid_machine
840 bd!
841 let b:netrw_lastfile= choice
842
843 ".........................................
844 else " Complain
845 echo "***warning*** unable to comply with your request<" . choice . ">"
846 endif
847 endwhile
848
849 " cleanup
850" call Decho("cleanup")
851 let result=delete(tmpfile)
852 call s:NetOptionRestore()
853
854 if a:firstline == 1 && a:lastline == line("$")
855 let &mod= mod " usually equivalent to set nomod
856 endif
857
858" call Dret("NetWrite")
859endfun
860" end of NetWrite
861
862" ------------------------------------------------------------------------
863" NetMethod: determine method of transfer {{{1
864" method == 1: rcp
865" 2: ftp + <.netrc>
866" 3: ftp + machine, id, password, and [path]filename
867" 4: scp
868" 5: http (wget)
869" 6: cadaver
870" 7: rsync
871" 8: fetch
872" 9: sftp
873fun! s:NetMethod(choice) " globals: method machine id passwd fname
874" call Dfunc("NetMethod(a:choice<".a:choice.">)")
875
876 " initialization
877 let b:netrw_method = 0
878 let g:netrw_machine = ""
879 let b:netrw_fname = ""
880 let g:netrw_port = ""
881
882 " Patterns:
883 " mipf : a:machine a:id password filename Use ftp
884 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
885 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
886 " rcpurm : rcp://[user@]host/filename Use rcp
887 " rcphf : [user@]host:filename Use rcp
888 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
889 " httpurm : http://[user@]host/filename Use wget
890 " davurm : dav://host[:port]/path Use cadaver
891 " rsyncurm : rsync://host[:port]/path Use rsync
892 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
893 " sftpurm : sftp://[user@]host/filename Use scp
894 let mipf = '\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)'
895 let mf = '\(\S\+\)\s\+\(\S\+\)'
896 let ftpurm = 'ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
897 let rcpurm = 'rcp://\(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
898 let rcphf = '\(\([^@]\{-}\)@\)\=\(\I\i*\):\(\S\+\)'
899 let scpurm = 'scp://\([^/]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
900 let httpurm = 'http://\([^/]\{-}\)\(/.*\)\=$'
901 let davurm = 'dav://\([^/]\{-}\)/\(.*\)\=$'
902 let rsyncurm = 'rsync://\([^/]\{-}\)/\(.*\)\=$'
903 let fetchurm = 'fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
904 let sftpurm = 'sftp://\([^/]\{-}\)/\(.*\)\=$'
905
906" call Decho("determine method:")
907 " Determine Method
908 " rcp://user@hostname/...path-to-file
909 if match(a:choice,rcpurm) == 0
910" call Decho("rcp://...")
911 let b:netrw_method = 1
912 let userid = substitute(a:choice,rcpurm,'\2',"")
913 let g:netrw_machine= substitute(a:choice,rcpurm,'\3',"")
914 let b:netrw_fname = substitute(a:choice,rcpurm,'\4',"")
915 if userid != ""
916 let g:netrw_uid= userid
917 endif
918
919 " scp://user@hostname/...path-to-file
920 elseif match(a:choice,scpurm) == 0
921" call Decho("scp://...")
922 let b:netrw_method = 4
923 let g:netrw_machine= substitute(a:choice,scpurm,'\1',"")
924 let b:netrw_port = substitute(a:choice,scpurm,'\2',"")
925 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
926
927 " http://user@hostname/...path-to-file
928 elseif match(a:choice,httpurm) == 0
929" call Decho("http://...")
930 let b:netrw_method = 5
931 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
932 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
933
934 " dav://hostname[:port]/..path-to-file..
935 elseif match(a:choice,davurm) == 0
936" call Decho("dav://...")
937 let b:netrw_method= 6
938 let g:netrw_machine= substitute(a:choice,davurm,'\1',"")
939 let b:netrw_fname = substitute(a:choice,davurm,'\2',"")
940
941 " rsync://user@hostname/...path-to-file
942 elseif match(a:choice,rsyncurm) == 0
943" call Decho("rsync://...")
944 let b:netrw_method = 7
945 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
946 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
947
948 " ftp://[user@]hostname[[:#]port]/...path-to-file
949 elseif match(a:choice,ftpurm) == 0
950" call Decho("ftp://...")
951 let userid = substitute(a:choice,ftpurm,'\2',"")
952 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
953 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
954 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
955 if g:netrw_port != ""
956 let g:netrw_port = substitute(g:netrw_port,"[#:]","","")
957 endif
958 if userid != ""
959 let g:netrw_uid= userid
960 endif
961 if exists("g:netrw_uid") && exists("g:netrw_passwd")
962 let b:netrw_method = 3
963 else
964 if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc")
965 let b:netrw_method= 2
966 else
967 if !exists("g:netrw_uid") || g:netrw_uid == ""
968 call NetUserPass()
969 elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
970 call NetUserPass(g:netrw_uid)
971 " else just use current g:netrw_uid and g:netrw_passwd
972 endif
973 let b:netrw_method= 3
974 endif
975 endif
976
977 elseif match(a:choice,fetchurm) == 0
978" call Decho("fetch://...")
979 let b:netrw_method = 8
980 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
981 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
982 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
983 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
984
985 " Issue an ftp : "machine id password [path/]filename"
986 elseif match(a:choice,mipf) == 0
987" call Decho("(ftp) host id pass file")
988 let b:netrw_method = 3
989 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
990 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
991 let g:netrw_passwd = substitute(a:choice,mipf,'\3',"")
992 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
993
994 " Issue an ftp: "hostname [path/]filename"
995 elseif match(a:choice,mf) == 0
996" call Decho("(ftp) host file")
997 if exists("g:netrw_uid") && exists("g:netrw_passwd")
998 let b:netrw_method = 3
999 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1000 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
1001
1002 elseif filereadable(expand("$HOME/.netrc"))
1003 let b:netrw_method = 2
1004 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1005 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
1006 endif
1007
1008 " sftp://user@hostname/...path-to-file
1009 elseif match(a:choice,sftpurm) == 0
1010" call Decho("sftp://...")
1011 let b:netrw_method = 9
1012 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
1013 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
1014
1015 " Issue an rcp: hostname:filename" (this one should be last)
1016 elseif match(a:choice,rcphf) == 0
1017" call Decho("(rcp) host:file)")
1018 let b:netrw_method = 1
1019 let userid = substitute(a:choice,rcphf,'\2',"")
1020 let g:netrw_machine= substitute(a:choice,rcphf,'\3',"")
1021 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
1022 if userid != ""
1023 let g:netrw_uid= userid
1024 endif
1025 if has("win32")
1026 " don't let PCs try <.netrc>
1027 let b:netrw_method = 3
1028 endif
1029
1030 else
1031 echoerr "***error*** cannot determine method"
1032 let b:netrw_method = -1
1033 endif
1034
1035" call Decho("a:choice <".a:choice.">")
1036" call Decho("b:netrw_method <".b:netrw_method.">")
1037" call Decho("g:netrw_machine<".g:netrw_machine.">")
1038" call Decho("g:netrw_port <".g:netrw_port.">")
1039" if exists("g:netrw_uid") "Decho
1040" call Decho("g:netrw_uid <".g:netrw_uid.">")
1041" endif "Decho
1042" if exists("g:netrw_passwd") "Decho
1043" call Decho("g:netrw_passwd <".g:netrw_passwd.">")
1044" endif "Decho
1045" call Decho("b:netrw_fname <".b:netrw_fname.">")
1046" call Dret("NetMethod")
1047endfun
1048" end of NetMethod
1049
1050" ------------------------------------------------------------------------
1051" NetUserPass: set username and password for subsequent ftp transfer {{{1
1052" Usage: :call NetUserPass() -- will prompt for userid and password
1053" :call NetUserPass("uid") -- will prompt for password
1054" :call NetUserPass("uid","password") -- sets global userid and password
1055fun! NetUserPass(...)
1056
1057 " get/set userid
1058 if a:0 == 0
1059" call Dfunc("NetUserPass(a:0<".a:0.">)")
1060 if !exists("g:netrw_uid") || g:netrw_uid == ""
1061 " via prompt
1062 let g:netrw_uid= input('Enter username: ')
1063 endif
1064 else " from command line
1065" call Dfunc("NetUserPass(a:1<".a:1.">) {")
1066 let g:netrw_uid= a:1
1067 endif
1068
1069 " get password
1070 if a:0 <= 1 " via prompt
1071" call Decho("a:0=".a:0." case <=1:")
1072 let g:netrw_passwd= inputsecret("Enter Password: ")
1073 else " from command line
1074" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
1075 let g:netrw_passwd=a:2
1076 endif
1077" call Dret("NetUserPass")
1078endfun
1079" end NetUserPass
1080
1081" ------------------------------------------------------------------------
1082" NetOptionSave: save options and set to "standard" form {{{1
1083fun!s:NetOptionSave()
1084" call Dfunc("NetOptionSave()")
1085
1086 " Get Temporary Filename
1087 let s:aikeep = &ai
1088 let s:cinkeep = &cin
1089 let s:cinokeep = &cino
1090 let s:comkeep = &com
1091 let s:cpokeep = &cpo
1092 let s:dirkeep = getcwd()
1093 let s:gdkeep = &gd
1094 let s:twkeep = &tw
1095 set cino =
1096 set com =
1097 set cpo -=aA
1098 set nocin noai
1099 set tw =0
1100 if has("win32") && !has("win95")
1101 let s:swfkeep= &swf
1102 set noswf
1103" call Decho("setting s:swfkeep to <".&swf.">")
1104 endif
1105
1106" call Dret("NetOptionSave")
1107endfun
1108
1109" ------------------------------------------------------------------------
1110" NetOptionRestore: restore options {{{1
1111fun! s:NetOptionRestore()
1112" call Dfunc("NetOptionRestore()")
1113
1114 let &ai = s:aikeep
1115 let &cin = s:cinkeep
1116 let &cino = s:cinokeep
1117 let &com = s:comkeep
1118 let &cpo = s:cpokeep
1119 exe "lcd ".s:dirkeep
1120 let &gd = s:gdkeep
1121 let &tw = s:twkeep
1122 if exists("s:swfkeep")
1123 let &swf= s:swfkeep
1124 unlet s:swfkeep
1125 endif
1126 unlet s:aikeep
1127 unlet s:cinkeep
1128 unlet s:cinokeep
1129 unlet s:comkeep
1130 unlet s:cpokeep
1131 unlet s:gdkeep
1132 unlet s:twkeep
1133 unlet s:dirkeep
1134
1135" call Dret("NetOptionRestore")
1136endfun
1137
1138" ------------------------------------------------------------------------
1139" NetReadFixup: this sort of function is typically written by the user {{{1
1140" to handle extra junk that their system's ftp dumps
1141" into the transfer. This function is provided as an
1142" example and as a fix for a Windows 95 problem: in my
1143" experience, win95's ftp always dumped four blank lines
1144" at the end of the transfer.
1145if has("win95") && g:netrw_win95ftp
1146 fun! NetReadFixup(method, line1, line2)
1147" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
1148 if method == 3 " ftp (no <.netrc>)
1149 let fourblanklines= line2 - 3
1150 silent fourblanklines.",".line2."g/^\s*/d"
1151 endif
1152" call Dret("NetReadFixup")
1153 endfun
1154endif
1155
1156" ------------------------------------------------------------------------
1157" Restore {{{1
1158let &cpo= s:save_cpo
1159unlet s:save_cpo
1160" vim:ts=8 fdm=marker