blob: 4f74fbb8ad496040b92bc99a3fcd1445b93f0c69 [file] [log] [blame]
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001" netrw.vim: Handles file transfer and remote directory listing across a network
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002" AUTOLOAD PORTION
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003" Date: Nov 18, 2005
4" Version: 75
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005" Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
7" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +00008" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
12" *as is* and comes with no warranty of any kind, either
13" expressed or implied. By using this plugin, you agree that
14" in no event will the copyright holder be liable for any damages
15" resulting from the use of this software.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000016" of this software.
Bram Moolenaar071d4272004-06-13 20:20:40 +000017"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000018" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" (James 1:22 RSV)
20" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar1afcace2005-11-25 19:54:28 +000021
22" Exception for &cp: {{{1
23if &cp || exists("g:loaded_netrw")
24 finish
25endif
26let g:loaded_netrw = "v75"
Bram Moolenaar578b49e2005-09-10 19:22:57 +000027if v:version < 700
28 echohl WarningMsg | echo "***netrw*** you need vim version 7.0 or later for version ".g:loaded_netrw." of netrw" | echohl None
29 finish
30endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +000031let s:keepcpo= &cpo
32set cpo&vim
33" call Decho("doing autoload/netrw.vim")
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +000036" Default values for netrw's global protocol variables {{{1
37if !exists("g:netrw_dav_cmd")
38 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar071d4272004-06-13 20:20:40 +000039endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +000040if !exists("g:netrw_fetch_cmd")
41 if executable("fetch")
42 let g:netrw_fetch_cmd = "fetch -o"
43 else
44 let g:netrw_fetch_cmd = ""
45 endif
46endif
47if !exists("g:netrw_ftp_cmd")
48 let g:netrw_ftp_cmd = "ftp"
49endif
50if !exists("g:netrw_http_cmd")
51 if executable("wget")
52 let g:netrw_http_cmd = "wget -q -O"
53 elseif executable("fetch")
54 let g:netrw_http_cmd = "fetch -o"
55 else
56 let g:netrw_http_cmd = ""
57 endif
58endif
59if !exists("g:netrw_rcp_cmd")
60 let g:netrw_rcp_cmd = "rcp"
61endif
62if !exists("g:netrw_rsync_cmd")
63 let g:netrw_rsync_cmd = "rsync"
64endif
65if !exists("g:netrw_scp_cmd")
66 let g:netrw_scp_cmd = "scp -q"
67endif
68if !exists("g:netrw_sftp_cmd")
69 let g:netrw_sftp_cmd = "sftp"
70endif
71if !exists("g:netrw_ssh_cmd")
72 let g:netrw_ssh_cmd= "ssh"
73endif
74
75if has("win32") || has("win95") || has("win64") || has("win16")
76 \ && exists("g:netrw_use_nt_rcp")
77 \ && g:netrw_use_nt_rcp
78 \ && executable( $SystemRoot .'/system32/rcp.exe')
79 let s:netrw_has_nt_rcp = 1
80 let s:netrw_rcpmode = '-b'
81 else
82 let s:netrw_has_nt_rcp = 0
83 let s:netrw_rcpmode = ''
84endif
85
86" ---------------------------------------------------------------------
87" Default values for netrw's global variables {{{1
88" Default values - a-c ---------- {{{2
89if !exists("g:netrw_alto")
90 let g:netrw_alto= 0
91endif
92if !exists("g:netrw_altv")
93 let g:netrw_altv= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000094endif
95if !exists("g:netrw_cygwin")
Bram Moolenaard4755bb2004-09-02 19:12:26 +000096 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000097 if &shell == "bash"
98 let g:netrw_cygwin= 1
99 else
100 let g:netrw_cygwin= 0
101 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102 else
103 let g:netrw_cygwin= 0
104 endif
105endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000106" Default values - d-f ---------- {{{2
107if !exists("g:NETRW_DIRHIST_CNT")
108 let g:NETRW_DIRHIST_CNT= 0
109endif
110if !exists("g:netrw_dirhistmax")
111 let g:netrw_dirhistmax= 10
112endif
113if !exists("g:netrw_ftp_browse_reject")
114 let g:netrw_ftp_browse_reject='^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$'
Bram Moolenaar843ee412004-06-30 16:16:41 +0000115endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000116if !exists("g:netrw_ftp_list_cmd")
117 if has("unix") || exists("g:netrw_cygwin")
118 let g:netrw_ftp_list_cmd= "ls -lF"
119 else
120 let g:netrw_ftp_list_cmd= "dir"
121 endif
122endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000123if !exists("g:netrw_ftpmode")
124 let g:netrw_ftpmode= "binary"
Bram Moolenaar61036992005-10-12 20:54:52 +0000125endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000126" Default values - h-lh ---------- {{{2
127if !exists("g:netrw_hide")
128 let g:netrw_hide= 1
Bram Moolenaar61036992005-10-12 20:54:52 +0000129endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000130if !exists("g:netrw_keepdir")
131 let g:netrw_keepdir= 1
132endif
133if !exists("g:netrw_list_cmd")
134 if executable(g:netrw_ssh_cmd)
135 " provide a default listing command
136 let g:netrw_list_cmd= g:netrw_ssh_cmd." HOSTNAME ls -FLa"
137 else
138" call Decho(g:netrw_ssh_cmd." is not executable, can't do remote directory exploring)
139 let g:netrw_list_cmd= ""
140 endif
141endif
142if !exists("g:netrw_list_hide")
143 let g:netrw_list_hide= ""
144endif
145" Default values - lh-lz ---------- {{{2
146if !exists("g:netrw_local_mkdir")
147 let g:netrw_local_mkdir= "mkdir"
148endif
149if !exists("g:netrw_local_rmdir")
150 let g:netrw_local_rmdir= "rmdir"
151endif
152if !exists("g:netrw_longlist")
153 let g:netrw_longlist= 0
154endif
155if g:netrw_longlist < 0 || g:netrw_longlist > 2
156 " sanity check
157 let g:netrw_longlist= 0
158endif
159if g:netrw_longlist == 1
160 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
161endif
162" Default values - m-r ---------- {{{2
163if !exists("g:netrw_maxfilenamelen")
164 let g:netrw_maxfilenamelen= 32
165endif
166if !exists("g:netrw_mkdir_cmd")
167 let g:netrw_mkdir_cmd= g:netrw_ssh_cmd." HOSTNAME mkdir"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000168endif
169if !exists("g:netrw_rename_cmd")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000170 let g:netrw_rename_cmd= g:netrw_ssh_cmd." HOSTNAME mv"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000171endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000172if !exists("g:netrw_rm_cmd")
173 let g:netrw_rm_cmd = g:netrw_ssh_cmd." HOSTNAME rm"
174endif
175if !exists("g:netrw_rmdir_cmd")
176 let g:netrw_rmdir_cmd = g:netrw_ssh_cmd." HOSTNAME rmdir"
177endif
178if !exists("g:netrw_rmf_cmd")
179 let g:netrw_rmf_cmd = g:netrw_ssh_cmd." HOSTNAME rm -f"
180endif
181" Default values - s ---------- {{{2
Bram Moolenaar843ee412004-06-30 16:16:41 +0000182if exists("g:netrw_silent") && g:netrw_silent != 0
183 let g:netrw_silentxfer= "silent "
184else
185 let g:netrw_silentxfer= ""
186endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000187if !exists("g:netrw_sort_by")
188 " alternatives: date size
189 let g:netrw_sort_by= "name"
190endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000191if !exists("g:netrw_sort_direction")
192 " alternative: reverse (z y x ...)
193 let g:netrw_sort_direction= "normal"
194endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000195if !exists("g:netrw_sort_sequence")
196 let g:netrw_sort_sequence= '[\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000197endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000198if !exists("g:netrw_ssh_browse_reject")
199 let g:netrw_ssh_browse_reject='^total\s\+\d\+$'
200endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000201" Default values - t-w ---------- {{{2
202if !exists("g:netrw_timefmt")
203 let g:netrw_timefmt= "%c"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000204endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000205if !exists("g:netrw_win95ftp")
206 let g:netrw_win95ftp= 1
207endif
208if !exists("g:netrw_winsize")
209 let g:netrw_winsize= ""
210endif
211" ---------------------------------------------------------------------
212" Default values for netrw's script variables: {{{1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000213if !exists("s:netrw_cd_escape")
214 if has("win32") || has("win95") || has("win64") || has("win16")
215 let s:netrw_cd_escape="#% "
216 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000217 let s:netrw_cd_escape="[]#*$%'\" ?`!&();<>\\"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000218 endif
219endif
220if !exists("s:netrw_glob_escape")
221 if has("win32") || has("win95") || has("win64") || has("win16")
222 let s:netrw_glob_escape= ""
223 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000224 let s:netrw_glob_escape= '[]*?`{~$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000225 endif
226endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000227
228" BufEnter event ignored by decho when following variable is true
229" Has a side effect that doau BufReadPost doesn't work, so
230" files read by network transfer aren't appropriately highlighted.
231"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233" ------------------------------------------------------------------------
234" NetSavePosn: saves position of cursor on screen {{{1
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000235fun! netrw#NetSavePosn()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000236" call Dfunc("NetSavePosn()")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237 " Save current line and column
Bram Moolenaar488c6512005-08-11 20:09:58 +0000238 let w:netrw_winnr= winnr()
239 let w:netrw_line = line(".")
240 let w:netrw_col = virtcol(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241
242 " Save top-of-screen line
243 norm! H0
Bram Moolenaar488c6512005-08-11 20:09:58 +0000244 let w:netrw_hline= line(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000246 call netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000247" call Dret("NetSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248endfun
249
250" ------------------------------------------------------------------------
251" NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{1
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000252fun! netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000253" call Dfunc("NetRestorePosn() winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline)
Bram Moolenaar572cb562005-08-05 21:35:02 +0000254 let eikeep= &ei
255 set ei=all
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256
Bram Moolenaar81695252004-12-29 20:58:21 +0000257 " restore window
Bram Moolenaar488c6512005-08-11 20:09:58 +0000258" call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w")
259 exe "silent! ".w:netrw_winnr."wincmd w"
Bram Moolenaar572cb562005-08-05 21:35:02 +0000260" if v:shell_error == 0
261" " as suggested by Bram M: redraw on no error
262" " allows protocol error messages to remain visible
263" redraw!
264" endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000265
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266 " restore top-of-screen line
Bram Moolenaar488c6512005-08-11 20:09:58 +0000267" call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z")
268 exe "norm! ".w:netrw_hline."G0z\<CR>"
Bram Moolenaar81695252004-12-29 20:58:21 +0000269
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270 " restore position
Bram Moolenaar488c6512005-08-11 20:09:58 +0000271" call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|")
272 exe "norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
Bram Moolenaar572cb562005-08-05 21:35:02 +0000274 let &ei= eikeep
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000275" call Dret("NetRestorePosn")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276endfun
277
278" ------------------------------------------------------------------------
279" NetRead: responsible for reading a file over the net {{{1
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000280fun! netrw#NetRead(...)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000281" call Dfunc("NetRead(a:1<".a:1.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000282
283 " save options
284 call s:NetOptionSave()
285
286 " Special Exception: if a file is named "0r", then
287 " "0r" will be used to read the
288 " following files instead of "r"
289 if a:0 == 0
290 let readcmd= "r"
291 let ichoice= 0
292 elseif a:1 == "0r"
293 let readcmd = "0r"
294 let ichoice = 2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000296 let readcmd = "r"
297 let ichoice = 1
298 endif
299
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000300 " get name of a temporary file and set up shell-quoting character
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000301 let tmpfile= tempname()
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000302 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000303 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000304 echohl Error | echo "***netrw*** your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000305 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
306" call Dret("NetRead")
307 return
308 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000309
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000310" call Decho("ichoice=".ichoice." readcmd<".readcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000311 while ichoice <= a:0
312
313 " attempt to repeat with previous host-file-etc
314 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000315" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000316 let choice = b:netrw_lastfile
317 let ichoice= ichoice + 1
318
319 else
320 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000321" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000322
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000323 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000324 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000325 echomsg 'NetRead Usage:'
326 echomsg ':Nread machine:path uses rcp'
327 echomsg ':Nread "machine path" uses ftp with <.netrc>'
328 echomsg ':Nread "machine id password path" uses ftp'
329 echomsg ':Nread dav://machine[:port]/path uses cadaver'
330 echomsg ':Nread fetch://machine/path uses fetch'
331 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
332 echomsg ':Nread http://[user@]machine/path uses http wget'
333 echomsg ':Nread rcp://[user@]machine/path uses rcp'
334 echomsg ':Nread rsync://machine[:port]/path uses rsync'
335 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
336 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000337 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000338
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000339 elseif match(choice,"^\"") != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000340 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000341" call Decho("reconstructing choice")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000342 if match(choice,"\"$") != -1
343 " case "..."
344 let choice=strpart(choice,1,strlen(choice)-2)
345 else
346 " case "... ... ..."
347 let choice = strpart(choice,1,strlen(choice)-1)
348 let wholechoice = ""
349
350 while match(choice,"\"$") == -1
351 let wholechoice = wholechoice . " " . choice
352 let ichoice = ichoice + 1
353 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000354 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000355 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000356 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000357 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000358" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000359 return
360 endif
361 let choice= a:{ichoice}
362 endwhile
363 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
364 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365 endif
366 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000368" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000369 let ichoice= ichoice + 1
370
371 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000372 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000373 let choice = substitute(choice,'\\','/','ge')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000374" call Decho("fixing up windows url to <".choice."> tmpfile<".tmpfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000376 exe 'lcd ' . fnamemodify(tmpfile,':h')
377 let tmpfile = fnamemodify(tmpfile,':t')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000378 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000379
380 " Determine method of read (ftp, rcp, etc)
381 call s:NetMethod(choice)
382
Bram Moolenaar843ee412004-06-30 16:16:41 +0000383 " Check if NetBrowse() should be handling this request
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000384" call Decho("checking if netlist: choice<".choice."> netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000385 if choice =~ "^.*[\/]$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000386 keepjumps call s:NetBrowse(choice)
387" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000388 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000390
391 " use filename's suffix for the temporary file
392 if b:netrw_fname =~ '\.[^./]\+'
393 let suffix = substitute(b:netrw_fname,'^.*\(\.[^./]\+\)','\1','e')
394 let tmpfile= substitute(tmpfile,"$",suffix,'e')
395" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix)")
396 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000397
398 " ============
399 " Perform Read
400 " ============
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000401 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
402 echo "(netrw) Processing your read request..."
403 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000404
405 ".........................................
406 " rcp: NetRead Method #1
407 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000408" call Decho("read via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000409 " ER: noting done with g:netrw_uid yet?
410 " ER: on Win2K" rcp machine[.user]:file tmpfile
411 " ER: if machine contains '.' adding .user is required (use $USERNAME)
412 " ER: the tmpfile is full path: rcp sees C:\... as host C
413 if s:netrw_has_nt_rcp == 1
414 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
415 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
416 else
417 " Any way needed it machine contains a '.'
418 let uid_machine = g:netrw_machine .'.'. $USERNAME
419 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000421 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
422 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
423 else
424 let uid_machine = g:netrw_machine
425 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000427" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000428 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
429 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
430 let b:netrw_lastfile = choice
431
432 ".........................................
433 " ftp + <.netrc>: NetRead Method #2
434 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000435" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000436 let netrw_fname= b:netrw_fname
437 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000438 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000439 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000440" call Decho("filter input: ".getline("."))
441 exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'"
442" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000443 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000444" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000445 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
446 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000447" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000448 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
449 endif
450 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar83bab712005-08-01 21:58:57 +0000451 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000452 let debugkeep= &debug
453 set debug=msg
Bram Moolenaar572cb562005-08-05 21:35:02 +0000454 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000455 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000456 let &debug= debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000457 endif
458 bd!
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000459 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000460 let b:netrw_lastfile = choice
461
462 ".........................................
463 " ftp + machine,id,passwd,filename: NetRead Method #3
464 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
465 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000466" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467 let netrw_fname= b:netrw_fname
468 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000469 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000470 if exists("g:netrw_port") && g:netrw_port != ""
471 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000472" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000473 else
474 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000475" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000476 endif
477
478 if exists("g:netrw_ftp") && g:netrw_ftp == 1
479 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000480" call Decho("filter input: ".getline("."))
481 put ='\"'.g:netrw_passwd.'\"'
482" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000483 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000484 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
485" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000486 endif
487
488 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
489 put =g:netrw_ftpmode
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000490" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000491 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000492 put ='get \"'.netrw_fname.'\" '.tmpfile
493" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000494
495 " perform ftp:
496 " -i : turns off interactive prompting from ftp
497 " -n unix : DON'T use <.netrc>, even though it exists
498 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000499 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000500" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000501 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
502 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
503 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000504" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000505 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000506 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000507 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000508 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000509 endif
510 bd!
511 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
512 let b:netrw_lastfile = choice
513
514 ".........................................
515 " scp: NetRead Method #4
516 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000517" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000518 if exists("g:netrw_port") && g:netrw_port != ""
519 let useport= " -P ".g:netrw_port
520 else
521 let useport= ""
522 endif
523 if g:netrw_cygwin == 1
524 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000525" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000526 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
527 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000528" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000529 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
530 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000531 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000532 let b:netrw_lastfile = choice
533
534 ".........................................
535 elseif b:netrw_method == 5 " read with http (wget)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000536" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000537 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000538 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000539 echohl Error | echo "***netrw*** neither wget nor fetch command is available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000540 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000541 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000542" call Dret("NetRead")
543 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000544 endif
545
546 if match(b:netrw_fname,"#") == -1
547 " simple wget
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000548" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000549 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&')
550 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
551
552 else
553 " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
554 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
555 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000556" call Decho("netrw_html<".netrw_html.">")
557" call Decho("netrw_tag <".netrw_tag.">")
558" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000559 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html
560 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000561" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000562 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
563 endif
564 let b:netrw_lastfile = choice
565
566 ".........................................
567 " cadaver: NetRead Method #6
568 elseif b:netrw_method == 6 " read with cadaver
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000569" call Decho("read via cadaver (method #6)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000570
571 " Construct execution string (four lines) which will be passed through filter
572 let netrw_fname= b:netrw_fname
573 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000574 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000575 if exists("g:netrw_port") && g:netrw_port != ""
576 put ='open '.g:netrw_machine.' '.g:netrw_port
577 else
578 put ='open '.g:netrw_machine
579 endif
580 put ='user '.g:netrw_uid.' '.g:netrw_passwd
581
582 if g:netrw_cygwin == 1
583 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
584 put ='get '.netrw_fname.' '.cygtmpfile
585 else
586 put ='get '.netrw_fname.' '.tmpfile
587 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000588 put ='quit'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000589
590 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000591 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000592" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000593 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
594 bd!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000595 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000596 let b:netrw_lastfile = choice
597
598 ".........................................
599 " rsync: NetRead Method #7
600 elseif b:netrw_method == 7 " read with rsync
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000601" call Decho("read via rsync (method #7)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000602 if g:netrw_cygwin == 1
603 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000604" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000605 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
606 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000607" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000608 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
609 endif
610 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
611 let b:netrw_lastfile = choice
612
613 ".........................................
614 " fetch: NetRead Method #8
615 " fetch://[user@]host[:http]/path
616 elseif b:netrw_method == 8 " read with fetch
617 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000618 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000619 echohl Error | echo "***netrw*** fetch command not available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000620 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000621 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000622" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000623 endif
624 if exists("g:netrw_option") && g:netrw_option == ":http"
625 let netrw_option= "http"
626 else
627 let netrw_option= "ftp"
628 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000629" call Decho("read via fetch for ".netrw_option)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000630
631 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000632" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000633 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&')
634 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000635" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000636 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&')
637 endif
638
639 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
640 let b:netrw_lastfile = choice
641
642 ".........................................
643 " sftp: NetRead Method #9
644 elseif b:netrw_method == 9 " read with sftp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000645" call Decho("read via sftp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000646 if g:netrw_cygwin == 1
647 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000648" call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
649" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000650 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
651 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000652" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000653 exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
654 endif
655 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
656 let b:netrw_lastfile = choice
657
658 ".........................................
659 else " Complain
660 echo "***warning*** unable to comply with your request<" . choice . ">"
661 endif
662 endwhile
663
664 " cleanup
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000665" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000666 if exists("b:netrw_method")
667 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000668 unlet b:netrw_fname
669 endif
670 call s:NetOptionRestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +0000671
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000672" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000673endfun
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000674
675" ------------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000676" NetGetFile: Function to read temporary file "tfile" with command "readcmd". {{{1
677fun! s:NetGetFile(readcmd, tfile, method)
678" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
679
680 " get name of remote filename (ie. url and all)
681 let rfile= bufname("%")
682" call Decho("rfile<".rfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000683
684 if exists("*NetReadFixup")
685 " for the use of NetReadFixup (not otherwise used internally)
686 let line2= line("$")
687 endif
688
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000689 " transform paths from / to \ for Windows (except for cygwin)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000690 if &term == "win32"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000691 if g:netrw_cygwin
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000692 let tfile= a:tfile
693" call Decho("(win32 && cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000694 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000695 let tfile= substitute(a:tfile,'/','\\\\','ge')
696" call Decho("(win32 && !cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000697 endif
698 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000699 let tfile= a:tfile
700" call Decho("tfile=a:tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000701 endif
702
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000703 if a:readcmd[0] == '0'
Bram Moolenaar81695252004-12-29 20:58:21 +0000704 " get file into buffer
Bram Moolenaar83bab712005-08-01 21:58:57 +0000705
Bram Moolenaar83bab712005-08-01 21:58:57 +0000706" call Dredir("ls!","starting buffer list")
707
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000708 " rename the current buffer to the temp file (ie. tfile)
709 keepalt exe "file ".tfile
710" call Dredir("ls!","after renaming current buffer to <".tfile.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +0000711
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000712 " edit temporary file (ie. read the temporary file in)
713 if rfile =~ '\.zip$'
714 call zip#Browse(tfile)
715 elseif rfile =~ '\.tar$'
716 call tar#Browse(tfile)
717 else
718 e
719 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +0000720
Bram Moolenaar81695252004-12-29 20:58:21 +0000721 " rename buffer back to remote filename
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000722 keepalt exe "file ".rfile
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000723 filetype detect
724" call Dredir("ls!","renamed buffer back to remote filename<".rfile.">")
Bram Moolenaar81695252004-12-29 20:58:21 +0000725 let line1 = 1
726 let line2 = line("$")
727
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000728 elseif filereadable(tfile)
Bram Moolenaar81695252004-12-29 20:58:21 +0000729 " read file after current line
730 let curline = line(".")
731 let lastline= line("$")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000732" call Decho("exe<".a:readcmd." ".v:cmdarg." ".tfile."> line#".curline)
733 exe a:readcmd." ".v:cmdarg." ".tfile
Bram Moolenaar81695252004-12-29 20:58:21 +0000734 let line1 = curline + 1
735 let line2 = line("$") - lastline + 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000736
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000737 else
Bram Moolenaar81695252004-12-29 20:58:21 +0000738 " not readable
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000739" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
740 echohl WarningMsg | echo "***netrw*** file <".tfile."> not readable"| echohl None
741 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
742" call Dret("NetGetFile : tfile<".tfile."> not readable")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000743 return
744 endif
745
746 " User-provided (ie. optional) fix-it-up command
747 if exists("*NetReadFixup")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000748" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000749 call NetReadFixup(a:method, line1, line2)
Bram Moolenaar83bab712005-08-01 21:58:57 +0000750" else " Decho
751" call Decho("NetReadFixup() not called, doesn't exist")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000752 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000753
754 " update the Buffers menu
755 if has("gui") && has("gui_running")
756 silent! emenu Buffers.Refresh\ menu
757 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000758
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000759" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".filereadable(a:tfile))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000760
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000761 " make sure file is being displayed
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000762 redraw!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000763" call Dret("NetGetFile")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000764endfun
765
766" ------------------------------------------------------------------------
767" NetWrite: responsible for writing a file over the net {{{1
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000768fun! netrw#NetWrite(...) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000769" call Dfunc("NetWrite(a:0=".a:0.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000770
771 " option handling
772 let mod= 0
773 call s:NetOptionSave()
774
775 " Get Temporary Filename
776 let tmpfile= tempname()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000777 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
778 echohl Error | echo "***netrw*** your ".substitute(tmpfile,'[^/]\+$','','e')." directory is missing!"
779 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000780" call Dret("NetWrite")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000781 return
782 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000783
784 if a:0 == 0
785 let ichoice = 0
786 else
787 let ichoice = 1
788 endif
789
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000790 if &binary
791 " for binary writes, write entire file. Line numbers don't really make sense.
792 " Supports the writing of tar and zip files.
793" call Decho("silent exe w! ".v:cmdarg." ".tmpfile)
794 silent exe "w! ".v:cmdarg." ".tmpfile
795 else
796 " write (selected portion of) file to temporary
797" call Decho("silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile)
798 silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
799 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000800
801 while ichoice <= a:0
802
803 " attempt to repeat with previous host-file-etc
804 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000805" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000806 let choice = b:netrw_lastfile
807 let ichoice= ichoice + 1
808 else
809 exe "let choice= a:" . ichoice
810
811 " Reconstruct Choice if choice starts with '"'
812 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000813 echomsg 'NetWrite Usage:"'
814 echomsg ':Nwrite machine:path uses rcp'
815 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
816 echomsg ':Nwrite "machine id password path" uses ftp'
817 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
818 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
819 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
820 echomsg ':Nwrite rcp://machine/path uses rcp'
821 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
822 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
823 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000824 break
825
826 elseif match(choice,"^\"") != -1
827 if match(choice,"\"$") != -1
828 " case "..."
829 let choice=strpart(choice,1,strlen(choice)-2)
830 else
831 " case "... ... ..."
832 let choice = strpart(choice,1,strlen(choice)-1)
833 let wholechoice = ""
834
835 while match(choice,"\"$") == -1
836 let wholechoice= wholechoice . " " . choice
837 let ichoice = ichoice + 1
838 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000839 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000840 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000841 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000842 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000843" call Dret("NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000844 return
845 endif
846 let choice= a:{ichoice}
847 endwhile
848 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
849 endif
850 endif
851 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000852" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000853 let ichoice= ichoice + 1
854
855 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000856 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000857 let choice= substitute(choice,'\\','/','ge')
858 "ER: see NetRead()
859 exe 'lcd ' . fnamemodify(tmpfile,':h')
860 let tmpfile = fnamemodify(tmpfile,':t')
861 endif
862
863 " Determine method of read (ftp, rcp, etc)
864 call s:NetMethod(choice)
865
866 " =============
867 " Perform Write
868 " =============
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000869 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
870 echo "(netrw) Processing your write request..."
871 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000872
873 ".........................................
874 " rcp: NetWrite Method #1
875 if b:netrw_method == 1 " write with rcp
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000876" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000877 if s:netrw_has_nt_rcp == 1
878 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
879 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
880 else
881 let uid_machine = g:netrw_machine .'.'. $USERNAME
882 endif
883 else
884 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
885 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
886 else
887 let uid_machine = g:netrw_machine
888 endif
889 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000890" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000891 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&')
892 let b:netrw_lastfile = choice
893
894 ".........................................
895 " ftp + <.netrc>: NetWrite Method #2
896 elseif b:netrw_method == 2 " write with ftp + <.netrc>
897 let netrw_fname = b:netrw_fname
898 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000899 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000901" call Decho(" filter input: ".getline("."))
902 exe "put ='"."put ".tmpfile.' \"'.netrw_fname.'\"'."'"
903" call Decho(" filter input: ".getline("."))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000905" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000906 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000908" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000909 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 endif
911 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
912 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000913 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000914 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000915 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000916 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000917 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 endif
919 bd!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 let b:netrw_lastfile = choice
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000921
922 ".........................................
923 " ftp + machine, id, passwd, filename: NetWrite Method #3
924 elseif b:netrw_method == 3 " write with ftp + machine, id, passwd, and fname
925 let netrw_fname= b:netrw_fname
926 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000927 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000928 if exists("g:netrw_port") && g:netrw_port != ""
929 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000930" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000931 else
932 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000933" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000934 endif
935 if exists("g:netrw_ftp") && g:netrw_ftp == 1
936 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000937" call Decho("filter input: ".getline("."))
938 put ='\"'.g:netrw_passwd.'\"'
939" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000940 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000941 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
942" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000943 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000944 put ='put '.tmpfile.' \"'.netrw_fname.'\"'
945" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000946 " save choice/id/password for future use
947 let b:netrw_lastfile = choice
948
949 " perform ftp:
950 " -i : turns off interactive prompting from ftp
951 " -n unix : DON'T use <.netrc>, even though it exists
952 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000953 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000954" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000955 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
956 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
957 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000958 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000959 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000960 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000961 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000962 let mod=1
963 endif
964 bd!
965
966 ".........................................
967 " scp: NetWrite Method #4
968 elseif b:netrw_method == 4 " write with scp
969 if exists("g:netrw_port") && g:netrw_port != ""
970 let useport= " -P ".g:netrw_port
971 else
972 let useport= ""
973 endif
974 if g:netrw_cygwin == 1
975 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000976" call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000977 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
978 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000979" call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000980 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
981 endif
982 let b:netrw_lastfile = choice
983
984 ".........................................
985 " http: NetWrite Method #5
986 elseif b:netrw_method == 5
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000987 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000988 echohl Error | echo "***netrw*** currently <netrw.vim> does not support writing using http:" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000989 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000990 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000991
992 ".........................................
993 " dav: NetWrite Method #6
994 elseif b:netrw_method == 6 " write with cadaver
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000995" call Decho("write via cadaver (method #6)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000996
997 " Construct execution string (four lines) which will be passed through filter
998 let netrw_fname= b:netrw_fname
999 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001000 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001001 if exists("g:netrw_port") && g:netrw_port != ""
1002 put ='open '.g:netrw_machine.' '.g:netrw_port
1003 else
1004 put ='open '.g:netrw_machine
1005 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001007
1008 if g:netrw_cygwin == 1
1009 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
1010 put ='put '.cygtmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001012 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001014
1015 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001016 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001017" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001018 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
1019 bd!
1020 let b:netrw_lastfile = choice
1021
1022 ".........................................
1023 " rsync: NetWrite Method #7
1024 elseif b:netrw_method == 7 " write with rsync
1025 if g:netrw_cygwin == 1
1026 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001027" call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001028 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001030" call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001031 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001033 let b:netrw_lastfile = choice
1034
1035 ".........................................
1036 " scp: NetWrite Method #9
1037 elseif b:netrw_method == 9 " write with sftp
1038 let netrw_fname= b:netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1040 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1041 else
1042 let uid_machine = g:netrw_machine
1043 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001044 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001045 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001047 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001048" call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001049 exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine
1050 bd!
1051 let b:netrw_lastfile= choice
1052
1053 ".........................................
1054 else " Complain
1055 echo "***warning*** unable to comply with your request<" . choice . ">"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001057 endwhile
1058
1059 " cleanup
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001060" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001061 let result=delete(tmpfile)
1062 call s:NetOptionRestore()
1063
1064 if a:firstline == 1 && a:lastline == line("$")
1065 let &mod= mod " usually equivalent to set nomod
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001067
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001068" call Dret("NetWrite")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070
Bram Moolenaar83bab712005-08-01 21:58:57 +00001071" ===========================================
1072" Remote Directory Browsing Support: {{{1
1073" ===========================================
1074
Bram Moolenaar843ee412004-06-30 16:16:41 +00001075" NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001076" of the contents of a remote directory. It is assumed that the
1077" g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted
1078" with the requested remote hostname first.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001079fun! s:NetBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001080 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
1081" call Dfunc("NetBrowse(dirname<".a:dirname.">) longlist=".w:netrw_longlist)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001082
Bram Moolenaar488c6512005-08-11 20:09:58 +00001083 if exists("s:netrw_skipbrowse")
1084 unlet s:netrw_skipbrowse
1085" call Dret("NetBrowse")
1086 return
1087 endif
1088
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001089 call s:NetOptionSave()
1090
Bram Moolenaar843ee412004-06-30 16:16:41 +00001091 " sanity check
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001092 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
1093" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001094 if !executable("ftp")
1095 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001096 echohl Error | echo "***netrw*** this system doesn't support remote directory listing via ftp" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001097 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001098 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001099 call s:NetOptionRestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001100" call Dret("NetBrowse")
1101 return
1102 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001103 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001104 if !exists("g:netrw_quiet")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001105 echohl Error | echo "***netrw*** this system doesn't support remote directory listing via ".g:netrw_list_cmd | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001106 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001107 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001108
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001109 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001110" call Dret("NetBrowse")
1111 return
Bram Moolenaar843ee412004-06-30 16:16:41 +00001112 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001113
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001114 " use buffer-oriented WinVars if buffer ones exist but window ones don't
1115 call s:UseBufWinVars()
1116
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001117 " make this buffer modifiable
Bram Moolenaar83bab712005-08-01 21:58:57 +00001118 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001119
1120 " analyze a:dirname and g:netrw_list_cmd
1121 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001122 let dirname = substitute(a:dirname,'\\','/','ge')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001123" call Decho("dirname<".dirname.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001124 if dirname !~ dirpat
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001125 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001126 echohl Error | echo "***netrw*** netrw doesn't understand your dirname<".dirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001127 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001128 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001129 call s:NetOptionRestore()
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001130" call Dret("NetBrowse : badly formatted dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001131 return
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001132 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001133
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001134 let method = substitute(dirname,dirpat,'\1','')
1135 let user = substitute(dirname,dirpat,'\2','')
1136 let machine = substitute(dirname,dirpat,'\3','')
1137 let path = substitute(dirname,dirpat,'\4','')
1138 let fname = substitute(dirname,'^.*/\ze.','','')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001139" call Decho("set up method <".method .">")
1140" call Decho("set up user <".user .">")
1141" call Decho("set up machine<".machine.">")
1142" call Decho("set up path <".path .">")
1143" call Decho("set up fname <".fname .">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001144
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001145 if method == "ftp" || method == "http"
1146 let method = "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001147 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001148 else
1149 let listcmd = substitute(g:netrw_list_cmd,'\<HOSTNAME\>',user.machine,'')
1150 endif
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001151
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001152 if exists("b:netrw_method")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001153" call Decho("setting w:netrw_method<".b:netrw_method.">")
1154 let w:netrw_method= b:netrw_method
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001155 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001156
Bram Moolenaar8299df92004-07-10 09:47:34 +00001157 " optionally sort by time (-t) or by size (-S)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001158 if listcmd == "dir" && g:netrw_sort_by =~ "^[ts]"
Bram Moolenaar572cb562005-08-05 21:35:02 +00001159 echohl WarningMsg | echo "***netrw*** windows' ftp doesn't support time/size sorts (get cygwin, set g:netrw_cygwin)" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001160 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001161 else
1162 if g:netrw_sort_by =~ "^t"
1163 let listcmd= listcmd."t"
1164 elseif g:netrw_sort_by =~ "^s"
1165 let listcmd= listcmd."S"
1166 endif
1167 " optionally sort in reverse
1168 if g:netrw_sort_direction =~ "^r" && listcmd == "dir"
1169 let listcmd= listcmd."r"
1170 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001171 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001172
1173" call Decho("set up listcmd<".listcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001174 if fname =~ '@$' && fname !~ '^"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001175" call Decho("attempt transfer of symlink as file")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001176 call s:NetBrowse(substitute(dirname,'@$','','e'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001177 redraw!
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001178 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001179" call Dret("NetBrowse : symlink")
1180 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001181
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001182 elseif fname !~ '[\/]$' && fname !~ '^"'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001183 " looks like a regular file, attempt transfer
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001184" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001185
1186 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001187 " "this is a directory" indicator (/). There shouldn't be one of those,
1188 " anyway.
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001189 let path= substitute(path,'[*=@|]\r\=$','','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001190" call Decho("new path<".path.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001191
1192 " remote-read the requested file into current buffer
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001193 keepjumps keepalt enew!
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001194 set ma
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001195" call Decho("exe file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001196 exe "file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001197 exe "silent doau BufReadPre ".fname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001198 silent call netrw#NetRead(method."://".user.machine."/".path)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001199 exe "silent doau BufReadPost ".fname
Bram Moolenaar8299df92004-07-10 09:47:34 +00001200 keepjumps 1d
Bram Moolenaar572cb562005-08-05 21:35:02 +00001201
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001202 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001203 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001204 call s:NetOptionRestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001205 setlocal nomod
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001206
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001207" call Dret("NetBrowse : file<".fname.">")
1208 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001209 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001210
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001211 " ---------------------------------------------------------------------
1212 " Perform Directory Listing:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001213" call Decho("Perform directory listing...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001214 " set up new buffer and map
1215 let bufname = method.'://'.user.machine.'/'.path
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001216 let bufnamenr = bufnr(bufname.'$')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001217" call Decho("bufname<".bufname."> bufnamenr=".bufnamenr)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001218 if bufnamenr != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001219 " buffer already exists, switch to it!
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001220" call Decho("buffer already exists, switching to it")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001221 exe "b ".bufnamenr
1222 if line("$") >= 5
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001223 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001224" call Dret("NetBrowse")
1225 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001226 endif
1227 else
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001228" call Decho("generate a new buffer")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001229 keepjumps keepalt enew!
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001230 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001231
1232 " rename file to reflect where its from
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001233 setlocal bt=nofile bh=wipe nobl noswf
1234 exe "setlocal ts=".g:netrw_maxfilenamelen
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001235" call Decho("exe file ".escape(bufname,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001236 exe 'file '.escape(bufname,s:netrw_cd_escape)
Bram Moolenaar269ec652004-07-29 08:43:53 +00001237" call Decho("renaming file to bufname<".bufname.">")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001238 setlocal bh=hide bt=nofile nobl nonu
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001239
1240 " save current directory on directory history list
1241 call <SID>NetBookmarkDir(3,expand("%"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001242
1243 " set up buffer-local mappings
1244" call Decho("set up buffer-local mappings")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001245 nnoremap <buffer> <silent> <cr> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001246 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>NetBrowseChgDir(expand("%"),'./'),0)<cr>
Bram Moolenaar843ee412004-06-30 16:16:41 +00001247 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'../'))<cr>
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001248 nnoremap <buffer> <silent> a :let g:netrw_hide=(g:netrw_hide+1)%3<bar>exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'./'))<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001249 if w:netrw_longlist != 2
1250 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1251 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,expand("%"))<cr>
1252 endif
1253 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1254 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001255 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(0)<cr>
1256 nnoremap <buffer> <silent> i :call <SID>NetLongList(0)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001257 nnoremap <buffer> <silent> o :call <SID>NetSplit(0)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001258 nnoremap <buffer> <silent> O :call <SID>NetObtain()<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001259 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,expand("%"))<cr>
1260 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'./'))<cr>
1261 nnoremap <buffer> <silent> s :call <SID>NetSaveWordPosn()<bar>let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name'<bar>exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'./'))<bar>call <SID>NetRestoreWordPosn()<cr>
1262 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001263 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
1264 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001265 nnoremap <buffer> <silent> v :call <SID>NetSplit(1)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001266 nnoremap <buffer> <silent> x :call <SID>NetBrowseX(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()),1)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001267 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001268 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001269 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001270 exe 'nnoremap <buffer> <silent> d :call <SID>NetMakeDir("'.user.machine.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001271 exe 'nnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001272 exe 'vnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001273 exe 'nnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00001274 exe 'vnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar8299df92004-07-10 09:47:34 +00001275 nnoremap <buffer> ? :he netrw-browse-cmds<cr>
Bram Moolenaar83bab712005-08-01 21:58:57 +00001276 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001277
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001278 " Set up the banner
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001279" call Decho("set up the banner: sortby<".g:netrw_sort_by."> method<".method.">")
1280 keepjumps put ='\" ==========================================================================='
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001281 keepjumps put ='\" Netrw Remote Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001282 keepjumps put ='\" '.bufname
Bram Moolenaar488c6512005-08-11 20:09:58 +00001283 let w:netrw_bannercnt = 7
1284 let sortby = g:netrw_sort_by
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001285 if g:netrw_sort_direction =~ "^r"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001286 let sortby = sortby." reversed"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001287 endif
1288
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001289 if g:netrw_sort_by =~ "^n"
1290 " sorted by name
Bram Moolenaar488c6512005-08-11 20:09:58 +00001291 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001292 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001293 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
1294 else
1295 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001296 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001297 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001298 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001299" call Decho("g:netrw_hide=".g:netrw_hide)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001300 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001301 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001302 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001303 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001304 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00001305 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar843ee412004-06-30 16:16:41 +00001306 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001307 keepjumps put ='\" Quick Help: ?:help -:go up dir D:delete R:rename s:sort-by x:exec'
1308 keepjumps put ='\" ==========================================================================='
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001309
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001310 " remote read the requested directory listing
1311 " Use ftp if that was the file-transfer method selected, otherwise use ssh
1312 " Note that not all ftp servers honor the options for ls
1313 if method == "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001314 " use ftp to get remote file listing
1315" call Decho("use ftp to get remote file listing")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001316 call s:NetBrowseFtpCmd(path,listcmd)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001317 keepjumps 1d
1318
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001319 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001320 " shorten the listing
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001321" call Decho("generate short listing")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001322 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001323
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001324 " cleanup
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001325 if g:netrw_ftp_browse_reject != ""
1326 exe "silent! g/".g:netrw_ftp_browse_reject."/keepjumps d"
1327 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001328 silent! keepjumps %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001329
1330 " if there's no ../ listed, then put ./ and ../ in
1331 let line1= line(".")
1332 keepjumps 1
1333 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1334 let line2= line(".")
1335 if line2 == 0
1336 keepjumps put='../'
1337 keepjumps put='./'
1338 endif
1339 exe "keepjumps ".line1
1340 keepjumps norm! 0
1341
1342 " more cleanup
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001343 exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
1344 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
1345 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001346 endif
1347
1348 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001349 " use ssh to get remote file listing
1350" call Decho("use ssh to get remote file listing")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001351 let shq= &shq? &shq : ( &sxq? &sxq : "'")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001352" call Decho("exe silent r! ".listcmd." '".shq.escape(path,s:netrw_cd_escape).shq."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001353 exe "silent r! ".listcmd." ".shq.escape(path,s:netrw_cd_escape).shq
1354 keepjumps 1d
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001355 " cleanup
1356 if g:netrw_ftp_browse_reject != ""
1357 exe "silent! g/".g:netrw_ssh_browse_reject."/keepjumps d"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001358 endif
1359 endif
1360
1361 " set up syntax highlighting
1362 if has("syntax")
1363 setlocal ft=netrwlist
Bram Moolenaar572cb562005-08-05 21:35:02 +00001364 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001365 setlocal ft=
Bram Moolenaar572cb562005-08-05 21:35:02 +00001366 " Ugly workaround -- when syntax highlighting is off and laststatus==2,
1367 " sometimes the laststatus highlight bleeds into the entire display.
1368 " Only seems to happen with remote browsing. Weird.
1369 redraw
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001370 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001371 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001372
1373 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001374 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00001375 if g:netrw_hide && g:netrw_list_hide != ""
1376 call s:NetrwListHide()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001377 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001378
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001379 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00001380 " do a long listing; these substitutions need to be done prior to sorting
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001381" call Decho("manipulate long listing")
1382
1383 if method == "ftp"
1384 " cleanup
Bram Moolenaar488c6512005-08-11 20:09:58 +00001385 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar572cb562005-08-05 21:35:02 +00001386 while getline(".") =~ g:netrw_ftp_browse_reject
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001387 keepjumps d
1388 endwhile
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001389 " if there's no ../ listed, then put ./ and ../ in
1390 let line1= line(".")
1391 keepjumps 1
1392 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1393 let line2= line(".")
1394 if line2 == 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00001395 exe 'keepjumps '.w:netrw_bannercnt."put='./'"
1396 exe 'keepjumps '.w:netrw_bannercnt."put='../'"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001397 endif
1398 exe "keepjumps ".line1
1399 keepjumps norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001400 endif
1401
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001402 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/ -> .*$//e'
1403 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
1404 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar8299df92004-07-10 09:47:34 +00001405 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001406
Bram Moolenaar488c6512005-08-11 20:09:58 +00001407 if line("$") >= w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001408 if g:netrw_sort_by =~ "^n"
1409 call s:SetSort()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001410 if g:netrw_sort_direction =~ 'n'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001411 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001412 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001413 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
Bram Moolenaar83bab712005-08-01 21:58:57 +00001414 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001415 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001416 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001417 if w:netrw_longlist == 1
1418 " shorten the list to keep its width <= winwidth characters
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001419 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\t[-dstrwx]\+/\t/e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001420 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001421 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001422 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001423
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001424 call s:NetrwWideListing()
1425 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001426 " place cursor on the top-left corner of the file listing
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001427 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001428 norm! 0
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001429 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001430
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001431 call s:NetOptionRestore()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001432 setlocal nomod noma nonu
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001433
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001434" call Dret("NetBrowse")
1435 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001436endfun
1437
1438" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001439" NetBrowseChgDir: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001440fun! s:NetBrowseChgDir(dirname,newdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001441" call Dfunc("NetBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001442
1443 let dirname= a:dirname
Bram Moolenaar843ee412004-06-30 16:16:41 +00001444 let newdir = a:newdir
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001445
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001446 if newdir !~ '[\/]$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001447 " handling a file
1448 let dirname= dirname.newdir
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001449" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001450
1451 elseif newdir == './'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001452 " refresh the directory list
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001453" call Decho("refresh directory listing")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001454 setlocal ma nobl bh=hide
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001455 %d
1456
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001457 elseif newdir == '../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001458 " go up one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001459 let trailer= substitute(a:dirname,'^\(\w\+://\%(\w\+@\)\=\w\+/\)\(.*\)$','\2','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001460
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001461 if trailer =~ '^\%(\.\./\)*$'
1462 " tack on a ../"
1463 let dirname= dirname.'../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001464
1465 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001466 " strip off a directory name from dirname
1467 let dirname= substitute(dirname,'^\(.*/\)[^/]\+/','\1','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001468 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001469" call Decho("go up one dir: dirname<".dirname."> trailer<".trailer.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001470
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001471 else
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001472 " go down one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001473 let dirname= dirname.newdir
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001474" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001475 endif
1476
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001477" call Dret("NetBrowseChgDir <".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001478 return dirname
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001479endfun
1480
Bram Moolenaar843ee412004-06-30 16:16:41 +00001481" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001482" NetGetWord: it gets the directory named under the cursor
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001483fun! s:NetGetWord()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001484" call Dfunc("NetGetWord() line#".line("."))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001485 call s:UseBufWinVars()
1486
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001487 " insure that w:netrw_longlist is set up
1488 if !exists("w:netrw_longlist")
1489 if exists("g:netrw_longlist")
1490 let w:netrw_longlist= g:netrw_longlist
1491 else
1492 let w:netrw_longlist= 0
1493 endif
1494 endif
1495
Bram Moolenaar488c6512005-08-11 20:09:58 +00001496 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001497 " Active Banner support
1498" call Decho("active banner handling")
1499 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001500 let dirname= "./"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001501 let curline= getline(".")
1502 if curline =~ '"\s*Sorted by\s'
1503 norm s
1504 let s:netrw_skipbrowse= 1
1505 echo 'Pressing "s" also works'
1506 elseif curline =~ '"\s*Sort sequence:'
1507 let s:netrw_skipbrowse= 1
1508 echo 'Press "S" to edit sorting sequence'
1509 elseif curline =~ '"\s*Quick Help:'
1510 norm ?
1511 let s:netrw_skipbrowse= 1
1512 echo 'Pressing "?" also works'
1513 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
1514 norm a
1515 let s:netrw_skipbrowse= 1
1516 echo 'Pressing "a" also works'
1517 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001518 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00001519 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001520
1521 elseif w:netrw_longlist == 0
1522" call Decho("thin column handling")
1523 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001524 let dirname= getline(".")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001525
1526 elseif w:netrw_longlist == 1
1527" call Decho("long column handling")
1528 norm! 0
1529 let dirname= substitute(getline("."),'^\(\%(\S\+\s\)*\S\+\).\{-}$','\1','e')
1530
1531 else
1532" call Decho("obtain word from wide listing")
1533 let dirname= getline(".")
1534
1535 if !exists("b:netrw_cpf")
1536 let b:netrw_cpf= 0
1537 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
1538" call Decho("computed cpf")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001539 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001540
1541 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
1542" call Decho("virtcol=".virtcol(".")." cpf=".b:netrw_cpf." bannercnt=".w:netrw_bannercnt." filestart=".filestart)
1543" call Decho("1: dirname<".dirname.">")
1544 if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif
1545" call Decho("2: dirname<".dirname.">")
1546 let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e')
1547" call Decho("3: dirname<".dirname.">")
1548 let dirname = substitute(dirname,'\s\+$','','e')
1549" call Decho("4: dirname<".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001550 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001551
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001552" call Dret("NetGetWord <".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001553 return dirname
1554endfun
1555
1556" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001557" NetBrowseRm: remove/delete a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001558fun! s:NetBrowseRm(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001559" call Dfunc("NetBrowseRm(usrhost<".a:usrhost."> path<".a:path.">)")
1560" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001561
1562 " preparation for removing multiple files/directories
1563 let ctr= a:firstline
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001564 let all= 0
Bram Moolenaar843ee412004-06-30 16:16:41 +00001565
1566 " remove multiple files and directories
1567 while ctr <= a:lastline
1568 exe ctr
1569
1570 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001571 let rmfile= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001572" call Decho("rmfile<".rmfile.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001573
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001574 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar843ee412004-06-30 16:16:41 +00001575 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001576 if !all
1577 echohl Statement
1578 call inputsave()
1579 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1580 call inputrestore()
1581 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001582 if ok == ""
1583 let ok="no"
1584 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001585 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1586 if ok =~ 'a\%[ll]'
1587 let all= 1
1588 endif
1589 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001590
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001591 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001592 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001593 silent! keepjumps .,$d
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001594 call s:NetBrowseFtpCmd(a:path,"delete ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001595 else
1596 let netrw_rm_cmd= substitute(g:netrw_rm_cmd,'HOSTNAME',a:usrhost,'').' "'.escape(a:path.rmfile,s:netrw_cd_escape).'"'
1597" call Decho("attempt to remove file: system(".netrw_rm_cmd.")")
1598 let ret= system(netrw_rm_cmd)
1599" call Decho("returned=".ret." errcode=".v:shell_error)
1600 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001601 elseif ok =~ 'q\%[uit]'
1602 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001603 endif
1604
1605 else
1606 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001607 if !all
1608 call inputsave()
1609 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1610 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001611 if ok == ""
1612 let ok="no"
1613 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001614 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1615 if ok =~ 'a\%[ll]'
1616 let all= 1
1617 endif
1618 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001619
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001620 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001621 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001622 call s:NetBrowseFtpCmd(a:path,"rmdir ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001623 else
1624 let rmfile = a:path.rmfile
1625 let netrw_rmdir_cmd= substitute(g:netrw_rmdir_cmd,'HOSTNAME',a:usrhost,'').' '."'".'"'.rmfile.'"'."'"
1626" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
1627 let ret= system(netrw_rmdir_cmd)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001628" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001629
1630 if v:shell_error != 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001631 let netrw_rmf_cmd= substitute(g:netrw_rmf_cmd,'HOSTNAME',a:usrhost,'').' '.substitute(rmfile,'[\/]$','','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001632" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
1633 let ret= system(netrw_rmf_cmd)
1634" call Decho("returned=".ret." errcode=".v:shell_error)
1635
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001636 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001637 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001638 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001639 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001640 endif
1641 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001642
1643 elseif ok =~ 'q\%[uit]'
1644 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001645 endif
1646 endif
1647
1648 let ctr= ctr + 1
1649 endwhile
1650
1651 " refresh the directory
1652 let curline= line(".")-1
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001653" call Decho("refresh the directory")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001654 call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'./'))
1655 exe curline
1656
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001657" call Dret("NetBrowseRm")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001658endfun
1659
1660" ---------------------------------------------------------------------
1661" NetBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001662fun! s:NetBrowseRename(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001663" call Dfunc("NetBrowseRename(usrhost<".a:usrhost."> path<".a:path.">)")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001664
1665 " preparation for removing multiple files/directories
1666 let ctr = a:firstline
1667 let rename_cmd = substitute(g:netrw_rename_cmd,'\<HOSTNAME\>',a:usrhost,'')
1668
1669 " attempt to rename files/directories
1670 while ctr <= a:lastline
Bram Moolenaar8299df92004-07-10 09:47:34 +00001671 exe "keepjumps ".ctr
Bram Moolenaar843ee412004-06-30 16:16:41 +00001672
1673 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001674 let oldname= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001675" call Decho("oldname<".oldname.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001676
1677 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001678 let newname= input("Moving ".oldname." to : ",oldname)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001679 call inputrestore()
1680
Bram Moolenaar488c6512005-08-11 20:09:58 +00001681 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001682 call s:NetBrowseFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001683 else
1684 let oldname= a:path.oldname
1685 let newname= a:path.newname
1686" call Decho("system(rename_cmd".' "'.escape(oldname," ").'" "'.escape(newname,s:netrw_cd_escape).'"')
1687 let ret= system(rename_cmd.' "'.escape(oldname,s:netrw_cd_escape).'" "'.escape(newname,s:netrw_cd_escape).'"')
1688 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001689
1690 let ctr= ctr + 1
1691 endwhile
1692
1693 " refresh the directory
1694 let curline= line(".")
1695 call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001696 exe "keepjumps ".curline
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001697" call Dret("NetBrowseRename")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001698endfun
1699
1700" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00001701" NetRefresh: {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001702fun! s:NetRefresh(dirname,islocal)
1703" call Dfunc("NetRefresh(dirname<".a:dirname.">,islocal=".a:islocal.")")
1704 call netrw#NetSavePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001705 set ma
1706 %d
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001707 if a:islocal
1708 call s:LocalBrowse(a:dirname)
1709 else
1710 call s:NetBrowse(a:dirname)
1711 endif
1712 call netrw#NetRestorePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001713 redraw!
1714" call Dret("NetRefresh")
1715endfun
1716
1717" ---------------------------------------------------------------------
Bram Moolenaar488c6512005-08-11 20:09:58 +00001718" NetSplit: mode {{{2
1719" =0 : net and o
1720" =1 : net and v
1721" =2 : local and o
1722" =3 : local and v
1723fun! s:NetSplit(mode)
1724" call Dfunc("NetSplit(mode=".a:mode.")")
1725
1726 call s:SaveWinVars()
1727 if a:mode == 0
1728 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1729 call s:CopyWinVars()
1730 exe "norm! 0"
1731 call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))
1732 elseif a:mode ==1
1733 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1734 call s:CopyWinVars()
1735 exe "norm! 0"
1736 call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))
1737 elseif a:mode ==2
1738 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1739 call s:CopyWinVars()
1740 exe "norm! 0"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001741 call s:LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001742 else
1743 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1744 call s:CopyWinVars()
1745 exe "norm! 0"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001746 call s:LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001747 endif
1748
1749" call Dret("NetSplit")
1750endfun
1751
1752" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001753" NetBrowseX: allows users to write custom functions to operate on {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00001754" files given their extension. Passes 0=local, 1=remote
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001755fun! s:NetBrowseX(fname,remote)
Bram Moolenaar8299df92004-07-10 09:47:34 +00001756" call Dfunc("NetBrowseX(".a:fname." remote=".a:remote.")")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001757
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001758 " set up the filename
1759 " (lower case the extension, make a local copy of a remote file)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001760 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001761 if has("win32") || has("win95") || has("win64") || has("win16")
1762 let exten= substitute(exten,'^.*$','\L&\E','')
1763 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001764 let fname= escape(a:fname,"%#")
1765" call Decho("fname<".fname."> after escape()")
1766
1767 if a:remote == 1
1768 " create a local copy
1769 let fname= tempname().".".exten
1770" call Decho("create a local copy of <".a:fname."> as <".fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001771 exe "silent keepjumps bot 1new ".a:fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001772 set bh=delete
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001773 exe "w! ".fname
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001774 q
1775 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001776" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001777
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001778 " set up redirection
1779 if &srr =~ "%s"
1780 let redir= substitute(&srr,"%s","/dev/null"."")
1781 else
1782 let redir= &srr . "/dev/null"
1783 endif
1784" call Decho("redir:".redir.":")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001785
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001786 " execute the file handler
1787 if has("win32") || has("win64")
1788" call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"')
1789 exe 'silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"'
1790 let ret= v:shell_error
1791
Bram Moolenaara5792f52005-11-23 21:25:05 +00001792 elseif has("unix") && executable("gnome-open")
1793" call Decho("exe silent !gnome-open '".escape(fname,'%#')."' ".redir)
1794 exe "silent !gnome-open '".escape(fname,'%#')."'".redir
1795 let ret= v:shell_error
1796
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001797 elseif has("unix") && executable("kfmclient")
1798" call Decho("exe silent !kfmclient exec '".escape(fname,'%#')."' ".redir)
1799 exe "silent !kfmclient exec '".escape(fname,'%#')."' ".redir
1800 let ret= v:shell_error
1801
1802 else
1803 call netrwFileHandlers#Init()
1804 if exten != "" && exists("*netrwFileHandlers#NFH_".exten)
1805" call Decho("let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")')
1806 exe "let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")'
1807 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001808 endif
1809 redraw!
Bram Moolenaar8299df92004-07-10 09:47:34 +00001810
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001811 " cleanup: remove temporary file,
1812 " delete current buffer if success with handler,
1813 " return to prior buffer (directory listing)
1814 if a:remote == 1 && fname != a:fname
1815" call Decho("deleting temporary file<".fname.">")
1816 call delete(fname)
1817 endif
1818
1819 if a:remote == 1
Bram Moolenaar572cb562005-08-05 21:35:02 +00001820 set bh=delete bt=nofile noswf
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001821 exe "norm! \<c-o>"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001822 redraw!
Bram Moolenaar843ee412004-06-30 16:16:41 +00001823 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001824
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001825" call Dret("NetBrowseX")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001826endfun
1827
1828" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001829" NetBrowseFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
1830" This function assumes that a long listing will be received. Size, time,
1831" and reverse sorts will be requested of the server but not otherwise
1832" enforced here.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001833fun! s:NetBrowseFtpCmd(path,cmd)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001834" call Dfunc("NetBrowseFtpCmd(path<".a:path."> cmd<".a:cmd.">) netrw_method=".w:netrw_method)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001835
1836 " because WinXX ftp uses unix style input
1837 " curline is one more than the bannercnt in order to account
1838 " for the unwanted first blank line (doing a :put to an empty
1839 " buffer yields a blank first line)
1840 let ffkeep= &ff
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001841 setlocal ma ff=unix
Bram Moolenaar488c6512005-08-11 20:09:58 +00001842 let curline= w:netrw_bannercnt+1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001843 exe "silent! keepjumps ".curline.",$d"
1844
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001845 ".........................................
1846 if w:netrw_method == 2 || w:netrw_method == 5
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001847 " ftp + <.netrc>: Method #2
1848 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001849 put ='cd \"'.a:path.'\"'
1850" call Decho('ftp: '.getline("."))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001851 endif
1852 exe "put ='".a:cmd."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001853" call Decho("ftp: ".getline("."))
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001854" redraw!|call inputsave()|call input("Pausing...")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001855 if exists("g:netrw_port") && g:netrw_port != ""
1856" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
1857 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
1858 else
1859" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
1860 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
1861 endif
1862
1863 ".........................................
Bram Moolenaar488c6512005-08-11 20:09:58 +00001864 elseif w:netrw_method == 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001865 " ftp + machine,id,passwd,filename: Method #3
1866 setlocal ff=unix
1867 if exists("g:netrw_port") && g:netrw_port != ""
1868 put ='open '.g:netrw_machine.' '.g:netrw_port
1869 else
1870 put ='open '.g:netrw_machine
1871 endif
1872
1873 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1874 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001875 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001876 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001877 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001878 endif
1879
1880 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001881 put ='cd \"'.a:path.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001882 endif
1883 exe "put ='".a:cmd."'"
1884
1885 " perform ftp:
1886 " -i : turns off interactive prompting from ftp
1887 " -n unix : DON'T use <.netrc>, even though it exists
1888 " -n win32: quit being obnoxious about password
1889" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
1890 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n"
1891
1892 ".........................................
1893 else
1894 echo "***warning*** unable to comply with your request<" . choice . ">"
1895 endif
1896
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001897 " cleanup for Windows
1898 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001899 silent! keepjumps! %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001900 endif
1901 if a:cmd == "dir"
1902 " infer directory/link based on the file permission string
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001903 silent! keepjumps g/d\%([-r][-w][-x]\)\{3}/s@$@/@
1904 silent! keepjumps g/l\%([-r][-w][-x]\)\{3}/s/$/@/
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001905 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001906 exe "silent! keepjumps ".curline.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001907 endif
1908 endif
1909
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001910 " ftp's ls doesn't seem to include ./ or ../
1911 if !search('^\.\/$','wn')
1912 exe 'keepjumps '.curline
1913 if a:path !~ '^$'
1914 put ='../'
1915 endif
1916 put ='./'
1917 exe 'keepjumps '.curline
1918 endif
1919
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001920 " restore settings
1921 let &ff= ffkeep
1922" call Dret("NetBrowseFtpCmd")
1923endfun
1924
1925" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001926" NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
1927" separated patterns given in g:netrw_list_hide
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001928fun! s:NetrwListHide()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001929" call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001930
1931 let listhide= g:netrw_list_hide
1932 while listhide != ""
1933 if listhide =~ ','
1934 let hide = substitute(listhide,',.*$','','e')
1935 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
1936 else
1937 let hide = listhide
1938 let listhide= ""
1939 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001940
1941 " Prune the list by hiding any files which match
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001942 if g:netrw_hide == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001943" call Decho("hiding<".hide."> listhide<".listhide.">")
1944" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d')
1945 exe 'silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001946 elseif g:netrw_hide == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001947" call Decho("showing<".hide."> listhide<".listhide.">")
1948" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d')
1949 exe 'silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001950 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001951 endwhile
1952
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001953" call Dret("NetrwListHide")
1954endfun
1955
1956" ---------------------------------------------------------------------
1957" NetHideEdit: allows user to edit the file/directory hiding list
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001958fun! s:NetHideEdit(islocal)
1959" call Dfunc("NetHideEdit(islocal=".a:islocal.")")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001960
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001961 " get new hiding list from user
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001962 call inputsave()
1963 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
1964 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001965 let g:netrw_list_hide= newhide
1966" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001967
1968 " refresh the listing
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001969 if a:islocal == 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00001970 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
1971 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001972 silent call s:NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,"./"),a:islocal)
Bram Moolenaar8299df92004-07-10 09:47:34 +00001973 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001974
1975" call Dret("NetHideEdit")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001976endfun
1977
Bram Moolenaar8299df92004-07-10 09:47:34 +00001978" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001979" NetSortSequence: allows user to edit the sorting sequence
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001980fun! s:NetSortSequence(mode)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001981" call Dfunc("NetSortSequence(mode=".a:mode.")")
1982
1983 call inputsave()
1984 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
1985 call inputrestore()
1986
1987 " refresh the listing
1988 let g:netrw_sort_sequence= newsortseq
1989 if a:mode == 0
1990 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
1991 else
1992 silent call s:LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,"./"))
1993 endif
1994
1995" call Dret("NetSortSequence")
1996endfun
1997
1998" ---------------------------------------------------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00001999" NetLongList: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002000fun! s:NetLongList(mode)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002001" call Dfunc("NetLongList(mode=".a:mode.") netrw_longlist=".w:netrw_longlist)
2002 let fname = s:NetGetWord()
2003 let w:netrw_longlist = (w:netrw_longlist + 1) % 3
2004" call Decho("fname<".fname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002005
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002006 if w:netrw_longlist == 0
2007 " use one column listing
2008" call Decho("use one column list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002009 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2010
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002011 elseif w:netrw_longlist == 1
2012 " use long list
2013" call Decho("use long list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002014 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002015
2016 else
2017 " give wide list
2018" call Decho("use wide list")
2019 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002020 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002021 setlocal ma
Bram Moolenaar572cb562005-08-05 21:35:02 +00002022
2023 " clear buffer - this will cause NetBrowse/LocalBrowse to do a refresh
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002024 %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002025
2026 " refresh the listing
2027 if a:mode == 0
2028 silent call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),"./"))
2029 else
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002030 silent call s:LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002031 endif
2032
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002033 " keep cursor on the filename
2034 silent keepjumps $
2035 if fname =~ '/$'
2036 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2037 else
2038 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2039 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002040
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002041" call Dret("NetLongList : w:netrw_longlist=".w:netrw_longlist)
2042endfun
2043
2044" ---------------------------------------------------------------------
2045" NetrwWideListing: {{{2
2046fun! s:NetrwWideListing()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002047" call Dfunc("NetrwWideListing() w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002048
2049 if w:netrw_longlist == 2
2050 " look for longest filename (cpf=characters per filename)
2051 " cpf: characters per file
2052 " fpl: files per line
2053 " fpc: files per column
2054 set ma
2055 let b:netrw_cpf= 0
2056 if line("$") >= w:netrw_bannercnt
2057 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
2058 else
2059" call Dret("NetrwWideListing")
2060 return
2061 endif
2062" call Decho("max file strlen+1=".b:netrw_cpf)
2063 let b:netrw_cpf= b:netrw_cpf + 1
2064
2065 " determine qty files per line (fpl)
2066 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
2067" call Decho("fpl= ".winwidth(0)."/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
2068
2069 " make wide display
2070 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^.*$/\=printf("%-'.b:netrw_cpf.'s",submatch(0))/'
2071 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
2072 let newcolstart = w:netrw_bannercnt + fpc
2073 let newcolend = newcolstart + fpc - 1
2074" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
2075 while line("$") >= newcolstart
2076 if newcolend > line("$") | let newcolend= line("$") | endif
2077 let newcolqty= newcolend - newcolstart
2078 exe newcolstart
2079 if newcolqty == 0
2080 exe "silent keepjumps norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
2081 else
2082 exe "silent keepjumps norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
2083 endif
2084 exe "silent keepjumps ".newcolstart.','.newcolend.'d'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002085 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002086 endwhile
2087 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002088 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002089 endif
2090
2091" call Dret("NetrwWideListing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002092endfun
2093
2094" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002095" NetSaveWordPosn: used by the "s" command in both remote and local {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002096" browsing. Along with NetRestoreWordPosn(), it keeps the cursor on
2097" the same word even though the sorting has changed its order of appearance.
2098fun! s:NetSaveWordPosn()
2099" call Dfunc("NetSaveWordPosn()")
2100 let s:netrw_saveword= '^'.escape(getline("."),s:netrw_cd_escape).'$'
2101" call Dret("NetSaveWordPosn : saveword<".s:netrw_saveword.">")
2102endfun
2103
2104" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002105" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002106fun! s:NetRestoreWordPosn()
2107" call Dfunc("NetRestoreWordPosn()")
2108 silent! call search(s:netrw_saveword,'w')
2109" call Dret("NetRestoreWordPosn")
2110endfun
2111
2112" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002113" NetMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002114fun! s:NetMakeDir(usrhost)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002115" call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)")
2116
2117 " get name of new directory from user. A bare <CR> will skip.
2118 " if its currently a directory, also request will be skipped, but with
2119 " a message.
2120 call inputsave()
2121 let newdirname= input("Please give directory name: ")
2122 call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002123" call Decho("newdirname<".newdirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002124
2125 if newdirname == ""
2126" call Dret("NetMakeDir : user aborted with bare <cr>")
2127 return
2128 endif
2129
2130 if a:usrhost == ""
2131
2132 " Local mkdir:
2133 " sanity checks
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002134 let fullnewdir= b:netrw_curdir.'/'.newdirname
2135" call Decho("fullnewdir<".fullnewdir.">")
2136 if isdirectory(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002137 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002138 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a directory!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002139 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002140 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002141" call Dret("NetMakeDir : directory<".newdirname."> exists previously")
2142 return
2143 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002144 if filereadable(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002145 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002146 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a file!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002147 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002148 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002149" call Dret("NetMakeDir : file<".newdirname."> exists previously")
2150 return
2151 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002152
2153 " requested new local directory is neither a pre-existing file or
2154 " directory, so make it!
2155 if exists("*mkdir")
2156 call mkdir(fullnewdir,"p")
2157 else
2158 let netrw_origdir= s:NetGetcwd(1)
2159 exe 'cd '.b:netrw_curdir
2160" call Decho("netrw_origdir<".netrw_origdir."> b:netrw_curdir<".b:netrw_curdir.">")
2161" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.newdirname.'"')
2162 exe "silent! !".g:netrw_local_mkdir.' "'.newdirname.'"'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002163 if !g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002164 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002165
Bram Moolenaar8299df92004-07-10 09:47:34 +00002166 if v:shell_error == 0
2167 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002168" call Decho("refresh listing")
2169 let linenum= line(".")
2170 norm! H0
2171 let hline = line(".")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002172 set ma|norm! 2D
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002173 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,'./'))
2174 exe "norm! ".hline."G0z\<CR>"
2175 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002176 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002177 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002178 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002179 endif
2180 redraw!
2181
2182 else
2183 " Remote mkdir:
2184 let mkdircmd = substitute(g:netrw_mkdir_cmd,'\<HOSTNAME\>',a:usrhost,'')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002185 let newdirname= "'".'"'.substitute(expand("%"),'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname.'"'."'"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002186" call Decho("exe silent! !".mkdircmd." ".newdirname)
2187 exe "silent! !".mkdircmd." ".newdirname
2188 if v:shell_error == 0
2189 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002190 let linenum= line(".")
2191 norm! H0
2192 let hline = line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002193 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002194 exe "norm! ".hline."G0z\<CR>"
2195 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002196 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002197 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002198 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002199 endif
2200 redraw!
2201 endif
2202
2203" call Dret("NetMakeDir")
2204endfun
2205
2206" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002207" NetBookmarkDir: {{{2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002208" 0: (user: <b>) bookmark current directory
2209" 1: (user: <B>) change to the bookmarked directory
2210" 2: (user: <q>) list bookmarks
2211" 3: (LocalBrowse) record current directory history
2212" 4: (user: <u>) go up (previous) bookmark
2213" 5: (user: <U>) go down (next) bookmark
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002214fun! s:NetBookmarkDir(chg,curdir)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002215" call Dfunc("NetBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002216 if exists("w:netrw_bannercnt") && line(".") <= w:netrw_bannercnt
2217 " looks like a "b" was pressed while in the banner region
2218 if line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002219 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00002220 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002221 if &ch > 1
2222 " "clear" the message
2223 echo ""
2224 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002225" call Dret("NetBookmarkDir - ignoring")
2226 return
2227 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002228
2229 if a:chg == 0
2230 " bookmark the current directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002231 let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir
2232 if !exists("g:NETRW_BOOKMARKMAX")
2233 let g:NETRW_BOOKMARKMAX= v:count
2234 elseif v:count > g:NETRW_BOOKMARKMAX
2235 let g:NETRW_BOOKMARKMAX= v:count
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002236 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002237 echo "bookmarked the current directory"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002238
2239 elseif a:chg == 1
2240 " change to the bookmarked directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002241 if exists("g:NETRW_BOOKMARKDIR_{v:count}")
2242 exe "e ".g:NETRW_BOOKMARKDIR_{v:count}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002243 else
2244 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2245 endif
2246
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002247 elseif a:chg == 2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002248 " list user's bookmarks
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002249 if exists("g:NETRW_BOOKMARKMAX")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002250" call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]")
2251 let cnt= 0
2252 while cnt <= g:NETRW_BOOKMARKMAX
2253 if exists("g:NETRW_BOOKMARKDIR_{cnt}")
2254" call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt})
2255 echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}
2256 endif
2257 let cnt= cnt + 1
2258 endwhile
2259 endif
2260
2261 " list directory history
2262 let cnt = g:NETRW_DIRHIST_CNT
2263 let first = 1
2264 let histcnt = 0
2265 while ( first || cnt != g:NETRW_DIRHIST_CNT )
2266" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT)
2267 let histcnt= histcnt + 1
2268 if exists("g:NETRW_DIRHIST_{cnt}")
2269" call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt})
2270 echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002271 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002272 let first = 0
2273 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2274 if cnt < 0
2275 let cnt= cnt + g:netrw_dirhistmax
2276 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002277 endwhile
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002278
2279 elseif a:chg == 3
Bram Moolenaar572cb562005-08-05 21:35:02 +00002280 " saves most recently visited directories (when they differ)
2281 if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir
2282 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2283 let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e')
2284" call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2285 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002286
2287 elseif a:chg == 4
2288 " u: change to the previous directory stored on the history list
2289 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2290 if g:NETRW_DIRHIST_CNT < 0
2291 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2292 endif
2293 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2294" call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2295 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2296 else
2297 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2298 echo "Sorry, no predecessor directory exists yet"
2299 endif
2300
2301 elseif a:chg == 5
2302 " U: change to the subsequent directory stored on the history list
2303 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2304 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2305" call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2306 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2307 else
2308 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2309 if g:NETRW_DIRHIST_CNT < 0
2310 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2311 endif
2312 echo "Sorry, no successor directory exists yet"
2313 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002314 endif
2315" call Dret("NetBookmarkDir")
2316endfun
2317
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002318" ---------------------------------------------------------------------
2319" NetObtain: obtain file under cursor (for remote browsing support) {{{2
2320fun! s:NetObtain()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002321 let fname= expand("<cWORD>")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002322
2323 " NetrwStatusLine support - for obtaining support
2324 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.fname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002325
2326" call Dfunc("NetObtain() method=".w:netrw_method)
2327 if exists("w:netrw_method") && w:netrw_method =~ '[235]'
2328 if executable("ftp")
2329 let curdir = expand("%")
2330 let path = substitute(curdir,'ftp://[^/]\+/','','e')
2331 let curline= line(".")
2332 let endline= line("$")+1
2333 set ma
2334 keepjumps $
2335
2336 ".........................................
2337 if w:netrw_method == 2
2338 " ftp + <.netrc>: Method #2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002339 setlocal ff=unix
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002340 if path != ""
2341 put ='cd '.path
2342" call Decho("ftp: cd ".path)
2343 endif
2344 put ='get '.fname
2345" call Decho("ftp: get ".fname)
2346 if exists("g:netrw_port") && g:netrw_port != ""
2347" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
2348 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
2349 else
2350" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
2351 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
2352 endif
2353
2354 ".........................................
2355 elseif w:netrw_method == 3
2356 " ftp + machine,id,passwd,filename: Method #3
2357 setlocal ff=unix
2358 if exists("g:netrw_port") && g:netrw_port != ""
2359 put ='open '.g:netrw_machine.' '.g:netrw_port
2360" call Decho('ftp: open '.g:netrw_machine.' '.g:netrw_port)
2361 else
2362 put ='open '.g:netrw_machine
2363" call Decho('ftp: open '.g:netrw_machine
2364 endif
2365
2366 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2367 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002368 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002369" call Decho('ftp: g:netrw_uid')
2370" call Decho('ftp: g:netrw_passwd')
2371 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002372 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002373" call Decho('user '.g:netrw_uid.' '.g:netrw_passwd)
2374 endif
2375
2376 if a:path != ""
2377 put ='cd '.a:path
2378" call Decho('cd '.a:path)
2379 endif
2380 exe "put ='".a:cmd."'"
2381" call Decho("ftp: ".a:cmd)
2382
2383 " perform ftp:
2384 " -i : turns off interactive prompting from ftp
2385 " -n unix : DON'T use <.netrc>, even though it exists
2386 " -n win32: quit being obnoxious about password
2387" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
2388 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i -n"
2389
2390 ".........................................
2391 else
2392 echo "***warning*** unable to comply with your request<" . choice . ">"
2393 endif
2394 " restore
2395 exe "silent! ".endline.",$d"
2396 exe "keepjumps ".curline
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002397 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002398 else
2399 if !exists("g:netrw_quiet")
2400 echohl Error | echo "***netrw*** this system doesn't support ftp" | echohl None
2401 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2402 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002403 let &stl = s:netrw_users_stl
2404 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002405" call Dret("NetObtain")
2406 return
2407 endif
2408
2409 ".........................................
2410 else
2411 " scp: Method#4
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002412 let curdir = expand("%")
2413 let path = substitute(curdir,'scp://[^/]\+/','','e')
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002414 if exists("g:netrw_port") && g:netrw_port != ""
2415 let useport= " -P ".g:netrw_port
2416 else
2417 let useport= ""
2418 endif
2419 if g:netrw_cygwin == 1
2420 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002421" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2422 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002423 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002424" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2425 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002426 endif
2427 endif
2428
2429 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002430 let &stl = s:netrw_users_stl
2431 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002432 redraw!
2433
2434" call Dret("NetObtain")
2435endfun
2436
Bram Moolenaar83bab712005-08-01 21:58:57 +00002437" ==========================================
2438" Local Directory Browsing Support: {{{1
2439" ==========================================
Bram Moolenaar8299df92004-07-10 09:47:34 +00002440
2441" ---------------------------------------------------------------------
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002442" LocalBrowse: {{{2
2443fun! s:LocalBrowse(dirname)
2444 " unfortunate interaction -- debugging calls can't be used here;
2445 " the BufEnter event causes triggering when attempts to write to
2446 " the DBG buffer are made.
2447 if isdirectory(a:dirname)
2448 call netrw#DirBrowse(a:dirname)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002449 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002450 " not a directory, ignore it
2451endfun
Bram Moolenaar8299df92004-07-10 09:47:34 +00002452
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002453" ---------------------------------------------------------------------
2454" DirBrowse: supports local file/directory browsing {{{2
2455fun! netrw#DirBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002456 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002457" call Dfunc("DirBrowse(dirname<".a:dirname.">) buf#".bufnr("%")." winnr=".winnr()." sortby=".g:netrw_sort_by)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002458" call Dredir("ls!")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002459
Bram Moolenaar488c6512005-08-11 20:09:58 +00002460 if exists("s:netrw_skipbrowse")
2461 unlet s:netrw_skipbrowse
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002462" call Dret("DirBrowse")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002463 return
2464 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002465 call s:NetOptionSave()
Bram Moolenaar488c6512005-08-11 20:09:58 +00002466
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002467 if v:version < 603
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002468 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002469 echohl Error | echo "***netrw*** vim version<".v:version."> too old for browsing with netrw" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002470 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002471 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002472 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002473" call Dret("DirBrowse : vim version<".v:version."> too old")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002474 return
2475 endif
2476
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002477 " use buffer-oriented WinVars if buffer ones exist but window ones don't
2478 call s:UseBufWinVars()
2479
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002480 " find buffer number of buffer named precisely the same as a:dirname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002481 let bufnum= bufnr(escape(a:dirname,'\'))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002482" call Decho("findbuf: bufnum=".bufnum)
2483 if bufnum > 0 && bufname(bufnum) != a:dirname
2484 let ibuf= 1
2485 let buflast= bufnr("$")
2486 while bufname(ibuf) !~ '^'.a:dirname.'\=$' && ibuf <= buflast
2487" call Decho("findbuf: ibuf=".ibuf. " bufname<".bufname(ibuf)."> dirname<".a:dirname.">")
2488 let ibuf= ibuf + 1
2489 endwhile
2490 if ibuf > buflast
2491 let bufnum= -1
2492 else
2493 let bufnum= ibuf
2494 endif
2495" call Decho("findbuf: bufnum=".bufnum." (final)")
2496 endif
2497
2498 " get cleared buffer
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002499 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002500 keepjumps keepalt enew!
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002501" call Decho("enew buffer")
2502 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002503 exe "keepalt b ".bufnum
Bram Moolenaar572cb562005-08-05 21:35:02 +00002504 if exists("s:last_sort_by") && g:netrw_sort_by == s:last_sort_by
2505 if getline(2) =~ '^" Directory Listing '
2506 if !g:netrw_keepdir
2507" call Decho("change directory: cd ".b:netrw_curdir)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002508 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar572cb562005-08-05 21:35:02 +00002509 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002510 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002511" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002512 return
2513 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002514 endif
2515 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00002516 let s:last_sort_by= g:netrw_sort_by
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002517
2518 " get the new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002519 if has("win32") || has("win95") || has("win64") || has("win16")
2520 let b:netrw_curdir= substitute(a:dirname,'\\','/','ge')
2521 else
2522 let b:netrw_curdir= a:dirname
2523 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002524 if b:netrw_curdir =~ '[/\\]$'
2525 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2526 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002527 if b:netrw_curdir == ''
2528 " under unix, when the root directory is encountered, the result
2529 " from the preceding substitute is an empty string.
2530 let b:netrw_curdir= '/'
2531 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002532" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002533
Bram Moolenaar83bab712005-08-01 21:58:57 +00002534 " make netrw's idea of the current directory vim's if the user wishes
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002535 if !g:netrw_keepdir
Bram Moolenaar83bab712005-08-01 21:58:57 +00002536" call Decho("change directory: cd ".b:netrw_curdir)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002537 try
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002538 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002539 catch /^Vim\%((\a\+)\)\=:E472/
2540 echohl Error | echo "***netrw*** unable to change directory to <".b:netrw_curdir."> (permissions?)" | echohl None
2541 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2542 if exists("w:netrw_prvdir")
2543 let b:netrw_curdir= w:netrw_prvdir
2544 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002545 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002546" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002547 return
2548 endif
2549 endtry
Bram Moolenaar83bab712005-08-01 21:58:57 +00002550 endif
2551
2552 " change the name of the buffer to reflect the b:netrw_curdir
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002553 exe 'silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002554
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002555 " make this buffer not-a-file, modifiable, not line-numbered, etc
2556 setlocal bh=hide bt=nofile nobl ma nonu
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002557 keepalt silent! %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002558
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002559 " ---------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002560 " Perform Directory Listing:
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002561 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2562 echo "(netrw) Processing your browsing request..."
2563 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002564
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002565 " save current directory on directory history list
Bram Moolenaar83bab712005-08-01 21:58:57 +00002566 call <SID>NetBookmarkDir(3,b:netrw_curdir)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002567
Bram Moolenaar8299df92004-07-10 09:47:34 +00002568 " set up all the maps
Bram Moolenaar269ec652004-07-29 08:43:53 +00002569" call Decho("Setting up local browser maps")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002570 nnoremap <buffer> <silent> <cr> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002571 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002572 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,'../'))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002573 nnoremap <buffer> <silent> a :let g:netrw_hide=(g:netrw_hide+1)%3<bar>exe "norm! 0"<bar>call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002574 if w:netrw_longlist != 2
2575 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2576 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
2577 endif
2578 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2579 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002580 nnoremap <buffer> <silent> c :exe "cd ".b:netrw_curdir<cr>
2581 nnoremap <buffer> <silent> d :call <SID>NetMakeDir("")<cr>
2582 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(1)<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002583 nnoremap <buffer> <silent> i :call <SID>NetLongList(1)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002584 nnoremap <buffer> <silent> o :call <SID>NetSplit(2)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002585 nnoremap <buffer> <silent> O :call <SID>LocalObtain()<cr>
2586 nnoremap <buffer> <silent> p :call <SID>LocalPreview(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),1))<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002587 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002588 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002589 nnoremap <buffer> <silent> s :call <SID>NetSaveWordPosn()<bar>let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name'<bar>exe "norm! 0"<bar>call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'))<bar>call <SID>NetRestoreWordPosn()<cr>
2590 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002591 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
2592 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002593 nnoremap <buffer> <silent> v :call <SID>NetSplit(3)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002594 nnoremap <buffer> <silent> x :call <SID>NetBrowseX(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),0),0)"<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002595 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar572cb562005-08-05 21:35:02 +00002596 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
2597 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002598 exe 'nnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002599 exe 'vnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002600 exe 'nnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002601 exe 'vnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002602 exe 'nnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002603 exe 'vnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00002604 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetMakeDir("")<cr>'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002605 nnoremap <buffer> ? :he netrw-dir<cr>
2606
2607 " Set up the banner
Bram Moolenaar269ec652004-07-29 08:43:53 +00002608" call Decho("set up banner")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002609 keepjumps put ='\" ============================================================================'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002610 keepjumps 1d
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002611 keepjumps put ='\" Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002612 keepjumps put ='\" '.b:netrw_curdir
Bram Moolenaar488c6512005-08-11 20:09:58 +00002613 let w:netrw_bannercnt= 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002614
2615 let sortby= g:netrw_sort_by
2616 if g:netrw_sort_direction =~ "^r"
2617 let sortby= sortby." reversed"
2618 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00002619
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002620 " Sorted by...
Bram Moolenaar8299df92004-07-10 09:47:34 +00002621 if g:netrw_sort_by =~ "^n"
Bram Moolenaar269ec652004-07-29 08:43:53 +00002622" call Decho("directories will be sorted by name")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002623 " sorted by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002624 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar8299df92004-07-10 09:47:34 +00002625 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar488c6512005-08-11 20:09:58 +00002626 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8299df92004-07-10 09:47:34 +00002627 else
Bram Moolenaar269ec652004-07-29 08:43:53 +00002628" call Decho("directories will be sorted by size or date")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002629 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002630 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar488c6512005-08-11 20:09:58 +00002631 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002632 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002633
2634 " Hiding... -or- Showing...
Bram Moolenaar269ec652004-07-29 08:43:53 +00002635 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002636 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002637 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002638 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002639 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002640 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002641 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002642 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002643 keepjumps put ='\" Quick Help: ?:help -:go up dir D:delete R:rename s:sort-by x:exec'
2644 keepjumps put ='\" ============================================================================'
Bram Moolenaar488c6512005-08-11 20:09:58 +00002645 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002646
2647 " bannercnt should index the line just after the banner
Bram Moolenaar488c6512005-08-11 20:09:58 +00002648 let w:netrw_bannercnt= w:netrw_bannercnt + 1
2649" call Decho("bannercnt=".w:netrw_bannercnt)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002650
2651 " generate the requested directory listing
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002652 call s:LocalBrowseList()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002653
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002654 " set up syntax highlighting
2655 if has("syntax")
2656 setlocal ft=netrwlist
Bram Moolenaar572cb562005-08-05 21:35:02 +00002657 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002658 setlocal ft=
2659 endif
2660 endif
2661
Bram Moolenaar8299df92004-07-10 09:47:34 +00002662 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002663 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00002664 if g:netrw_hide && g:netrw_list_hide != ""
2665 call s:NetrwListHide()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002666 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002667 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002668
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002669 if g:netrw_sort_by =~ "^n"
2670 call s:SetSort()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002671
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002672 if w:netrw_bannercnt < line("$")
2673 if g:netrw_sort_direction =~ 'n'
2674 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
2675 else
2676 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
2677 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002678 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002679 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002680
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002681 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002682 if w:netrw_bannercnt < line("$")
2683 if g:netrw_sort_direction =~ 'n'
2684 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
2685 else
2686 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
2687 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002688 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002689 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002690 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002691
Bram Moolenaar8299df92004-07-10 09:47:34 +00002692 endif
2693 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002694
2695 call s:NetrwWideListing()
Bram Moolenaar488c6512005-08-11 20:09:58 +00002696 if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002697 " place cursor on the top-left corner of the file listing
2698 exe 'silent '.w:netrw_bannercnt
2699 norm! 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00002700 endif
2701
2702 " record previous current directory
2703 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaar8299df92004-07-10 09:47:34 +00002704
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002705 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002706 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002707 call s:NetOptionRestore()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002708 setlocal noma nomod nonu bh=hide nobl
Bram Moolenaar8299df92004-07-10 09:47:34 +00002709
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002710" call Dret("DirBrowse : file<".expand("%:p")."> bufname<".bufname("%").">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002711endfun
2712
2713" ---------------------------------------------------------------------
2714" LocalBrowseList: does the job of "ls" for local directories {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002715fun! s:LocalBrowseList()
Bram Moolenaar83bab712005-08-01 21:58:57 +00002716" call Dfunc("LocalBrowseList() b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002717
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002718 " get the list of files contained in the current directory
Bram Moolenaar83bab712005-08-01 21:58:57 +00002719 let dirname = escape(b:netrw_curdir,s:netrw_glob_escape)
2720 let dirnamelen = strlen(b:netrw_curdir)
2721 let filelist = glob(dirname."/*")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002722" call Decho("glob(dirname<".dirname.">,*)=".filelist)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002723 if filelist != ""
2724 let filelist= filelist."\n"
2725 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002726 let filelist= filelist.glob(dirname."/.*")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002727" call Decho("glob(dirname<".dirname.">,.*)=".glob(dirname.".*"))
2728
2729 " if the directory name includes a "$", and possibly other characters,
2730 " the glob() doesn't include "." and ".." entries.
2731 if filelist !~ '[\\/]\.[\\/]\=\(\n\|$\)'
2732" call Decho("forcibly tacking on .")
2733 if filelist == ""
2734 let filelist= dirname."."
2735 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00002736 let filelist= filelist."\n".b:netrw_curdir."."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002737 endif
2738" call Decho("filelist<".filelist.">")
2739 endif
2740 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
2741" call Decho("forcibly tacking on ..")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002742 let filelist= filelist."\n".b:netrw_curdir.".."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002743" call Decho("filelist<".filelist.">")
2744 endif
2745 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002746 let filelist= substitute(filelist,'\','/','ge')
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002747
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002748" call Decho("dirname<".dirname.">")
2749" call Decho("dirnamelen<".dirnamelen.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002750" call Decho("filelist<".filelist.">")
2751
2752 while filelist != ""
2753 if filelist =~ '\n'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002754 let filename = substitute(filelist,'\n.*$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002755 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
2756 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00002757 let filename = filelist
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002758 let filelist = ""
Bram Moolenaar8299df92004-07-10 09:47:34 +00002759 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002760 let pfile= filename
2761 if isdirectory(filename)
2762 let pfile= filename."/"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002763 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002764 if pfile =~ '//$'
2765 let pfile= substitute(pfile,'//$','/','e')
2766 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002767 let pfile= strpart(pfile,dirnamelen)
Bram Moolenaar572cb562005-08-05 21:35:02 +00002768 let pfile= substitute(pfile,'^/','','e')
Bram Moolenaar83bab712005-08-01 21:58:57 +00002769" call Decho(" ")
2770" call Decho("filename<".filename.">")
2771" call Decho("pfile <".pfile.">")
2772
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002773 if w:netrw_longlist == 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00002774 let sz = getfsize(filename)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002775 let fsz = strpart(" ",1,15-strlen(sz)).sz
2776 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaar83bab712005-08-01 21:58:57 +00002777" call Decho("sz=".sz." fsz=".fsz)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002778 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002779
Bram Moolenaar8299df92004-07-10 09:47:34 +00002780 if g:netrw_sort_by =~ "^t"
2781 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002782" call Decho("getftime(".filename.")=".getftime(filename))
2783 let t = getftime(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002784 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar83bab712005-08-01 21:58:57 +00002785" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002786 let ftpfile= ft.'/'.pfile
2787 keepjumps put=ftpfile
2788
Bram Moolenaar8299df92004-07-10 09:47:34 +00002789 elseif g:netrw_sort_by =~ "^s"
2790 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002791" call Decho("getfsize(".filename.")=".getfsize(filename))
2792 let sz = getfsize(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002793 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar83bab712005-08-01 21:58:57 +00002794" call Decho("exe keepjumps put ='".fsz.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002795 let fszpfile= fsz.'/'.pfile
2796 keepjumps put =fszpfile
2797
Bram Moolenaar8299df92004-07-10 09:47:34 +00002798 else
2799 " sort by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002800" call Decho("exe keepjumps put ='".pfile."'")
2801 keepjumps put=pfile
Bram Moolenaar8299df92004-07-10 09:47:34 +00002802 endif
2803 endwhile
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002804
2805 " cleanup any windows mess at end-of-line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002806 silent! keepjumps %s/\r$//e
Bram Moolenaar83bab712005-08-01 21:58:57 +00002807 setlocal ts=32
Bram Moolenaar8299df92004-07-10 09:47:34 +00002808
2809" call Dret("LocalBrowseList")
2810endfun
2811
2812" ---------------------------------------------------------------------
2813" LocalBrowseChgDir: constructs a new directory based on the current {{{2
2814" directory and a new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002815fun! s:LocalBrowseChgDir(dirname,newdir,...)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002816" call Dfunc("LocalBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">) a:0=".a:0)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002817
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002818 let dirname= substitute(a:dirname,'\\','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002819 let newdir = a:newdir
2820
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002821 if dirname !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002822 " apparently vim is "recognizing" that it is in the home directory and
2823 " is removing the "/". Bad idea, so I have to put it back.
2824 let dirname= dirname.'/'
2825" call Decho("adjusting dirname<".dirname.">")
2826 endif
2827
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002828 if newdir !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002829 " handling a file
2830 let dirname= dirname.newdir
2831" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002832 " this lets NetBrowseX avoid the edit
2833 if a:0 < 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00002834" call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape.">")
2835" call Decho("about to edit<".escape(dirname,s:netrw_cd_escape).">")
2836 exe "e! ".escape(dirname,s:netrw_cd_escape)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002837 set ma nomod
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002838 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002839
2840 elseif newdir == './'
2841 " refresh the directory list
2842" call Decho("refresh directory listing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002843
2844 elseif newdir == '../'
2845 " go up one directory
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002846 let dirname= substitute(dirname,'^\(.*/\)\([^/]\+[\/]$\)','\1','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002847" call Decho("go up one dir: dirname<".dirname.">")
2848
2849 else
2850 " go down one directory
2851 let dirname= dirname.newdir
2852" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
2853 endif
2854
2855" call Dret("LocalBrowseChgDir <".dirname.">")
2856 return dirname
2857endfun
2858
2859" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00002860" LocalBrowseRm: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002861fun! s:LocalBrowseRm(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00002862" call Dfunc("LocalBrowseRm(path<".a:path.">)")
2863" call Decho("firstline=".a:firstline." lastline=".a:lastline)
2864
2865 " preparation for removing multiple files/directories
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002866 let ctr = a:firstline
2867 let ret = 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002868 let all= 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00002869
2870 " remove multiple files and directories
2871 while ctr <= a:lastline
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002872 exe "keepjumps ".ctr
2873
2874 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00002875 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002876 let ctr= ctr + 1
2877 continue
2878 endif
2879 let curword= s:NetGetWord()
2880 if curword == "./" || curword == "../"
2881 let ctr= ctr + 1
2882 continue
2883 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002884
2885 norm! 0
Bram Moolenaar83bab712005-08-01 21:58:57 +00002886 let rmfile= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00002887" call Decho("rmfile<".rmfile.">")
2888
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002889 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002890 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002891 if !all
2892 echohl Statement
2893 call inputsave()
2894 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
2895 call inputrestore()
2896 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002897 if ok == ""
2898 let ok="no"
2899 endif
2900" call Decho("response: ok<".ok.">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002901 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002902" call Decho("response: ok<".ok."> (after sub)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002903 if ok =~ 'a\%[ll]'
2904 let all= 1
2905 endif
2906 endif
2907
2908 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002909 let ret= delete(rmfile)
2910" call Decho("errcode=".v:shell_error." ret=".ret)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002911 elseif ok =~ 'q\%[uit]'
2912 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00002913 endif
2914
2915 else
2916 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002917 if !all
2918 echohl Statement
2919 call inputsave()
2920 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
2921 call inputrestore()
2922 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002923 if ok == ""
2924 let ok="no"
2925 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002926 if ok =~ 'a\%[ll]'
2927 let all= 1
2928 endif
2929 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002930 let rmfile= substitute(rmfile,'[\/]$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002931
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002932 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002933" call Decho("1st attempt: system(".g:netrw_local_rmdir.' "'.rmfile.'")')
2934 call system(g:netrw_local_rmdir.' "'.rmfile.'"')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002935" call Decho("v:shell_error=".v:shell_error)
2936
2937 if v:shell_error != 0
2938" call Decho("2nd attempt to remove directory<".rmfile.">")
2939 let errcode= delete(rmfile)
2940" call Decho("errcode=".errcode)
2941
2942 if errcode != 0
2943 if has("unix")
2944" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002945call system("rm ".rmfile)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002946 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002947 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002948 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002950 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002951 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002952 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002953 endif
2954 endif
2955 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002956
2957 elseif ok =~ 'q\%[uit]'
2958 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00002959 endif
2960 endif
2961
2962 let ctr= ctr + 1
2963 endwhile
2964
2965 " refresh the directory
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002966 let curline= line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002967" call Decho("refresh the directory")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002968 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002969 exe curline
2970
2971" call Dret("LocalBrowseRm")
2972endfun
2973
2974" ---------------------------------------------------------------------
2975" LocalBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002976fun! s:LocalBrowseRename(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00002977" call Dfunc("LocalBrowseRename(path<".a:path.">)")
2978
2979 " preparation for removing multiple files/directories
2980 let ctr= a:firstline
2981
2982 " attempt to rename files/directories
2983 while ctr <= a:lastline
2984 exe "keepjumps ".ctr
2985
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002986 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00002987 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002988 let ctr= ctr + 1
2989 continue
2990 endif
2991 let curword= s:NetGetWord()
2992 if curword == "./" || curword == "../"
2993 let ctr= ctr + 1
2994 continue
2995 endif
2996
Bram Moolenaar8299df92004-07-10 09:47:34 +00002997 norm! 0
Bram Moolenaar572cb562005-08-05 21:35:02 +00002998 let oldname= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00002999" call Decho("oldname<".oldname.">")
3000
3001 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003002 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00003003 call inputrestore()
3004
Bram Moolenaar83bab712005-08-01 21:58:57 +00003005 let ret= rename(oldname,newname)
3006" call Decho("renaming <".oldname."> to <".newname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003007
3008 let ctr= ctr + 1
3009 endwhile
3010
3011 " refresh the directory
3012 let curline= line(".")
Bram Moolenaar269ec652004-07-29 08:43:53 +00003013" call Decho("refresh the directory listing")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003014 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003015 exe "keepjumps ".curline
3016" call Dret("LocalBrowseRename")
3017endfun
3018
3019" ---------------------------------------------------------------------
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003020" LocalObtain: copy selected file to current working directory {{{2
3021fun! s:LocalObtain()
3022" call Dfunc("LocalObtain()")
3023 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
3024 let fname= expand("<cWORD>")
3025 let fcopy= readfile(b:netrw_curdir."/".fname,"b")
3026 call writefile(fcopy,getcwd()."/".fname,"b")
3027 elseif !exists("b:netrw_curdir")
3028 echohl Error | echo "***netrw*** local browsing directory doesn't exist!"
3029 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3030 else
3031 echohl Error | echo "***netrw*** local browsing directory and current directory are identical"
3032 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3033 endif
3034" call Dret("LocalObtain")
3035endfun
3036
3037" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003038" LocalPreview: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003039fun! s:LocalPreview(path) range
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003040" call Dfunc("LocalPreview(path<".a:path.">)")
3041 if has("quickfix")
3042 if !isdirectory(a:path)
3043 exe "pedit ".a:path
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003044 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003045 echohl WarningMsg | echo "***netrw*** sorry, cannot preview a directory such as <".a:path.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003046 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003047 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003048 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003049 echohl WarningMsg | echo "***netrw*** sorry, to preview your vim needs the quickfix feature compiled in" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003050 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003051 endif
3052" call Dret("LocalPreview")
3053endfun
3054
3055" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003056" Explore: launch the local browser in the directory of the current file {{{2
3057" dosplit==0: the window will be split iff the current file has
3058" been modified
3059" dosplit==1: the window will be split before running the local
3060" browser
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003061fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003062" call Dfunc("Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.")")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003063
3064 " if dosplit or file has been modified
3065 if a:dosplit || &modified
Bram Moolenaar488c6512005-08-11 20:09:58 +00003066 call <SID>SaveWinVars()
3067
Bram Moolenaar83bab712005-08-01 21:58:57 +00003068 if a:style == 0 " Explore, Sexplore
3069 exe g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003070" call Decho("style=0: Explore or Sexplore")
3071
Bram Moolenaar83bab712005-08-01 21:58:57 +00003072 elseif a:style == 1 "Explore!, Sexplore!
3073 exe g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003074" call Decho("style=1: Explore! or Sexplore!")
3075
Bram Moolenaar83bab712005-08-01 21:58:57 +00003076 elseif a:style == 2 " Hexplore
3077 exe "bel ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003078" call Decho("style=2: Hexplore")
3079
Bram Moolenaar83bab712005-08-01 21:58:57 +00003080 elseif a:style == 3 " Hexplore!
3081 exe "abo ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003082" call Decho("style=3: Hexplore!")
3083
Bram Moolenaar83bab712005-08-01 21:58:57 +00003084 elseif a:style == 4 " Vexplore
3085 exe "lefta ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003086" call Decho("style=4: Vexplore")
3087
Bram Moolenaar83bab712005-08-01 21:58:57 +00003088 elseif a:style == 5 " Vexplore!
3089 exe "rightb ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003090" call Decho("style=5: Vexplore!")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003091 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003092 call s:CopyWinVars()
Bram Moolenaar83bab712005-08-01 21:58:57 +00003093 endif
3094 norm! 0
3095
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003096 if a:1 == "" && a:indx >= 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003097 " Explore Hexplore Vexplore Sexplore
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003098" call Decho("Explore Hexplore Vexplore Sexplore")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003099 let newdir= substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
3100 if newdir =~ '^scp:' || newdir =~ '^ftp:'
3101" call Decho("calling NetBrowse(newdir<".newdir.">)")
3102 call s:NetBrowse(newdir)
3103 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003104 if newdir == ""|let newdir= getcwd()|endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003105" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3106 call s:LocalBrowse(newdir)
3107 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003108
Bram Moolenaar572cb562005-08-05 21:35:02 +00003109 elseif a:1 =~ '\*\*/' || a:indx < 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003110 " Nexplore Pexplore -or- Explore **/...
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003111" call Decho("Nexplore Pexplore -or- Explore **/...")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003112
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003113 if has("path_extra")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003114 if !exists("w:netrw_explore_indx")
3115 let w:netrw_explore_indx= 0
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003116 endif
3117 let indx = a:indx
3118 if indx == -1
Bram Moolenaar488c6512005-08-11 20:09:58 +00003119 let indx= w:netrw_explore_indx + 1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003120 elseif indx == -2
Bram Moolenaar488c6512005-08-11 20:09:58 +00003121 let indx= w:netrw_explore_indx - 1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003122 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003123 let w:netrw_explore_indx = 0
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003124 if !exists("b:netrw_curdir")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003125 let b:netrw_curdir= getcwd()
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003126 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003127 let w:netrw_explore_list = split(expand(b:netrw_curdir."/".a:1),'\n')
3128 let w:netrw_explore_listlen = len(w:netrw_explore_list)
3129 if w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/'
Bram Moolenaar572cb562005-08-05 21:35:02 +00003130 echohl WarningMsg | echo "***netrw*** no files matched" | echohl None
3131 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3132" call Dret("Explore")
3133 return
3134 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003135 endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003136
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003137 " NetrwStatusLine support - for exploring support
Bram Moolenaar488c6512005-08-11 20:09:58 +00003138 let w:netrw_explore_indx= indx
Bram Moolenaar488c6512005-08-11 20:09:58 +00003139" call Decho("explorelist<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003140
3141 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003142 if indx >= w:netrw_explore_listlen || indx < 0
3143 let indx= (indx < 0)? 0 : ( w:netrw_explore_listlen - 1 )
Bram Moolenaar572cb562005-08-05 21:35:02 +00003144 echohl WarningMsg | echo "***netrw*** no more files match Explore pattern" | echohl None
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003145 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3146" call Dret("Explore")
3147 return
3148 endif
3149
Bram Moolenaar488c6512005-08-11 20:09:58 +00003150 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003151" call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003152 let newdir= substitute(dirfile,'/[^/]*$','','e')
3153" call Decho("newdir<".newdir.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003154
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003155" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3156 call s:LocalBrowse(newdir)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003157 if w:netrw_longlist == 0 || w:netrw_longlist == 1
3158 call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
3159 else
3160 call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
3161 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003162 let w:netrw_explore_mtchcnt = indx + 1
3163 let w:netrw_explore_bufnr = bufnr(".")
3164 let w:netrw_explore_line = line(".")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003165 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaar488c6512005-08-11 20:09:58 +00003166" call Decho("explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003167
3168 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003169 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003170 echohl WarningMsg | echo "***netrw*** your vim needs the +path_extra feature for Exploring with **!" | echohl None | echohl None
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003171 endif
3172 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3173 endif
3174
Bram Moolenaar83bab712005-08-01 21:58:57 +00003175 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003176" call Decho("Explore newdir<".a:1.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003177 let newdir= a:1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003178 call s:LocalBrowse(newdir)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003179 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003180
3181" call Dret("Explore")
3182endfun
3183
3184" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003185" SetupNetrwStatusLine: {{{2
3186fun! s:SetupNetrwStatusLine(statline)
3187" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
3188
3189 if !exists("s:netrw_setup_statline")
3190 let s:netrw_setup_statline= 1
3191" call Decho("do first-time status line setup")
3192
3193 if !exists("s:netrw_users_stl")
3194 let s:netrw_users_stl= &stl
3195 endif
3196 if !exists("s:netrw_users_ls")
3197 let s:netrw_users_ls= &laststatus
3198 endif
3199
3200 " set up User9 highlighting as needed
3201 let keepa= @a
3202 redir @a
3203 try
3204 hi User9
3205 catch /^Vim\%((\a\+)\)\=:E411/
3206 if &bg == "dark"
3207 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
3208 else
3209 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
3210 endif
3211 endtry
3212 redir END
3213 let @a= keepa
3214 endif
3215
3216 " set up status line (may use User9 highlighting)
3217 " insure that windows have a statusline
3218 " make sure statusline is displayed
3219 let &stl=a:statline
3220 set laststatus=2
3221" call Decho("stl=".&stl)
3222 redraw!
3223
3224" call Dret("SetupNetrwStatusLine : stl=".&stl)
3225endfun
3226
3227" ---------------------------------------------------------------------
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003228" NetrwStatusLine: {{{2
3229fun! NetrwStatusLine()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003230
3231 " vvv NetrwStatusLine() debugging vvv
3232" let g:stlmsg=""
3233" if !exists("w:netrw_explore_bufnr")
3234" let g:stlmsg="!X<explore_bufnr>"
3235" elseif w:netrw_explore_bufnr != bufnr(".")
3236" let g:stlmsg="explore_bufnr!=".bufnr(".")
3237" endif
3238" if !exists("w:netrw_explore_line")
3239" let g:stlmsg=" !X<explore_line>"
3240" elseif w:netrw_explore_line != line(".")
3241" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
3242" endif
3243" if !exists("w:netrw_explore_list")
3244" let g:stlmsg=" !X<explore_list>"
3245" endif
3246 " ^^^ NetrwStatusLine() debugging ^^^
3247
Bram Moolenaar488c6512005-08-11 20:09:58 +00003248 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr(".") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003249 " restore user's status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003250 let &stl = s:netrw_users_stl
3251 let &laststatus = s:netrw_users_ls
Bram Moolenaar488c6512005-08-11 20:09:58 +00003252 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
3253 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003254 return ""
3255 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003256 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003257 endif
3258endfun
3259
3260" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003261" NetGetcwd: get the current directory. {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003262" Change backslashes to forward slashes, if any.
3263" If doesc is true, escape certain troublesome characters
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003264fun! s:NetGetcwd(doesc)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003265" call Dfunc("NetGetcwd(doesc=".a:doesc.")")
3266 let curdir= substitute(getcwd(),'\\','/','ge')
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003267 if curdir !~ '[\/]$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003268 let curdir= curdir.'/'
3269 endif
3270 if a:doesc
3271 let curdir= escape(curdir,s:netrw_cd_escape)
3272 endif
3273" call Dret("NetGetcwd <".curdir.">")
3274 return curdir
3275endfun
3276
3277" ---------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278" NetMethod: determine method of transfer {{{1
3279" method == 1: rcp
3280" 2: ftp + <.netrc>
3281" 3: ftp + machine, id, password, and [path]filename
3282" 4: scp
3283" 5: http (wget)
3284" 6: cadaver
3285" 7: rsync
3286" 8: fetch
3287" 9: sftp
3288fun! s:NetMethod(choice) " globals: method machine id passwd fname
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003289" call Dfunc("NetMethod(a:choice<".a:choice.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003290
3291 " initialization
3292 let b:netrw_method = 0
3293 let g:netrw_machine = ""
3294 let b:netrw_fname = ""
3295 let g:netrw_port = ""
3296
3297 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003298 " mipf : a:machine a:id password filename Use ftp
3299 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003300 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003301 " rcpurm : rcp://[user@]host/filename Use rcp
3302 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003303 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003304 " httpurm : http://[user@]host/filename Use wget
3305 " davurm : [s]dav://host[:port]/path Use cadaver
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003306 " rsyncurm : rsync://host[:port]/path Use rsync
3307 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3308 " sftpurm : sftp://[user@]host/filename Use scp
3309 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3310 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
3311 let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003312 let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003313 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003314 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003315 let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003316 let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003317 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
3318 let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
3319 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
3320
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003322 " Determine Method
3323 " rcp://user@hostname/...path-to-file
3324 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003326 let b:netrw_method = 1
3327 let userid = substitute(a:choice,rcpurm,'\1',"")
3328 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3329 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003330 if userid != ""
3331 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003333
3334 " scp://user@hostname/...path-to-file
3335 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003336" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003337 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003338 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3339 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3340 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003341
3342 " http://user@hostname/...path-to-file
3343 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003344" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003345 let b:netrw_method = 5
3346 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3347 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
3348
3349 " dav://hostname[:port]/..path-to-file..
3350 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003351" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003352 let b:netrw_method= 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003353 if a:choice =~ '^s'
3354 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3355 else
3356 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3357 endif
3358 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003359
3360 " rsync://user@hostname/...path-to-file
3361 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003362" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003363 let b:netrw_method = 7
3364 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3365 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
3366
3367 " ftp://[user@]hostname[[:#]port]/...path-to-file
3368 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003369" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003370 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003371 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3372 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3373 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003374 if userid != ""
3375 let g:netrw_uid= userid
3376 endif
3377 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3378 let b:netrw_method = 3
3379 else
3380 if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc")
3381 let b:netrw_method= 2
3382 else
3383 if !exists("g:netrw_uid") || g:netrw_uid == ""
3384 call NetUserPass()
3385 elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
3386 call NetUserPass(g:netrw_uid)
3387 " else just use current g:netrw_uid and g:netrw_passwd
3388 endif
3389 let b:netrw_method= 3
3390 endif
3391 endif
3392
3393 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003394" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003395 let b:netrw_method = 8
3396 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3397 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3398 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3399 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
3400
3401 " Issue an ftp : "machine id password [path/]filename"
3402 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003403" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003405 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3406 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
3407 let g:netrw_passwd = substitute(a:choice,mipf,'\3',"")
3408 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
3409
3410 " Issue an ftp: "hostname [path/]filename"
3411 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003412" call Decho("(ftp) host file")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003413 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3414 let b:netrw_method = 3
3415 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3416 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3417
3418 elseif filereadable(expand("$HOME/.netrc"))
3419 let b:netrw_method = 2
3420 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3421 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3422 endif
3423
3424 " sftp://user@hostname/...path-to-file
3425 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003426" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003427 let b:netrw_method = 9
3428 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3429 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
3430
3431 " Issue an rcp: hostname:filename" (this one should be last)
3432 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003433" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003434 let b:netrw_method = 1
3435 let userid = substitute(a:choice,rcphf,'\2',"")
3436 let g:netrw_machine= substitute(a:choice,rcphf,'\3',"")
3437 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003438" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
3439" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
3440" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
3441" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003442 if userid != ""
3443 let g:netrw_uid= userid
3444 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003445 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003446 " don't let PCs try <.netrc>
3447 let b:netrw_method = 3
3448 endif
3449
3450 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003451 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003452 echohl Error | echo "***netrw*** cannot determine method" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003453 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003454 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003455 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456 endif
Bram Moolenaar81695252004-12-29 20:58:21 +00003457
3458 " remove any leading [:#] from port number
3459 if g:netrw_port != ""
3460 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3461 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003462
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003463" call Decho("a:choice <".a:choice.">")
3464" call Decho("b:netrw_method <".b:netrw_method.">")
3465" call Decho("g:netrw_machine<".g:netrw_machine.">")
3466" call Decho("g:netrw_port <".g:netrw_port.">")
3467" if exists("g:netrw_uid") "Decho
3468" call Decho("g:netrw_uid <".g:netrw_uid.">")
3469" endif "Decho
3470" if exists("g:netrw_passwd") "Decho
3471" call Decho("g:netrw_passwd <".g:netrw_passwd.">")
3472" endif "Decho
3473" call Decho("b:netrw_fname <".b:netrw_fname.">")
3474" call Dret("NetMethod")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
3477" ------------------------------------------------------------------------
3478" NetUserPass: set username and password for subsequent ftp transfer {{{1
3479" Usage: :call NetUserPass() -- will prompt for userid and password
3480" :call NetUserPass("uid") -- will prompt for password
3481" :call NetUserPass("uid","password") -- sets global userid and password
3482fun! NetUserPass(...)
3483
3484 " get/set userid
3485 if a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003486" call Dfunc("NetUserPass(a:0<".a:0.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 if !exists("g:netrw_uid") || g:netrw_uid == ""
3488 " via prompt
3489 let g:netrw_uid= input('Enter username: ')
3490 endif
3491 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003492" call Dfunc("NetUserPass(a:1<".a:1.">) {")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493 let g:netrw_uid= a:1
3494 endif
3495
3496 " get password
3497 if a:0 <= 1 " via prompt
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003498" call Decho("a:0=".a:0." case <=1:")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 let g:netrw_passwd= inputsecret("Enter Password: ")
3500 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003501" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 let g:netrw_passwd=a:2
3503 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003504
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003505" call Dret("NetUserPass")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507
3508" ------------------------------------------------------------------------
3509" NetOptionSave: save options and set to "standard" form {{{1
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003510fun! s:NetOptionSave()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003511" call Dfunc("NetOptionSave()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003512 if !exists("w:netoptionsave")
3513 let w:netoptionsave= 1
3514 else
3515" call Dret("NetOptionSave : netoptionsave=".w:netoptionsave)
3516 return
3517 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003519 " Get Temporary Filename
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003520 let w:aikeep = &ai
3521 " record autochdir setting and then insure its unset (tnx to David Fishburn)
3522 if has("netbeans_intg") || has("sun_workshop")
3523 let w:acdkeep = &autochdir
3524 set noautochdir
3525 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003526 let w:cinkeep = &cin
3527 let w:cinokeep = &cino
3528 let w:comkeep = &com
3529 let w:cpokeep = &cpo
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003530 if !g:netrw_keepdir
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003531 let w:dirkeep = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003532 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003533 let w:gdkeep = &gd
3534 let w:repkeep = &report
3535 let w:spellkeep = &spell
3536 let w:twkeep = &tw
Bram Moolenaar8299df92004-07-10 09:47:34 +00003537 setlocal cino =
3538 setlocal com =
3539 setlocal cpo -=aA
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003540 setlocal nocin noai nospell
Bram Moolenaar8299df92004-07-10 09:47:34 +00003541 setlocal tw =0
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003542 setlocal report=10000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003543 if has("win32") && !has("win95")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003544 let w:swfkeep= &swf
Bram Moolenaar8299df92004-07-10 09:47:34 +00003545 setlocal noswf
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003546" call Decho("setting w:swfkeep to <".&swf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003547 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003549" call Dret("NetOptionSave")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550endfun
3551
3552" ------------------------------------------------------------------------
3553" NetOptionRestore: restore options {{{1
3554fun! s:NetOptionRestore()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003555" call Dfunc("NetOptionRestore()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003556 if !exists("w:netoptionsave")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003557" call Dret("NetOptionRestore : w:netoptionsave doesn't exist")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003558 return
3559 endif
3560 unlet w:netoptionsave
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003561
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003562 if exists("w:aikeep")| let &ai= w:aikeep|endif
3563 if (has("netbeans_intg") || has("sun_workshop")) && exists("w:acdkeep")
3564 let &acd= w:acdkeep
3565 unlet w:acdkeep
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003566 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003567 if exists("w:cinkeep") |let &cin = w:cinkeep |unlet w:cinkeep |endif
3568 if exists("w:cinokeep") |let &cino = w:cinokeep |unlet w:cinokeep |endif
3569 if exists("w:comkeep") |let &com = w:comkeep |unlet w:comkeep |endif
3570 if exists("w:cpokeep") |let &cpo = w:cpokeep |unlet w:cpokeep |endif
3571 if exists("w:dirkeep") |exe "lcd ".w:dirkeep |unlet w:dirkeep |endif
3572 if exists("w:gdkeep") |let &gd = w:gdkeep |unlet w:gdkeep |endif
3573 if exists("w:repkeep") |let &report = w:repkeep |unlet w:repkeep |endif
3574 if exists("w:spellkeep")|let &spell = w:spellkeep |unlet w:spellkeep|endif
3575 if exists("w:twkeep") |let &tw = w:twkeep |unlet w:twkeep |endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003576 if exists("w:swfkeep")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003577 if &directory == "" && exists("w:swfkeep")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003578 " user hasn't specified a swapfile directory;
3579 " netrw will temporarily make the swapfile
3580 " directory the current local one.
3581 let &directory = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003582 silent! let &swf = w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003583 set directory=
3584 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003585 let &swf= w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003586 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003587 unlet w:swfkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003588 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003589
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003590" call Dret("NetOptionRestore")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003591endfun
3592
3593" ------------------------------------------------------------------------
3594" NetReadFixup: this sort of function is typically written by the user {{{1
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003595" to handle extra junk that their system's ftp dumps
3596" into the transfer. This function is provided as an
3597" example and as a fix for a Windows 95 problem: in my
3598" experience, win95's ftp always dumped four blank lines
3599" at the end of the transfer.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003600if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 fun! NetReadFixup(method, line1, line2)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003602" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 if method == 3 " ftp (no <.netrc>)
3604 let fourblanklines= line2 - 3
3605 silent fourblanklines.",".line2."g/^\s*/d"
3606 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003607" call Dret("NetReadFixup")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 endfun
3609endif
3610
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003611" ---------------------------------------------------------------------
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003612" NetSort: Piet Delport's BISort2() function, modified to take a range {{{1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003613if v:version < 700
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003614 fun! s:NetSort() range
Bram Moolenaar83bab712005-08-01 21:58:57 +00003615" " call Dfunc("NetSort()")
3616
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003617 let i = a:firstline + 1
3618 while i <= a:lastline
3619 " find insertion point via binary search
3620 let i_val = getline(i)
3621 let lo = a:firstline
3622 let hi = i
3623 while lo < hi
Bram Moolenaar83bab712005-08-01 21:58:57 +00003624 let mid = (lo + hi) / 2
3625 let mid_val = getline(mid)
3626 if g:netrw_sort_direction =~ '^n'
3627 " normal sorting order
3628 if i_val < mid_val
3629 let hi = mid
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003630 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003631 let lo = mid + 1
3632 if i_val == mid_val | break | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003633 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003634 else
3635 " reverse sorting order
3636 if i_val > mid_val
3637 let hi = mid
3638 else
3639 let lo = mid + 1
3640 if i_val == mid_val | break | endif
3641 endif
3642 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003643 endwhile
3644 " do insert
3645 if lo < i
Bram Moolenaar83bab712005-08-01 21:58:57 +00003646 exe 'keepjumps '.i.'d_'
3647 keepjumps call append(lo - 1, i_val)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003648 endif
3649 let i = i + 1
3650 endwhile
Bram Moolenaar83bab712005-08-01 21:58:57 +00003651
3652" " call Dret("NetSort")
3653 endfun
3654endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003655
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003656" ---------------------------------------------------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00003657" SetSort: sets up the sort based on the g:netrw_sort_sequence {{{1
3658" What this function does is to compute a priority for the patterns
3659" in the g:netrw_sort_sequence. It applies a substitute to any
3660" "files" that satisfy each pattern, putting the priority / in
3661" front. An "*" pattern handles the default priority.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003662fun! s:SetSort()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003663" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003664 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00003665 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
3666 else
3667 let seqlist = g:netrw_sort_sequence
3668 endif
3669 " sanity check -- insure that * appears somewhere
3670 if seqlist == ""
3671 let seqlist= '*'
3672 elseif seqlist !~ '\*'
3673 let seqlist= seqlist.',*'
3674 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003675 let priority = 1
3676 while seqlist != ""
3677 if seqlist =~ ','
3678 let seq = substitute(seqlist,',.*$','','e')
3679 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
3680 else
3681 let seq = seqlist
3682 let seqlist = ""
3683 endif
3684 let eseq= escape(seq,'/')
3685 if priority < 10
3686 let spriority= "00".priority.'\/'
3687 elseif priority < 100
3688 let spriority= "0".priority.'\/'
3689 else
3690 let spriority= priority.'\/'
3691 endif
3692" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
3693
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003694 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003695 if w:netrw_bannercnt > line("$")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003696 " apparently no files were left after a Hiding pattern was used
3697" call Dret("SetSort : no files left after hiding")
3698 return
3699 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003700 if seq == '*'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003701 exe 'silent keepjumps '.w:netrw_bannercnt.',$v/^\d\{3}\//s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003702 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003703 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/'.eseq.'/s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003704 endif
3705 let priority = priority + 1
3706 endwhile
3707
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003708 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{3}\/\)\%(\d\{3}\/\)\+/\1/e'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003709
3710" call Dret("SetSort")
3711endfun
3712
Bram Moolenaar488c6512005-08-11 20:09:58 +00003713" ---------------------------------------------------------------------
3714" SaveWinVars: (used by Explore()) {{{1
3715fun! s:SaveWinVars()
3716" call Dfunc("SaveWinVars()")
3717 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
3718 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
3719 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
3720 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
3721 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
3722 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
3723 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
3724 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003725 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003726" call Dret("SaveWinVars")
3727endfun
3728
3729" ---------------------------------------------------------------------
3730" CopyWinVars: (used by Explore()) {{{1
3731fun! s:CopyWinVars()
3732" call Dfunc("CopyWinVars()")
3733 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
3734 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
3735 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
3736 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
3737 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
3738 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
3739 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
3740 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003741 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003742" call Dret("CopyWinVars")
3743endfun
3744
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003745" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003746" SetBufWinVars: (used by NetBrowse() and LocalBrowse()) {{{1
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003747" To allow separate windows to have their own activities, such as
3748" Explore **/pattern, several variables have been made window-oriented.
3749" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003750" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003751" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003752fun! s:SetBufWinVars()
3753" call Dfunc("SetBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003754 if exists("w:netrw_longlist") |let b:netrw_longlist = w:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003755 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
3756 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
3757 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
3758 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
3759 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen = w:netrw_explore_listlen|endif
3760 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = w:netrw_explore_mtchcnt|endif
3761 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
3762 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
3763 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003764" call Dret("SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003765endfun
3766
3767" ---------------------------------------------------------------------
3768" UseBufWinVars: (used by NetBrowse() and LocalBrowse() {{{1
3769" Matching function to BufferWinVars()
3770fun! s:UseBufWinVars()
3771" call Dfunc("UseBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003772 if exists("b:netrw_longlist") && !exists("w:netrw_longlist") |let w:netrw_longlist = b:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003773 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
3774 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
3775 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
3776 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
3777 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
3778 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
3779 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
3780 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
3781 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
3782" call Dret("UseBufWinVars")
3783endfun
3784
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003785" ---------------------------------------------------------------------
3786" RFC2396: converts %xx into characters
3787fun! netrw#RFC2396(fname)
3788" call Dfunc("RFC2396(fname<".a:fname.">)")
3789 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
3790" call Dret("RFC2396 ".fname)
3791 return fname
3792endfun
3793
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003794" ------------------------------------------------------------------------
3795" Settings Restoration: {{{1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003796let &cpo= s:keepcpo
3797unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003798
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003800" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801" vim:ts=8 fdm=marker