blob: 3a184a14995b1ddb908e42f980d8f6944f298bf6 [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 Moolenaarafeb4fa2006-02-01 21:51:12 +00003" Date: Jan 30, 2006
4" Version: 78
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
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000026let g:loaded_netrw = "v78"
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
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000035" ======================
36" Netrw Variables: {{{1
37" ======================
38
Bram Moolenaar071d4272004-06-13 20:20:40 +000039" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000040" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +000041if !exists("g:netrw_dav_cmd")
42 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar071d4272004-06-13 20:20:40 +000043endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044if !exists("g:netrw_fetch_cmd")
45 if executable("fetch")
46 let g:netrw_fetch_cmd = "fetch -o"
47 else
48 let g:netrw_fetch_cmd = ""
49 endif
50endif
51if !exists("g:netrw_ftp_cmd")
52 let g:netrw_ftp_cmd = "ftp"
53endif
54if !exists("g:netrw_http_cmd")
55 if executable("wget")
56 let g:netrw_http_cmd = "wget -q -O"
57 elseif executable("fetch")
58 let g:netrw_http_cmd = "fetch -o"
59 else
60 let g:netrw_http_cmd = ""
61 endif
62endif
63if !exists("g:netrw_rcp_cmd")
64 let g:netrw_rcp_cmd = "rcp"
65endif
66if !exists("g:netrw_rsync_cmd")
67 let g:netrw_rsync_cmd = "rsync"
68endif
69if !exists("g:netrw_scp_cmd")
70 let g:netrw_scp_cmd = "scp -q"
71endif
72if !exists("g:netrw_sftp_cmd")
73 let g:netrw_sftp_cmd = "sftp"
74endif
75if !exists("g:netrw_ssh_cmd")
76 let g:netrw_ssh_cmd= "ssh"
77endif
78
79if has("win32") || has("win95") || has("win64") || has("win16")
80 \ && exists("g:netrw_use_nt_rcp")
81 \ && g:netrw_use_nt_rcp
82 \ && executable( $SystemRoot .'/system32/rcp.exe')
83 let s:netrw_has_nt_rcp = 1
84 let s:netrw_rcpmode = '-b'
85 else
86 let s:netrw_has_nt_rcp = 0
87 let s:netrw_rcpmode = ''
88endif
89
90" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000091" Default values for netrw's global variables {{{2
92" Default values - a-c ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +000093if !exists("g:netrw_alto")
94 let g:netrw_alto= 0
95endif
96if !exists("g:netrw_altv")
97 let g:netrw_altv= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000098endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000099if !exists("g:netrw_browse_split")
100 let g:netrw_browse_split= 0
101endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102if !exists("g:netrw_cygwin")
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000103 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000104 if &shell == "bash"
105 let g:netrw_cygwin= 1
106 else
107 let g:netrw_cygwin= 0
108 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109 else
110 let g:netrw_cygwin= 0
111 endif
112endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000113" Default values - d-f ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000114if !exists("g:NETRW_DIRHIST_CNT")
115 let g:NETRW_DIRHIST_CNT= 0
116endif
117if !exists("g:netrw_dirhistmax")
118 let g:netrw_dirhistmax= 10
119endif
120if !exists("g:netrw_ftp_browse_reject")
121 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 +0000122endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000123if !exists("g:netrw_ftp_list_cmd")
124 if has("unix") || exists("g:netrw_cygwin")
125 let g:netrw_ftp_list_cmd= "ls -lF"
126 else
127 let g:netrw_ftp_list_cmd= "dir"
128 endif
129endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000130if !exists("g:netrw_ftpmode")
131 let g:netrw_ftpmode= "binary"
Bram Moolenaar61036992005-10-12 20:54:52 +0000132endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000133" Default values - h-lh ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000134if !exists("g:netrw_hide")
135 let g:netrw_hide= 1
Bram Moolenaar61036992005-10-12 20:54:52 +0000136endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000137if !exists("g:netrw_keepdir")
138 let g:netrw_keepdir= 1
139endif
140if !exists("g:netrw_list_cmd")
141 if executable(g:netrw_ssh_cmd)
142 " provide a default listing command
143 let g:netrw_list_cmd= g:netrw_ssh_cmd." HOSTNAME ls -FLa"
144 else
145" call Decho(g:netrw_ssh_cmd." is not executable, can't do remote directory exploring)
146 let g:netrw_list_cmd= ""
147 endif
148endif
149if !exists("g:netrw_list_hide")
150 let g:netrw_list_hide= ""
151endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000152" Default values - lh-lz ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000153if !exists("g:netrw_local_mkdir")
154 let g:netrw_local_mkdir= "mkdir"
155endif
156if !exists("g:netrw_local_rmdir")
157 let g:netrw_local_rmdir= "rmdir"
158endif
159if !exists("g:netrw_longlist")
160 let g:netrw_longlist= 0
161endif
162if g:netrw_longlist < 0 || g:netrw_longlist > 2
163 " sanity check
164 let g:netrw_longlist= 0
165endif
166if g:netrw_longlist == 1
167 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
168endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000169" Default values - m-r ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000170if !exists("g:netrw_maxfilenamelen")
171 let g:netrw_maxfilenamelen= 32
172endif
173if !exists("g:netrw_mkdir_cmd")
174 let g:netrw_mkdir_cmd= g:netrw_ssh_cmd." HOSTNAME mkdir"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000175endif
176if !exists("g:netrw_rename_cmd")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000177 let g:netrw_rename_cmd= g:netrw_ssh_cmd." HOSTNAME mv"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000178endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000179if !exists("g:netrw_rm_cmd")
180 let g:netrw_rm_cmd = g:netrw_ssh_cmd." HOSTNAME rm"
181endif
182if !exists("g:netrw_rmdir_cmd")
183 let g:netrw_rmdir_cmd = g:netrw_ssh_cmd." HOSTNAME rmdir"
184endif
185if !exists("g:netrw_rmf_cmd")
186 let g:netrw_rmf_cmd = g:netrw_ssh_cmd." HOSTNAME rm -f"
187endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000188" Default values - s ---------- {{{3
Bram Moolenaar843ee412004-06-30 16:16:41 +0000189if exists("g:netrw_silent") && g:netrw_silent != 0
190 let g:netrw_silentxfer= "silent "
191else
192 let g:netrw_silentxfer= ""
193endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000194if !exists("g:netrw_sort_by")
195 " alternatives: date size
196 let g:netrw_sort_by= "name"
197endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000198if !exists("g:netrw_sort_direction")
199 " alternative: reverse (z y x ...)
200 let g:netrw_sort_direction= "normal"
201endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000202if !exists("g:netrw_sort_sequence")
203 let g:netrw_sort_sequence= '[\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000204endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000205if !exists("g:netrw_ssh_browse_reject")
206 let g:netrw_ssh_browse_reject='^total\s\+\d\+$'
207endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000208" Default values - t-w ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000209if !exists("g:netrw_timefmt")
210 let g:netrw_timefmt= "%c"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000211endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000212if !exists("g:netrw_win95ftp")
213 let g:netrw_win95ftp= 1
214endif
215if !exists("g:netrw_winsize")
216 let g:netrw_winsize= ""
217endif
218" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000219" Default values for netrw's script variables: {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000220if !exists("s:netrw_cd_escape")
221 if has("win32") || has("win95") || has("win64") || has("win16")
222 let s:netrw_cd_escape="#% "
223 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000224 let s:netrw_cd_escape="[]#*$%'\" ?`!&();<>\\"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000225 endif
226endif
227if !exists("s:netrw_glob_escape")
228 if has("win32") || has("win95") || has("win64") || has("win16")
229 let s:netrw_glob_escape= ""
230 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000231 let s:netrw_glob_escape= '[]*?`{~$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000232 endif
233endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000234
235" BufEnter event ignored by decho when following variable is true
236" Has a side effect that doau BufReadPost doesn't work, so
237" files read by network transfer aren't appropriately highlighted.
238"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000240" ==============================
241" Netrw Utility Functions: {{{1
242" ==============================
243
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000245" NetSavePosn: saves position of cursor on screen {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000246fun! netrw#NetSavePosn()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000247" call Dfunc("NetSavePosn()")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248 " Save current line and column
Bram Moolenaar488c6512005-08-11 20:09:58 +0000249 let w:netrw_winnr= winnr()
250 let w:netrw_line = line(".")
251 let w:netrw_col = virtcol(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252
253 " Save top-of-screen line
254 norm! H0
Bram Moolenaar488c6512005-08-11 20:09:58 +0000255 let w:netrw_hline= line(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000257 call netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000258" 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 +0000259endfun
260
261" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000262" NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000263fun! netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000264" 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 +0000265 let eikeep= &ei
266 set ei=all
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267
Bram Moolenaar81695252004-12-29 20:58:21 +0000268 " restore window
Bram Moolenaar488c6512005-08-11 20:09:58 +0000269" call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w")
270 exe "silent! ".w:netrw_winnr."wincmd w"
Bram Moolenaar572cb562005-08-05 21:35:02 +0000271" if v:shell_error == 0
272" " as suggested by Bram M: redraw on no error
273" " allows protocol error messages to remain visible
274" redraw!
275" endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000276
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277 " restore top-of-screen line
Bram Moolenaar488c6512005-08-11 20:09:58 +0000278" call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z")
279 exe "norm! ".w:netrw_hline."G0z\<CR>"
Bram Moolenaar81695252004-12-29 20:58:21 +0000280
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281 " restore position
Bram Moolenaar488c6512005-08-11 20:09:58 +0000282" call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|")
283 exe "norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284
Bram Moolenaar572cb562005-08-05 21:35:02 +0000285 let &ei= eikeep
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000286" call Dret("NetRestorePosn")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287endfun
288
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000289" ===============================
290" Netrw Transfer Functions: {{{1
291" ===============================
292
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000294" NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000295fun! netrw#NetRead(...)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000296" call Dfunc("NetRead(a:1<".a:1.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000297
298 " save options
299 call s:NetOptionSave()
300
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000301 " Special Exception: if a file is named "0r", then {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000302 " "0r" will be used to read the
303 " following files instead of "r"
304 if a:0 == 0
305 let readcmd= "r"
306 let ichoice= 0
307 elseif a:1 == "0r"
308 let readcmd = "0r"
309 let ichoice = 2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000311 let readcmd = "r"
312 let ichoice = 1
313 endif
314
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000315 " get name of a temporary file and set up shell-quoting character {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000316 let tmpfile= tempname()
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000317 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000318 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000319 echohl Error | echo "***netrw*** your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!" | echohl None
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000320 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
321" call Dret("NetRead")
322 return
323 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000324
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000325" call Decho("ichoice=".ichoice." readcmd<".readcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000326 while ichoice <= a:0
327
328 " attempt to repeat with previous host-file-etc
329 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000330" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000331 let choice = b:netrw_lastfile
332 let ichoice= ichoice + 1
333
334 else
335 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000336" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000337
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000338 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000339 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000340 echomsg 'NetRead Usage:'
341 echomsg ':Nread machine:path uses rcp'
342 echomsg ':Nread "machine path" uses ftp with <.netrc>'
343 echomsg ':Nread "machine id password path" uses ftp'
344 echomsg ':Nread dav://machine[:port]/path uses cadaver'
345 echomsg ':Nread fetch://machine/path uses fetch'
346 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
347 echomsg ':Nread http://[user@]machine/path uses http wget'
348 echomsg ':Nread rcp://[user@]machine/path uses rcp'
349 echomsg ':Nread rsync://machine[:port]/path uses rsync'
350 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
351 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000352 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000353
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000354 elseif match(choice,"^\"") != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000355 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000356" call Decho("reconstructing choice")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000357 if match(choice,"\"$") != -1
358 " case "..."
359 let choice=strpart(choice,1,strlen(choice)-2)
360 else
361 " case "... ... ..."
362 let choice = strpart(choice,1,strlen(choice)-1)
363 let wholechoice = ""
364
365 while match(choice,"\"$") == -1
366 let wholechoice = wholechoice . " " . choice
367 let ichoice = ichoice + 1
368 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000369 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000370 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000371 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000372 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000373" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000374 return
375 endif
376 let choice= a:{ichoice}
377 endwhile
378 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
379 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380 endif
381 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000383" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000384 let ichoice= ichoice + 1
385
386 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000387 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000388 let choice = substitute(choice,'\\','/','ge')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000389" call Decho("fixing up windows url to <".choice."> tmpfile<".tmpfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000391 exe 'lcd ' . fnamemodify(tmpfile,':h')
392 let tmpfile = fnamemodify(tmpfile,':t')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000393 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000394
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000395 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000396 call s:NetMethod(choice)
397
Bram Moolenaar843ee412004-06-30 16:16:41 +0000398 " Check if NetBrowse() should be handling this request
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000399" call Decho("checking if netlist: choice<".choice."> netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000400 if choice =~ "^.*[\/]$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000401 keepjumps call s:NetBrowse(choice)
402" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000403 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000405
406 " use filename's suffix for the temporary file
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000407 if b:netrw_fname =~ '\.[^./]\+$'
408 let suffix = substitute(b:netrw_fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000409 let tmpfile= substitute(tmpfile,"$",suffix,'e')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000410" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000411 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000412
413 " ============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000414 " Perform Protocol-Based Read {{{3
415 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000416 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
417 echo "(netrw) Processing your read request..."
418 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000419
420 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000421 " rcp: NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000422 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000423" call Decho("read via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000424 " ER: noting done with g:netrw_uid yet?
425 " ER: on Win2K" rcp machine[.user]:file tmpfile
426 " ER: if machine contains '.' adding .user is required (use $USERNAME)
427 " ER: the tmpfile is full path: rcp sees C:\... as host C
428 if s:netrw_has_nt_rcp == 1
429 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
430 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
431 else
432 " Any way needed it machine contains a '.'
433 let uid_machine = g:netrw_machine .'.'. $USERNAME
434 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000436 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
437 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
438 else
439 let uid_machine = g:netrw_machine
440 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000442" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000443 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
444 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
445 let b:netrw_lastfile = choice
446
447 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000448 " ftp + <.netrc>: NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000449 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000450" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000451 let netrw_fname= b:netrw_fname
452 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000453 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000454 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000455" call Decho("filter input: ".getline("."))
456 exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'"
457" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000458 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000459" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000460 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
461 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000462" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000463 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
464 endif
465 " 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 +0000466 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000467 let debugkeep= &debug
468 set debug=msg
Bram Moolenaar572cb562005-08-05 21:35:02 +0000469 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000470 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000471 let &debug= debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000472 endif
473 bd!
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000475 let b:netrw_lastfile = choice
476
477 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000478 " ftp + machine,id,passwd,filename: NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000479 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
480 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000481" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482 let netrw_fname= b:netrw_fname
483 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000484 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000485 if exists("g:netrw_port") && g:netrw_port != ""
486 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000487" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000488 else
489 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000490" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000491 endif
492
493 if exists("g:netrw_ftp") && g:netrw_ftp == 1
494 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000495" call Decho("filter input: ".getline("."))
496 put ='\"'.g:netrw_passwd.'\"'
497" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000498 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000499 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
500" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000501 endif
502
503 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
504 put =g:netrw_ftpmode
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000505" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000506 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000507 put ='get \"'.netrw_fname.'\" '.tmpfile
508" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000509
510 " perform ftp:
511 " -i : turns off interactive prompting from ftp
512 " -n unix : DON'T use <.netrc>, even though it exists
513 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000514 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000515" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000516 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
517 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
518 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000519" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000520 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000521 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000522 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000523 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000524 endif
525 bd!
526 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
527 let b:netrw_lastfile = choice
528
529 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000530 " scp: NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000531 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000532" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000533 if exists("g:netrw_port") && g:netrw_port != ""
534 let useport= " -P ".g:netrw_port
535 else
536 let useport= ""
537 endif
538 if g:netrw_cygwin == 1
539 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000540" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."' ".cygtmpfile)
541 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."' ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000542 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000543" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."' ".tmpfile)
544 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."' ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000545 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000546 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000547 let b:netrw_lastfile = choice
548
549 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000550 " http: NetRead Method #5 (wget) {{{3
551 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000552" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000553 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000554 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000555 echohl Error | echo "***netrw*** neither wget nor fetch command is available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000556 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000557 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000558" call Dret("NetRead")
559 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000560 endif
561
562 if match(b:netrw_fname,"#") == -1
563 " simple wget
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000564" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000565 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&')
566 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
567
568 else
569 " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
570 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
571 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000572" call Decho("netrw_html<".netrw_html.">")
573" call Decho("netrw_tag <".netrw_tag.">")
574" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000575 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html
576 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000577" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000578 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
579 endif
580 let b:netrw_lastfile = choice
581
582 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000583 " cadaver: NetRead Method #6 {{{3
584 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000585" call Decho("read via cadaver (method #6)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000586
587 " Construct execution string (four lines) which will be passed through filter
588 let netrw_fname= b:netrw_fname
589 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000590 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000591 if exists("g:netrw_port") && g:netrw_port != ""
592 put ='open '.g:netrw_machine.' '.g:netrw_port
593 else
594 put ='open '.g:netrw_machine
595 endif
596 put ='user '.g:netrw_uid.' '.g:netrw_passwd
597
598 if g:netrw_cygwin == 1
599 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
600 put ='get '.netrw_fname.' '.cygtmpfile
601 else
602 put ='get '.netrw_fname.' '.tmpfile
603 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000604 put ='quit'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000605
606 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000607 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000608" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000609 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
610 bd!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000611 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000612 let b:netrw_lastfile = choice
613
614 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000615 " rsync: NetRead Method #7 {{{3
616 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000617" call Decho("read via rsync (method #7)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000618 if g:netrw_cygwin == 1
619 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000620" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000621 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
622 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000623" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000624 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
625 endif
626 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
627 let b:netrw_lastfile = choice
628
629 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000630 " fetch: NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000631 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000632 elseif b:netrw_method == 8
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000633 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000634 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000635 echohl Error | echo "***netrw*** fetch command not available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000636 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000637 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000638" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000639 endif
640 if exists("g:netrw_option") && g:netrw_option == ":http"
641 let netrw_option= "http"
642 else
643 let netrw_option= "ftp"
644 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000645" call Decho("read via fetch for ".netrw_option)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000646
647 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000648" 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 +0000649 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&')
650 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000651" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000652 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&')
653 endif
654
655 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
656 let b:netrw_lastfile = choice
657
658 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000659 " sftp: NetRead Method #9 {{{3
660 elseif b:netrw_method == 9
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000661" call Decho("read via sftp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000662 if g:netrw_cygwin == 1
663 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000664" call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
665" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000666 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile
667 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000668" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000669 exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile
670 endif
671 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
672 let b:netrw_lastfile = choice
673
674 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000675 " Complain {{{3
676 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000677 echo "***warning*** unable to comply with your request<" . choice . ">"
678 endif
679 endwhile
680
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000681 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000682" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000683 if exists("b:netrw_method")
684 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000685 unlet b:netrw_fname
686 endif
687 call s:NetOptionRestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +0000688
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000689" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000690endfun
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000691
692" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000693" NetGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000694fun! s:NetGetFile(readcmd, tfile, method)
695" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
696
697 " get name of remote filename (ie. url and all)
698 let rfile= bufname("%")
699" call Decho("rfile<".rfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000700
701 if exists("*NetReadFixup")
702 " for the use of NetReadFixup (not otherwise used internally)
703 let line2= line("$")
704 endif
705
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000706 " transform paths from / to \ for Windows (except for cygwin)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000707 if &term == "win32"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000708 if g:netrw_cygwin
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000709 let tfile= a:tfile
710" call Decho("(win32 && cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000711 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000712 let tfile= substitute(a:tfile,'/','\\\\','ge')
713" call Decho("(win32 && !cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000714 endif
715 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000716 let tfile= a:tfile
717" call Decho("tfile=a:tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000718 endif
719
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000720 if a:readcmd[0] == '0'
Bram Moolenaar81695252004-12-29 20:58:21 +0000721 " get file into buffer
Bram Moolenaar83bab712005-08-01 21:58:57 +0000722
Bram Moolenaar83bab712005-08-01 21:58:57 +0000723" call Dredir("ls!","starting buffer list")
724
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000725 " rename the current buffer to the temp file (ie. tfile)
726 keepalt exe "file ".tfile
727" call Dredir("ls!","after renaming current buffer to <".tfile.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +0000728
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000729 " edit temporary file (ie. read the temporary file in)
730 if rfile =~ '\.zip$'
731 call zip#Browse(tfile)
732 elseif rfile =~ '\.tar$'
733 call tar#Browse(tfile)
734 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000735" call Decho("edit temporary file")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000736 e
737 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +0000738
Bram Moolenaar81695252004-12-29 20:58:21 +0000739 " rename buffer back to remote filename
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000740 keepalt exe "file ".escape(rfile,' ')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000741 filetype detect
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000742" call Dredir("ls!","renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">")
Bram Moolenaar81695252004-12-29 20:58:21 +0000743 let line1 = 1
744 let line2 = line("$")
745
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000746 elseif filereadable(tfile)
Bram Moolenaar81695252004-12-29 20:58:21 +0000747 " read file after current line
748 let curline = line(".")
749 let lastline= line("$")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000750" call Decho("exe<".a:readcmd." ".v:cmdarg." ".tfile."> line#".curline)
751 exe a:readcmd." ".v:cmdarg." ".tfile
Bram Moolenaar81695252004-12-29 20:58:21 +0000752 let line1 = curline + 1
753 let line2 = line("$") - lastline + 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000754
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000755 else
Bram Moolenaar81695252004-12-29 20:58:21 +0000756 " not readable
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000757" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
758 echohl WarningMsg | echo "***netrw*** file <".tfile."> not readable"| echohl None
759 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
760" call Dret("NetGetFile : tfile<".tfile."> not readable")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000761 return
762 endif
763
764 " User-provided (ie. optional) fix-it-up command
765 if exists("*NetReadFixup")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000766" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000767 call NetReadFixup(a:method, line1, line2)
Bram Moolenaar83bab712005-08-01 21:58:57 +0000768" else " Decho
769" call Decho("NetReadFixup() not called, doesn't exist")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000770 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000771
772 " update the Buffers menu
773 if has("gui") && has("gui_running")
774 silent! emenu Buffers.Refresh\ menu
775 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000776
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000777" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".filereadable(a:tfile))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000778
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000779 " make sure file is being displayed
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000780 redraw!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000781" call Dret("NetGetFile")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000782endfun
783
784" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000785" NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000786fun! netrw#NetWrite(...) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000787" call Dfunc("NetWrite(a:0=".a:0.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000788
789 " option handling
790 let mod= 0
791 call s:NetOptionSave()
792
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000793 " Get Temporary Filename {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000794 let tmpfile= tempname()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000795 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
796 echohl Error | echo "***netrw*** your ".substitute(tmpfile,'[^/]\+$','','e')." directory is missing!"
797 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000798" call Dret("NetWrite")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000799 return
800 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000801
802 if a:0 == 0
803 let ichoice = 0
804 else
805 let ichoice = 1
806 endif
807
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000808 if &binary
809 " for binary writes, write entire file. Line numbers don't really make sense.
810 " Supports the writing of tar and zip files.
811" call Decho("silent exe w! ".v:cmdarg." ".tmpfile)
812 silent exe "w! ".v:cmdarg." ".tmpfile
813 else
814 " write (selected portion of) file to temporary
815" call Decho("silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile)
816 silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
817 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000818
819 while ichoice <= a:0
820
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000821 " Process arguments: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000822 " attempt to repeat with previous host-file-etc
823 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000824" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000825 let choice = b:netrw_lastfile
826 let ichoice= ichoice + 1
827 else
828 exe "let choice= a:" . ichoice
829
830 " Reconstruct Choice if choice starts with '"'
831 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000832 echomsg 'NetWrite Usage:"'
833 echomsg ':Nwrite machine:path uses rcp'
834 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
835 echomsg ':Nwrite "machine id password path" uses ftp'
836 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
837 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
838 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
839 echomsg ':Nwrite rcp://machine/path uses rcp'
840 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
841 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
842 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000843 break
844
845 elseif match(choice,"^\"") != -1
846 if match(choice,"\"$") != -1
847 " case "..."
848 let choice=strpart(choice,1,strlen(choice)-2)
849 else
850 " case "... ... ..."
851 let choice = strpart(choice,1,strlen(choice)-1)
852 let wholechoice = ""
853
854 while match(choice,"\"$") == -1
855 let wholechoice= wholechoice . " " . choice
856 let ichoice = ichoice + 1
857 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000858 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000859 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000860 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000861 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000862" call Dret("NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000863 return
864 endif
865 let choice= a:{ichoice}
866 endwhile
867 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
868 endif
869 endif
870 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000871" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000872 let ichoice= ichoice + 1
873
874 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000875 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000876 let choice= substitute(choice,'\\','/','ge')
877 "ER: see NetRead()
878 exe 'lcd ' . fnamemodify(tmpfile,':h')
879 let tmpfile = fnamemodify(tmpfile,':t')
880 endif
881
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000882 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000883 call s:NetMethod(choice)
884
885 " =============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000886 " Perform Protocol-Based Write {{{3
887 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000888 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
889 echo "(netrw) Processing your write request..."
890 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000891
892 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000893 " rcp: NetWrite Method #1 {{{3
894 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000895" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000896 if s:netrw_has_nt_rcp == 1
897 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
898 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
899 else
900 let uid_machine = g:netrw_machine .'.'. $USERNAME
901 endif
902 else
903 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
904 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
905 else
906 let uid_machine = g:netrw_machine
907 endif
908 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000909" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000910 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&')
911 let b:netrw_lastfile = choice
912
913 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000914 " ftp + <.netrc>: NetWrite Method #2 {{{3
915 elseif b:netrw_method == 2
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000916 let netrw_fname = b:netrw_fname
917 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000918 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000920" call Decho(" filter input: ".getline("."))
921 exe "put ='"."put ".tmpfile.' \"'.netrw_fname.'\"'."'"
922" call Decho(" filter input: ".getline("."))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000924" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000925 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000927" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000928 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 endif
930 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
931 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000932 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000933 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000934 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000935 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000936 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 endif
938 bd!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000939 let b:netrw_lastfile = choice
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000940
941 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000942 " ftp + machine, id, passwd, filename: NetWrite Method #3 {{{3
943 elseif b:netrw_method == 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000944 let netrw_fname= b:netrw_fname
945 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000946 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000947 if exists("g:netrw_port") && g:netrw_port != ""
948 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000949" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000950 else
951 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000952" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000953 endif
954 if exists("g:netrw_ftp") && g:netrw_ftp == 1
955 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000956" call Decho("filter input: ".getline("."))
957 put ='\"'.g:netrw_passwd.'\"'
958" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000959 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000960 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
961" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000962 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000963 put ='put '.tmpfile.' \"'.netrw_fname.'\"'
964" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000965 " save choice/id/password for future use
966 let b:netrw_lastfile = choice
967
968 " perform ftp:
969 " -i : turns off interactive prompting from ftp
970 " -n unix : DON'T use <.netrc>, even though it exists
971 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000972 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000973" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000974 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
975 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
976 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000977 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000978 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000979 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000980 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000981 let mod=1
982 endif
983 bd!
984
985 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000986 " scp: NetWrite Method #4 {{{3
987 elseif b:netrw_method == 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000988 if exists("g:netrw_port") && g:netrw_port != ""
989 let useport= " -P ".g:netrw_port
990 else
991 let useport= ""
992 endif
993 if g:netrw_cygwin == 1
994 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000995" call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."'")
996 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000997 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000998" call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."'")
999 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".escape(b:netrw_fname,' ?&')."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001000 endif
1001 let b:netrw_lastfile = choice
1002
1003 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001004 " http: NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001005 elseif b:netrw_method == 5
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001006 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001007 echohl Error | echo "***netrw*** currently <netrw.vim> does not support writing using http:" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001008 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001009 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001010
1011 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001012 " dav: NetWrite Method #6 (cadaver) {{{3
1013 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001014" call Decho("write via cadaver (method #6)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001015
1016 " Construct execution string (four lines) which will be passed through filter
1017 let netrw_fname= b:netrw_fname
1018 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001019 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001020 if exists("g:netrw_port") && g:netrw_port != ""
1021 put ='open '.g:netrw_machine.' '.g:netrw_port
1022 else
1023 put ='open '.g:netrw_machine
1024 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001026
1027 if g:netrw_cygwin == 1
1028 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
1029 put ='put '.cygtmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001031 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001033
1034 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001035 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001036" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001037 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
1038 bd!
1039 let b:netrw_lastfile = choice
1040
1041 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001042 " rsync: NetWrite Method #7 {{{3
1043 elseif b:netrw_method == 7
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001044 if g:netrw_cygwin == 1
1045 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001046" call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001047 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001049" call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001050 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001052 let b:netrw_lastfile = choice
1053
1054 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001055 " sftp: NetWrite Method #9 {{{3
1056 elseif b:netrw_method == 9
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001057 let netrw_fname= b:netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1059 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1060 else
1061 let uid_machine = g:netrw_machine
1062 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001063 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001064 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001066 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001067" call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001068 exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine
1069 bd!
1070 let b:netrw_lastfile= choice
1071
1072 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001073 " Complain {{{3
1074 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001075 echo "***warning*** unable to comply with your request<" . choice . ">"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001077 endwhile
1078
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001079 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001080" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001081 let result=delete(tmpfile)
1082 call s:NetOptionRestore()
1083
1084 if a:firstline == 1 && a:lastline == line("$")
1085 let &mod= mod " usually equivalent to set nomod
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001087
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001088" call Dret("NetWrite")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090
Bram Moolenaar83bab712005-08-01 21:58:57 +00001091" ===========================================
1092" Remote Directory Browsing Support: {{{1
1093" ===========================================
1094
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001095" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001096" NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001097" of the contents of a remote directory. It is assumed that the
1098" g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted
1099" with the requested remote hostname first.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001100fun! s:NetBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001101 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
1102" call Dfunc("NetBrowse(dirname<".a:dirname.">) longlist=".w:netrw_longlist)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001103
Bram Moolenaar488c6512005-08-11 20:09:58 +00001104 if exists("s:netrw_skipbrowse")
1105 unlet s:netrw_skipbrowse
1106" call Dret("NetBrowse")
1107 return
1108 endif
1109
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001110 call s:NetOptionSave()
1111
Bram Moolenaar843ee412004-06-30 16:16:41 +00001112 " sanity check
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001113 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
1114" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001115 if !executable("ftp")
1116 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001117 echohl Error | echo "***netrw*** this system doesn't support remote directory listing via ftp" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001118 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001119 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001120 call s:NetOptionRestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001121" call Dret("NetBrowse")
1122 return
1123 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001124 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001125 if !exists("g:netrw_quiet")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001126 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 +00001127 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001128 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001129
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001130 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001131" call Dret("NetBrowse")
1132 return
Bram Moolenaar843ee412004-06-30 16:16:41 +00001133 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001134
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001135 " use buffer-oriented WinVars if buffer ones exist but window ones don't
1136 call s:UseBufWinVars()
1137
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001138 " make this buffer modifiable
Bram Moolenaar83bab712005-08-01 21:58:57 +00001139 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001140
1141 " analyze a:dirname and g:netrw_list_cmd
1142 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001143 let dirname = substitute(a:dirname,'\\','/','ge')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001144" call Decho("dirname<".dirname.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001145 if dirname !~ dirpat
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001146 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001147 echohl Error | echo "***netrw*** netrw doesn't understand your dirname<".dirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001148 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001149 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001150 call s:NetOptionRestore()
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001151" call Dret("NetBrowse : badly formatted dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001152 return
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001153 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001154
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001155 let method = substitute(dirname,dirpat,'\1','')
1156 let user = substitute(dirname,dirpat,'\2','')
1157 let machine = substitute(dirname,dirpat,'\3','')
1158 let path = substitute(dirname,dirpat,'\4','')
1159 let fname = substitute(dirname,'^.*/\ze.','','')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001160" call Decho("set up method <".method .">")
1161" call Decho("set up user <".user .">")
1162" call Decho("set up machine<".machine.">")
1163" call Decho("set up path <".path .">")
1164" call Decho("set up fname <".fname .">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001165
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001166 if method == "ftp" || method == "http"
1167 let method = "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001168 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001169 else
1170 let listcmd = substitute(g:netrw_list_cmd,'\<HOSTNAME\>',user.machine,'')
1171 endif
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001172
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001173 if exists("b:netrw_method")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001174" call Decho("setting w:netrw_method<".b:netrw_method.">")
1175 let w:netrw_method= b:netrw_method
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001176 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001177
Bram Moolenaar8299df92004-07-10 09:47:34 +00001178 " optionally sort by time (-t) or by size (-S)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001179 if listcmd == "dir" && g:netrw_sort_by =~ "^[ts]"
Bram Moolenaar572cb562005-08-05 21:35:02 +00001180 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 +00001181 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001182 else
1183 if g:netrw_sort_by =~ "^t"
1184 let listcmd= listcmd."t"
1185 elseif g:netrw_sort_by =~ "^s"
1186 let listcmd= listcmd."S"
1187 endif
1188 " optionally sort in reverse
1189 if g:netrw_sort_direction =~ "^r" && listcmd == "dir"
1190 let listcmd= listcmd."r"
1191 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001192 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001193
1194" call Decho("set up listcmd<".listcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001195 if fname =~ '@$' && fname !~ '^"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001196" call Decho("attempt transfer of symlink as file")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001197 call s:NetBrowse(substitute(dirname,'@$','','e'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001198 redraw!
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001199 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001200" call Dret("NetBrowse : symlink")
1201 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001202
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001203 elseif fname !~ '[\/]$' && fname !~ '^"'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001204 " looks like a regular file, attempt transfer
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001205" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001206
1207 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001208 " "this is a directory" indicator (/). There shouldn't be one of those,
1209 " anyway.
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001210 let path= substitute(path,'[*=@|]\r\=$','','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001211" call Decho("new path<".path.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001212
1213 " remote-read the requested file into current buffer
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001214 keepjumps keepalt enew!
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001215 set ma
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001216" call Decho("exe file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001217 exe "file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001218 exe "silent doau BufReadPre ".fname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001219 silent call netrw#NetRead(method."://".user.machine."/".path)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001220 exe "silent doau BufReadPost ".fname
Bram Moolenaar8299df92004-07-10 09:47:34 +00001221 keepjumps 1d
Bram Moolenaar572cb562005-08-05 21:35:02 +00001222
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001223 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001224 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001225 call s:NetOptionRestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001226 setlocal nomod
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001227
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001228" call Dret("NetBrowse : file<".fname.">")
1229 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001230 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001231
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001232 " ---------------------------------------------------------------------
1233 " Perform Directory Listing:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001234" call Decho("Perform directory listing...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001235 " set up new buffer and map
1236 let bufname = method.'://'.user.machine.'/'.path
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001237 let bufnamenr = bufnr(bufname.'$')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001238" call Decho("bufname<".bufname."> bufnamenr=".bufnamenr)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001239 if bufnamenr != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001240 " buffer already exists, switch to it!
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001241" call Decho("buffer already exists, switching to it")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001242 exe "b ".bufnamenr
1243 if line("$") >= 5
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001244 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001245" call Dret("NetBrowse")
1246 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001247 endif
1248 else
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001249" call Decho("generate a new buffer")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001250 keepjumps keepalt enew!
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001251 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001252
1253 " rename file to reflect where its from
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001254 setlocal bt=nofile bh=wipe nobl noswf
1255 exe "setlocal ts=".g:netrw_maxfilenamelen
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001256" call Decho("exe file ".escape(bufname,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001257 exe 'file '.escape(bufname,s:netrw_cd_escape)
Bram Moolenaar269ec652004-07-29 08:43:53 +00001258" call Decho("renaming file to bufname<".bufname.">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001259 setlocal bh=hide bt=nofile nobl nonu noswf
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001260
1261 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001262 call s:NetBookmarkDir(3,expand("%"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001263
1264 " set up buffer-local mappings
1265" call Decho("set up buffer-local mappings")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001266 nnoremap <buffer> <silent> <cr> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001267 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>NetBrowseChgDir(expand("%"),'./'),0)<cr>
Bram Moolenaar843ee412004-06-30 16:16:41 +00001268 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'../'))<cr>
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001269 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 +00001270 if w:netrw_longlist != 2
1271 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1272 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,expand("%"))<cr>
1273 endif
1274 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1275 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001276 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(0)<cr>
1277 nnoremap <buffer> <silent> i :call <SID>NetLongList(0)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001278 nnoremap <buffer> <silent> o :call <SID>NetSplit(0)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001279 nnoremap <buffer> <silent> O :call <SID>NetObtain()<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001280 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(0)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001281 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,expand("%"))<cr>
1282 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>
1283 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>
1284 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001285 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
1286 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001287 nnoremap <buffer> <silent> v :call <SID>NetSplit(1)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001288 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()),1)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001289 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001290 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001291 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001292 exe 'nnoremap <buffer> <silent> d :call <SID>NetMakeDir("'.user.machine.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001293 exe 'nnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001294 exe 'vnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001295 exe 'nnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00001296 exe 'vnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar8299df92004-07-10 09:47:34 +00001297 nnoremap <buffer> ? :he netrw-browse-cmds<cr>
Bram Moolenaar83bab712005-08-01 21:58:57 +00001298 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001299
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001300 " Set up the banner
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001301" call Decho("set up the banner: sortby<".g:netrw_sort_by."> method<".method.">")
1302 keepjumps put ='\" ==========================================================================='
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001303 keepjumps put ='\" Netrw Remote Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001304 keepjumps put ='\" '.bufname
Bram Moolenaar488c6512005-08-11 20:09:58 +00001305 let w:netrw_bannercnt = 7
1306 let sortby = g:netrw_sort_by
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001307 if g:netrw_sort_direction =~ "^r"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001308 let sortby = sortby." reversed"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001309 endif
1310
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001311 if g:netrw_sort_by =~ "^n"
1312 " sorted by name
Bram Moolenaar488c6512005-08-11 20:09:58 +00001313 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001314 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001315 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
1316 else
1317 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001318 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001319 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001320 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001321" call Decho("g:netrw_hide=".g:netrw_hide)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001322 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001323 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001324 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001325 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001326 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00001327 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar843ee412004-06-30 16:16:41 +00001328 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001329 keepjumps put ='\" Quick Help: ?:help -:go up dir D:delete R:rename s:sort-by x:exec'
1330 keepjumps put ='\" ==========================================================================='
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001331
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001332 " remote read the requested directory listing
1333 " Use ftp if that was the file-transfer method selected, otherwise use ssh
1334 " Note that not all ftp servers honor the options for ls
1335 if method == "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001336 " use ftp to get remote file listing
1337" call Decho("use ftp to get remote file listing")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001338 call s:NetBrowseFtpCmd(path,listcmd)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001339 keepjumps 1d
1340
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001341 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001342 " shorten the listing
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001343" call Decho("generate short listing")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001344 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001345
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001346 " cleanup
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001347 if g:netrw_ftp_browse_reject != ""
1348 exe "silent! g/".g:netrw_ftp_browse_reject."/keepjumps d"
1349 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001350 silent! keepjumps %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001351
1352 " if there's no ../ listed, then put ./ and ../ in
1353 let line1= line(".")
1354 keepjumps 1
1355 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1356 let line2= line(".")
1357 if line2 == 0
1358 keepjumps put='../'
1359 keepjumps put='./'
1360 endif
1361 exe "keepjumps ".line1
1362 keepjumps norm! 0
1363
1364 " more cleanup
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001365 exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
1366 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
1367 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001368 endif
1369
1370 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001371 " use ssh to get remote file listing
1372" call Decho("use ssh to get remote file listing")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001373 let shq= &shq? &shq : ( &sxq? &sxq : "'")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001374" call Decho("exe silent r! ".listcmd." '".shq.escape(path,s:netrw_cd_escape).shq."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001375 exe "silent r! ".listcmd." ".shq.escape(path,s:netrw_cd_escape).shq
1376 keepjumps 1d
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001377 " cleanup
1378 if g:netrw_ftp_browse_reject != ""
1379 exe "silent! g/".g:netrw_ssh_browse_reject."/keepjumps d"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001380 endif
1381 endif
1382
1383 " set up syntax highlighting
1384 if has("syntax")
1385 setlocal ft=netrwlist
Bram Moolenaar572cb562005-08-05 21:35:02 +00001386 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001387 setlocal ft=
Bram Moolenaar572cb562005-08-05 21:35:02 +00001388 " Ugly workaround -- when syntax highlighting is off and laststatus==2,
1389 " sometimes the laststatus highlight bleeds into the entire display.
1390 " Only seems to happen with remote browsing. Weird.
1391 redraw
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001392 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001393 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001394
1395 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001396 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00001397 if g:netrw_hide && g:netrw_list_hide != ""
1398 call s:NetrwListHide()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001399 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001400
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001401 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00001402 " do a long listing; these substitutions need to be done prior to sorting
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001403" call Decho("manipulate long listing")
1404
1405 if method == "ftp"
1406 " cleanup
Bram Moolenaar488c6512005-08-11 20:09:58 +00001407 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar572cb562005-08-05 21:35:02 +00001408 while getline(".") =~ g:netrw_ftp_browse_reject
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001409 keepjumps d
1410 endwhile
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001411 " if there's no ../ listed, then put ./ and ../ in
1412 let line1= line(".")
1413 keepjumps 1
1414 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1415 let line2= line(".")
1416 if line2 == 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00001417 exe 'keepjumps '.w:netrw_bannercnt."put='./'"
1418 exe 'keepjumps '.w:netrw_bannercnt."put='../'"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001419 endif
1420 exe "keepjumps ".line1
1421 keepjumps norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001422 endif
1423
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001424 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/ -> .*$//e'
1425 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
1426 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar8299df92004-07-10 09:47:34 +00001427 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001428
Bram Moolenaar488c6512005-08-11 20:09:58 +00001429 if line("$") >= w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001430 if g:netrw_sort_by =~ "^n"
1431 call s:SetSort()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001432 if g:netrw_sort_direction =~ 'n'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001433 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001434 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001435 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
Bram Moolenaar83bab712005-08-01 21:58:57 +00001436 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001437 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001438 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001439 if w:netrw_longlist == 1
1440 " shorten the list to keep its width <= winwidth characters
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001441 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\t[-dstrwx]\+/\t/e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001442 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001443 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001444 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001445
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001446 call s:NetrwWideListing()
1447 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001448 " place cursor on the top-left corner of the file listing
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001449 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001450 norm! 0
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001451 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001452
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001453 call s:NetOptionRestore()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001454 setlocal nomod noma nonu
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001455
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001456" call Dret("NetBrowse")
1457 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001458endfun
1459
1460" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001461" NetBrowseChgDir: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001462fun! s:NetBrowseChgDir(dirname,newdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001463" call Dfunc("NetBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001464
1465 let dirname= a:dirname
Bram Moolenaar843ee412004-06-30 16:16:41 +00001466 let newdir = a:newdir
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001467
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001468 if newdir !~ '[\/]$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001469 " handling a file
1470 let dirname= dirname.newdir
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001471 if g:netrw_browse_split == 1
1472 new
1473 wincmd _
1474 elseif g:netrw_browse_split == 2
1475 rightb vert new
1476 wincmd |
1477 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001478" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001479
1480 elseif newdir == './'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001481 " refresh the directory list
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001482" call Decho("refresh directory listing")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001483 setlocal ma nobl bh=hide
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001484 %d
1485
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001486 elseif newdir == '../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001487 " go up one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001488 let trailer= substitute(a:dirname,'^\(\w\+://\%(\w\+@\)\=\w\+/\)\(.*\)$','\2','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001489
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001490 if trailer =~ '^\%(\.\./\)*$'
1491 " tack on a ../"
1492 let dirname= dirname.'../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001493
1494 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001495 " strip off a directory name from dirname
1496 let dirname= substitute(dirname,'^\(.*/\)[^/]\+/','\1','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001497 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001498" call Decho("go up one dir: dirname<".dirname."> trailer<".trailer.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001499
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001500 else
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001501 " go down one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001502 let dirname= dirname.newdir
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001503" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001504 endif
1505
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001506" call Dret("NetBrowseChgDir <".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001507 return dirname
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001508endfun
1509
Bram Moolenaar843ee412004-06-30 16:16:41 +00001510" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001511" NetGetWord: it gets the directory named under the cursor {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001512fun! s:NetGetWord()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001513" call Dfunc("NetGetWord() line#".line("."))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001514 call s:UseBufWinVars()
1515
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001516 " insure that w:netrw_longlist is set up
1517 if !exists("w:netrw_longlist")
1518 if exists("g:netrw_longlist")
1519 let w:netrw_longlist= g:netrw_longlist
1520 else
1521 let w:netrw_longlist= 0
1522 endif
1523 endif
1524
Bram Moolenaar488c6512005-08-11 20:09:58 +00001525 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001526 " Active Banner support
1527" call Decho("active banner handling")
1528 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001529 let dirname= "./"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001530 let curline= getline(".")
1531 if curline =~ '"\s*Sorted by\s'
1532 norm s
1533 let s:netrw_skipbrowse= 1
1534 echo 'Pressing "s" also works'
1535 elseif curline =~ '"\s*Sort sequence:'
1536 let s:netrw_skipbrowse= 1
1537 echo 'Press "S" to edit sorting sequence'
1538 elseif curline =~ '"\s*Quick Help:'
1539 norm ?
1540 let s:netrw_skipbrowse= 1
1541 echo 'Pressing "?" also works'
1542 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
1543 norm a
1544 let s:netrw_skipbrowse= 1
1545 echo 'Pressing "a" also works'
1546 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001547 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00001548 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001549
1550 elseif w:netrw_longlist == 0
1551" call Decho("thin column handling")
1552 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001553 let dirname= getline(".")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001554
1555 elseif w:netrw_longlist == 1
1556" call Decho("long column handling")
1557 norm! 0
1558 let dirname= substitute(getline("."),'^\(\%(\S\+\s\)*\S\+\).\{-}$','\1','e')
1559
1560 else
1561" call Decho("obtain word from wide listing")
1562 let dirname= getline(".")
1563
1564 if !exists("b:netrw_cpf")
1565 let b:netrw_cpf= 0
1566 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
1567" call Decho("computed cpf")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001568 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001569
1570 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
1571" call Decho("virtcol=".virtcol(".")." cpf=".b:netrw_cpf." bannercnt=".w:netrw_bannercnt." filestart=".filestart)
1572" call Decho("1: dirname<".dirname.">")
1573 if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif
1574" call Decho("2: dirname<".dirname.">")
1575 let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e')
1576" call Decho("3: dirname<".dirname.">")
1577 let dirname = substitute(dirname,'\s\+$','','e')
1578" call Decho("4: dirname<".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001579 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001580
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001581" call Dret("NetGetWord <".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001582 return dirname
1583endfun
1584
1585" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001586" NetBrowseRm: remove/delete a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001587fun! s:NetBrowseRm(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001588" call Dfunc("NetBrowseRm(usrhost<".a:usrhost."> path<".a:path.">)")
1589" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001590
1591 " preparation for removing multiple files/directories
1592 let ctr= a:firstline
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001593 let all= 0
Bram Moolenaar843ee412004-06-30 16:16:41 +00001594
1595 " remove multiple files and directories
1596 while ctr <= a:lastline
1597 exe ctr
1598
1599 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001600 let rmfile= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001601" call Decho("rmfile<".rmfile.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001602
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001603 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar843ee412004-06-30 16:16:41 +00001604 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001605 if !all
1606 echohl Statement
1607 call inputsave()
1608 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1609 call inputrestore()
1610 echohl NONE
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 Moolenaard4755bb2004-09-02 19:12:26 +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 Moolenaard4755bb2004-09-02 19:12:26 +00001622 silent! keepjumps .,$d
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001623 call s:NetBrowseFtpCmd(a:path,"delete ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001624 else
1625 let netrw_rm_cmd= substitute(g:netrw_rm_cmd,'HOSTNAME',a:usrhost,'').' "'.escape(a:path.rmfile,s:netrw_cd_escape).'"'
1626" call Decho("attempt to remove file: system(".netrw_rm_cmd.")")
1627 let ret= system(netrw_rm_cmd)
1628" call Decho("returned=".ret." errcode=".v:shell_error)
1629 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001630 elseif ok =~ 'q\%[uit]'
1631 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001632 endif
1633
1634 else
1635 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001636 if !all
1637 call inputsave()
1638 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1639 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001640 if ok == ""
1641 let ok="no"
1642 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001643 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1644 if ok =~ 'a\%[ll]'
1645 let all= 1
1646 endif
1647 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001648
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001649 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001650 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001651 call s:NetBrowseFtpCmd(a:path,"rmdir ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001652 else
1653 let rmfile = a:path.rmfile
1654 let netrw_rmdir_cmd= substitute(g:netrw_rmdir_cmd,'HOSTNAME',a:usrhost,'').' '."'".'"'.rmfile.'"'."'"
1655" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
1656 let ret= system(netrw_rmdir_cmd)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001657" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001658
1659 if v:shell_error != 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001660 let netrw_rmf_cmd= substitute(g:netrw_rmf_cmd,'HOSTNAME',a:usrhost,'').' '.substitute(rmfile,'[\/]$','','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001661" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
1662 let ret= system(netrw_rmf_cmd)
1663" call Decho("returned=".ret." errcode=".v:shell_error)
1664
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001665 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001666 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001667 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001668 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001669 endif
1670 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001671
1672 elseif ok =~ 'q\%[uit]'
1673 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001674 endif
1675 endif
1676
1677 let ctr= ctr + 1
1678 endwhile
1679
1680 " refresh the directory
1681 let curline= line(".")-1
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001682" call Decho("refresh the directory")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001683 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar843ee412004-06-30 16:16:41 +00001684 exe curline
1685
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001686" call Dret("NetBrowseRm")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001687endfun
1688
1689" ---------------------------------------------------------------------
1690" NetBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001691fun! s:NetBrowseRename(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001692" call Dfunc("NetBrowseRename(usrhost<".a:usrhost."> path<".a:path.">)")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001693
1694 " preparation for removing multiple files/directories
1695 let ctr = a:firstline
1696 let rename_cmd = substitute(g:netrw_rename_cmd,'\<HOSTNAME\>',a:usrhost,'')
1697
1698 " attempt to rename files/directories
1699 while ctr <= a:lastline
Bram Moolenaar8299df92004-07-10 09:47:34 +00001700 exe "keepjumps ".ctr
Bram Moolenaar843ee412004-06-30 16:16:41 +00001701
1702 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001703 let oldname= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001704" call Decho("oldname<".oldname.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001705
1706 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001707 let newname= input("Moving ".oldname." to : ",oldname)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001708 call inputrestore()
1709
Bram Moolenaar488c6512005-08-11 20:09:58 +00001710 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001711 call s:NetBrowseFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001712 else
1713 let oldname= a:path.oldname
1714 let newname= a:path.newname
1715" call Decho("system(rename_cmd".' "'.escape(oldname," ").'" "'.escape(newname,s:netrw_cd_escape).'"')
1716 let ret= system(rename_cmd.' "'.escape(oldname,s:netrw_cd_escape).'" "'.escape(newname,s:netrw_cd_escape).'"')
1717 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001718
1719 let ctr= ctr + 1
1720 endwhile
1721
1722 " refresh the directory
1723 let curline= line(".")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001724 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001725 exe "keepjumps ".curline
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001726" call Dret("NetBrowseRename")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001727endfun
1728
1729" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00001730" NetRefresh: {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001731fun! s:NetRefresh(dirname,islocal)
1732" call Dfunc("NetRefresh(dirname<".a:dirname.">,islocal=".a:islocal.")")
1733 call netrw#NetSavePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001734 set ma
1735 %d
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001736 if a:islocal
1737 call s:LocalBrowse(a:dirname)
1738 else
1739 call s:NetBrowse(a:dirname)
1740 endif
1741 call netrw#NetRestorePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001742 redraw!
1743" call Dret("NetRefresh")
1744endfun
1745
1746" ---------------------------------------------------------------------
Bram Moolenaar488c6512005-08-11 20:09:58 +00001747" NetSplit: mode {{{2
1748" =0 : net and o
1749" =1 : net and v
1750" =2 : local and o
1751" =3 : local and v
1752fun! s:NetSplit(mode)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001753" call Dfunc("NetSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001754
1755 call s:SaveWinVars()
1756 if a:mode == 0
1757 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1758 call s:CopyWinVars()
1759 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001760 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001761 elseif a:mode ==1
1762 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1763 call s:CopyWinVars()
1764 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001765 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001766 elseif a:mode ==2
1767 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1768 call s:CopyWinVars()
1769 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001770 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001771 else
1772 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1773 call s:CopyWinVars()
1774 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001775 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001776 endif
1777
1778" call Dret("NetSplit")
1779endfun
1780
1781" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001782" NetBrowseX: allows users to write custom functions to operate on {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00001783" files given their extension. Passes 0=local, 1=remote
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001784fun! netrw#NetBrowseX(fname,remote)
1785" call Dfunc("NetBrowseX(fname<".a:fname."> remote=".a:remote.")")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001786
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001787 " set up the filename
1788 " (lower case the extension, make a local copy of a remote file)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001789 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001790 if has("win32") || has("win95") || has("win64") || has("win16")
1791 let exten= substitute(exten,'^.*$','\L&\E','')
1792 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001793 let fname= escape(a:fname,"%#")
1794" call Decho("fname<".fname."> after escape()")
1795
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001796 " seems kde systems often have gnome-open due to dependencies, even though
1797 " gnome-open's subsidiary display tools are largely absent. Kde systems
1798 " usually have "kicker" running, though... (tnx Mikolaj Machowski)
1799 if !exists("s:haskicker")
1800 if has("unix")
1801 let v:shell_error=0
1802 silent! let s:haskicker= system('ps -e') =~ 'kicker'
1803 if v:shell_error
1804 let s:haskicker = 0
1805 let v:shell_error = 0
1806 endif
1807 else
1808 let s:haskicker= 0
1809 endif
1810" call Decho("setting s:haskicker=".s:haskicker)
1811 endif
1812
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001813 if a:remote == 1
1814 " create a local copy
1815 let fname= tempname().".".exten
1816" call Decho("create a local copy of <".a:fname."> as <".fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001817 exe "silent keepjumps bot 1new ".a:fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001818 set bh=delete
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001819 exe "w! ".fname
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001820 q
1821 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001822" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001823
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001824 " set up redirection
1825 if &srr =~ "%s"
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00001826 let redir= substitute(&srr,"%s","/dev/null","")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001827 else
1828 let redir= &srr . "/dev/null"
1829 endif
1830" call Decho("redir:".redir.":")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001831
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001832 if exists("g:netrw_browsex_viewer") && executable(g:netrw_browsex_viewer)
1833 if g:netrw_browsex_viewer == '-'
1834 call netrwFileHandlers#Init()
1835 if exten != "" && exists("*netrwFileHandlers#NFH_".exten)
1836" call Decho("let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")')
1837 exe "let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")'
1838 endif
1839 else
1840" call Decho("exe silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."' ".redir)
1841 exe "silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."'".redir
1842 let ret= v:shell_error
1843 endif
1844
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001845 " execute the file handler
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001846 elseif has("win32") || has("win64")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001847" call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"')
1848 exe 'silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"'
1849 let ret= v:shell_error
1850
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001851 elseif has("unix") && executable("gnome-open") && !s:haskicker
Bram Moolenaara5792f52005-11-23 21:25:05 +00001852" call Decho("exe silent !gnome-open '".escape(fname,'%#')."' ".redir)
1853 exe "silent !gnome-open '".escape(fname,'%#')."'".redir
1854 let ret= v:shell_error
1855
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001856 elseif has("unix") && executable("kfmclient") && s:haskicker
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001857" call Decho("exe silent !kfmclient exec '".escape(fname,'%#')."' ".redir)
1858 exe "silent !kfmclient exec '".escape(fname,'%#')."' ".redir
1859 let ret= v:shell_error
1860
1861 else
1862 call netrwFileHandlers#Init()
1863 if exten != "" && exists("*netrwFileHandlers#NFH_".exten)
1864" call Decho("let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")')
1865 exe "let ret= netrwFileHandlers#NFH_".exten.'("'.fname.'")'
1866 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001867 endif
1868 redraw!
Bram Moolenaar8299df92004-07-10 09:47:34 +00001869
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001870 " cleanup: remove temporary file,
1871 " delete current buffer if success with handler,
1872 " return to prior buffer (directory listing)
1873 if a:remote == 1 && fname != a:fname
1874" call Decho("deleting temporary file<".fname.">")
1875 call delete(fname)
1876 endif
1877
1878 if a:remote == 1
Bram Moolenaar572cb562005-08-05 21:35:02 +00001879 set bh=delete bt=nofile noswf
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001880 exe "norm! \<c-o>"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001881 redraw!
Bram Moolenaar843ee412004-06-30 16:16:41 +00001882 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001883
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001884" call Dret("NetBrowseX")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001885endfun
1886
1887" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001888" NetBrowseFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
1889" This function assumes that a long listing will be received. Size, time,
1890" and reverse sorts will be requested of the server but not otherwise
1891" enforced here.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001892fun! s:NetBrowseFtpCmd(path,cmd)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001893" call Dfunc("NetBrowseFtpCmd(path<".a:path."> cmd<".a:cmd.">) netrw_method=".w:netrw_method)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001894
1895 " because WinXX ftp uses unix style input
1896 " curline is one more than the bannercnt in order to account
1897 " for the unwanted first blank line (doing a :put to an empty
1898 " buffer yields a blank first line)
1899 let ffkeep= &ff
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001900 setlocal ma ff=unix
Bram Moolenaar488c6512005-08-11 20:09:58 +00001901 let curline= w:netrw_bannercnt+1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001902 exe "silent! keepjumps ".curline.",$d"
1903
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001904 ".........................................
1905 if w:netrw_method == 2 || w:netrw_method == 5
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001906 " ftp + <.netrc>: Method #2
1907 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001908 put ='cd \"'.a:path.'\"'
1909" call Decho('ftp: '.getline("."))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001910 endif
1911 exe "put ='".a:cmd."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001912" call Decho("ftp: ".getline("."))
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001913" redraw!|call inputsave()|call input("Pausing...")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001914 if exists("g:netrw_port") && g:netrw_port != ""
1915" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
1916 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
1917 else
1918" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
1919 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
1920 endif
1921
1922 ".........................................
Bram Moolenaar488c6512005-08-11 20:09:58 +00001923 elseif w:netrw_method == 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001924 " ftp + machine,id,passwd,filename: Method #3
1925 setlocal ff=unix
1926 if exists("g:netrw_port") && g:netrw_port != ""
1927 put ='open '.g:netrw_machine.' '.g:netrw_port
1928 else
1929 put ='open '.g:netrw_machine
1930 endif
1931
1932 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1933 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001934 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001935 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001936 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001937 endif
1938
1939 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001940 put ='cd \"'.a:path.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001941 endif
1942 exe "put ='".a:cmd."'"
1943
1944 " perform ftp:
1945 " -i : turns off interactive prompting from ftp
1946 " -n unix : DON'T use <.netrc>, even though it exists
1947 " -n win32: quit being obnoxious about password
1948" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
1949 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n"
1950
1951 ".........................................
1952 else
1953 echo "***warning*** unable to comply with your request<" . choice . ">"
1954 endif
1955
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001956 " cleanup for Windows
1957 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001958 silent! keepjumps! %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001959 endif
1960 if a:cmd == "dir"
1961 " infer directory/link based on the file permission string
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001962 silent! keepjumps g/d\%([-r][-w][-x]\)\{3}/s@$@/@
1963 silent! keepjumps g/l\%([-r][-w][-x]\)\{3}/s/$/@/
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001964 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001965 exe "silent! keepjumps ".curline.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001966 endif
1967 endif
1968
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001969 " ftp's ls doesn't seem to include ./ or ../
1970 if !search('^\.\/$','wn')
1971 exe 'keepjumps '.curline
1972 if a:path !~ '^$'
1973 put ='../'
1974 endif
1975 put ='./'
1976 exe 'keepjumps '.curline
1977 endif
1978
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001979 " restore settings
1980 let &ff= ffkeep
1981" call Dret("NetBrowseFtpCmd")
1982endfun
1983
1984" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001985" NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
1986" separated patterns given in g:netrw_list_hide
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001987fun! s:NetrwListHide()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001988" call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001989
1990 let listhide= g:netrw_list_hide
1991 while listhide != ""
1992 if listhide =~ ','
1993 let hide = substitute(listhide,',.*$','','e')
1994 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
1995 else
1996 let hide = listhide
1997 let listhide= ""
1998 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001999
2000 " Prune the list by hiding any files which match
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002001 if g:netrw_hide == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002002" call Decho("hiding<".hide."> listhide<".listhide.">")
2003" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d')
2004 exe 'silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002005 elseif g:netrw_hide == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002006" call Decho("showing<".hide."> listhide<".listhide.">")
2007" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d')
2008 exe 'silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002009 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00002010 endwhile
2011
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002012" call Dret("NetrwListHide")
2013endfun
2014
2015" ---------------------------------------------------------------------
2016" NetHideEdit: allows user to edit the file/directory hiding list
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002017fun! s:NetHideEdit(islocal)
2018" call Dfunc("NetHideEdit(islocal=".a:islocal.")")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002019
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002020 " get new hiding list from user
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002021 call inputsave()
2022 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
2023 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002024 let g:netrw_list_hide= newhide
2025" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002026
2027 " refresh the listing
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002028 if a:islocal == 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00002029 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2030 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002031 silent call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,"./"),a:islocal)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002032 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002033
2034" call Dret("NetHideEdit")
Bram Moolenaar843ee412004-06-30 16:16:41 +00002035endfun
2036
Bram Moolenaar8299df92004-07-10 09:47:34 +00002037" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002038" NetSortSequence: allows user to edit the sorting sequence
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002039fun! s:NetSortSequence(mode)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002040" call Dfunc("NetSortSequence(mode=".a:mode.")")
2041
2042 call inputsave()
2043 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
2044 call inputrestore()
2045
2046 " refresh the listing
2047 let g:netrw_sort_sequence= newsortseq
2048 if a:mode == 0
2049 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2050 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002051 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002052 endif
2053
2054" call Dret("NetSortSequence")
2055endfun
2056
2057" ---------------------------------------------------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002058" NetLongList: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002059fun! s:NetLongList(mode)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002060" call Dfunc("NetLongList(mode=".a:mode.") netrw_longlist=".w:netrw_longlist)
2061 let fname = s:NetGetWord()
2062 let w:netrw_longlist = (w:netrw_longlist + 1) % 3
2063" call Decho("fname<".fname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002064
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002065 if w:netrw_longlist == 0
2066 " use one column listing
2067" call Decho("use one column list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002068 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2069
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002070 elseif w:netrw_longlist == 1
2071 " use long list
2072" call Decho("use long list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002073 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002074
2075 else
2076 " give wide list
2077" call Decho("use wide list")
2078 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002079 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002080 setlocal ma
Bram Moolenaar572cb562005-08-05 21:35:02 +00002081
2082 " clear buffer - this will cause NetBrowse/LocalBrowse to do a refresh
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002083 %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002084
2085 " refresh the listing
2086 if a:mode == 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002087 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002088 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002089 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002090 endif
2091
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002092 " keep cursor on the filename
2093 silent keepjumps $
2094 if fname =~ '/$'
2095 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2096 else
2097 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2098 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002099
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002100" call Dret("NetLongList : w:netrw_longlist=".w:netrw_longlist)
2101endfun
2102
2103" ---------------------------------------------------------------------
2104" NetrwWideListing: {{{2
2105fun! s:NetrwWideListing()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002106" call Dfunc("NetrwWideListing() w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002107
2108 if w:netrw_longlist == 2
2109 " look for longest filename (cpf=characters per filename)
2110 " cpf: characters per file
2111 " fpl: files per line
2112 " fpc: files per column
2113 set ma
2114 let b:netrw_cpf= 0
2115 if line("$") >= w:netrw_bannercnt
2116 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
2117 else
2118" call Dret("NetrwWideListing")
2119 return
2120 endif
2121" call Decho("max file strlen+1=".b:netrw_cpf)
2122 let b:netrw_cpf= b:netrw_cpf + 1
2123
2124 " determine qty files per line (fpl)
2125 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
2126" call Decho("fpl= ".winwidth(0)."/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
2127
2128 " make wide display
2129 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^.*$/\=printf("%-'.b:netrw_cpf.'s",submatch(0))/'
2130 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
2131 let newcolstart = w:netrw_bannercnt + fpc
2132 let newcolend = newcolstart + fpc - 1
2133" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
2134 while line("$") >= newcolstart
2135 if newcolend > line("$") | let newcolend= line("$") | endif
2136 let newcolqty= newcolend - newcolstart
2137 exe newcolstart
2138 if newcolqty == 0
2139 exe "silent keepjumps norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
2140 else
2141 exe "silent keepjumps norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
2142 endif
2143 exe "silent keepjumps ".newcolstart.','.newcolend.'d'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002144 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002145 endwhile
2146 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002147 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002148 endif
2149
2150" call Dret("NetrwWideListing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002151endfun
2152
2153" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002154" NetSaveWordPosn: used by the "s" command in both remote and local {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002155" browsing. Along with NetRestoreWordPosn(), it keeps the cursor on
2156" the same word even though the sorting has changed its order of appearance.
2157fun! s:NetSaveWordPosn()
2158" call Dfunc("NetSaveWordPosn()")
2159 let s:netrw_saveword= '^'.escape(getline("."),s:netrw_cd_escape).'$'
2160" call Dret("NetSaveWordPosn : saveword<".s:netrw_saveword.">")
2161endfun
2162
2163" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002164" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002165fun! s:NetRestoreWordPosn()
2166" call Dfunc("NetRestoreWordPosn()")
2167 silent! call search(s:netrw_saveword,'w')
2168" call Dret("NetRestoreWordPosn")
2169endfun
2170
2171" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002172" NetMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002173fun! s:NetMakeDir(usrhost)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002174" call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)")
2175
2176 " get name of new directory from user. A bare <CR> will skip.
2177 " if its currently a directory, also request will be skipped, but with
2178 " a message.
2179 call inputsave()
2180 let newdirname= input("Please give directory name: ")
2181 call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002182" call Decho("newdirname<".newdirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002183
2184 if newdirname == ""
2185" call Dret("NetMakeDir : user aborted with bare <cr>")
2186 return
2187 endif
2188
2189 if a:usrhost == ""
2190
2191 " Local mkdir:
2192 " sanity checks
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002193 let fullnewdir= b:netrw_curdir.'/'.newdirname
2194" call Decho("fullnewdir<".fullnewdir.">")
2195 if isdirectory(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002196 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002197 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a directory!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002198 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002199 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002200" call Dret("NetMakeDir : directory<".newdirname."> exists previously")
2201 return
2202 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002203 if filereadable(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002204 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002205 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a file!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002206 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002207 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002208" call Dret("NetMakeDir : file<".newdirname."> exists previously")
2209 return
2210 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002211
2212 " requested new local directory is neither a pre-existing file or
2213 " directory, so make it!
2214 if exists("*mkdir")
2215 call mkdir(fullnewdir,"p")
2216 else
2217 let netrw_origdir= s:NetGetcwd(1)
2218 exe 'cd '.b:netrw_curdir
2219" call Decho("netrw_origdir<".netrw_origdir."> b:netrw_curdir<".b:netrw_curdir.">")
2220" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.newdirname.'"')
2221 exe "silent! !".g:netrw_local_mkdir.' "'.newdirname.'"'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002222 if !g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002223 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002224
Bram Moolenaar8299df92004-07-10 09:47:34 +00002225 if v:shell_error == 0
2226 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002227" call Decho("refresh listing")
2228 let linenum= line(".")
2229 norm! H0
2230 let hline = line(".")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002231 set ma|norm! 2D
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002232 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,'./'))
2233 exe "norm! ".hline."G0z\<CR>"
2234 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002235 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002236 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002237 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002238 endif
2239 redraw!
2240
2241 else
2242 " Remote mkdir:
2243 let mkdircmd = substitute(g:netrw_mkdir_cmd,'\<HOSTNAME\>',a:usrhost,'')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002244 let newdirname= "'".'"'.substitute(expand("%"),'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname.'"'."'"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002245" call Decho("exe silent! !".mkdircmd." ".newdirname)
2246 exe "silent! !".mkdircmd." ".newdirname
2247 if v:shell_error == 0
2248 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002249 let linenum= line(".")
2250 norm! H0
2251 let hline = line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002252 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002253 exe "norm! ".hline."G0z\<CR>"
2254 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002255 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002256 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002257 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002258 endif
2259 redraw!
2260 endif
2261
2262" call Dret("NetMakeDir")
2263endfun
2264
2265" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002266" NetBookmarkDir: {{{2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002267" 0: (user: <b>) bookmark current directory
2268" 1: (user: <B>) change to the bookmarked directory
2269" 2: (user: <q>) list bookmarks
2270" 3: (LocalBrowse) record current directory history
2271" 4: (user: <u>) go up (previous) bookmark
2272" 5: (user: <U>) go down (next) bookmark
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002273fun! s:NetBookmarkDir(chg,curdir)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002274" call Dfunc("NetBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002275 if exists("w:netrw_bannercnt") && line(".") <= w:netrw_bannercnt
2276 " looks like a "b" was pressed while in the banner region
2277 if line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002278 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00002279 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002280 if &ch > 1
2281 " "clear" the message
2282 echo ""
2283 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002284" call Dret("NetBookmarkDir - ignoring")
2285 return
2286 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002287
2288 if a:chg == 0
2289 " bookmark the current directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002290 let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir
2291 if !exists("g:NETRW_BOOKMARKMAX")
2292 let g:NETRW_BOOKMARKMAX= v:count
2293 elseif v:count > g:NETRW_BOOKMARKMAX
2294 let g:NETRW_BOOKMARKMAX= v:count
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002295 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002296 echo "bookmarked the current directory"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002297
2298 elseif a:chg == 1
2299 " change to the bookmarked directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002300 if exists("g:NETRW_BOOKMARKDIR_{v:count}")
2301 exe "e ".g:NETRW_BOOKMARKDIR_{v:count}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002302 else
2303 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2304 endif
2305
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002306 elseif a:chg == 2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002307 " list user's bookmarks
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002308 if exists("g:NETRW_BOOKMARKMAX")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002309" call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]")
2310 let cnt= 0
2311 while cnt <= g:NETRW_BOOKMARKMAX
2312 if exists("g:NETRW_BOOKMARKDIR_{cnt}")
2313" call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt})
2314 echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}
2315 endif
2316 let cnt= cnt + 1
2317 endwhile
2318 endif
2319
2320 " list directory history
2321 let cnt = g:NETRW_DIRHIST_CNT
2322 let first = 1
2323 let histcnt = 0
2324 while ( first || cnt != g:NETRW_DIRHIST_CNT )
2325" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT)
2326 let histcnt= histcnt + 1
2327 if exists("g:NETRW_DIRHIST_{cnt}")
2328" call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt})
2329 echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002330 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002331 let first = 0
2332 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2333 if cnt < 0
2334 let cnt= cnt + g:netrw_dirhistmax
2335 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002336 endwhile
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002337
2338 elseif a:chg == 3
Bram Moolenaar572cb562005-08-05 21:35:02 +00002339 " saves most recently visited directories (when they differ)
2340 if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir
2341 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2342 let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e')
2343" call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2344 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002345
2346 elseif a:chg == 4
2347 " u: change to the previous directory stored on the history list
2348 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2349 if g:NETRW_DIRHIST_CNT < 0
2350 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2351 endif
2352 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2353" call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2354 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2355 else
2356 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2357 echo "Sorry, no predecessor directory exists yet"
2358 endif
2359
2360 elseif a:chg == 5
2361 " U: change to the subsequent directory stored on the history list
2362 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2363 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2364" call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2365 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2366 else
2367 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2368 if g:NETRW_DIRHIST_CNT < 0
2369 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2370 endif
2371 echo "Sorry, no successor directory exists yet"
2372 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002373 endif
2374" call Dret("NetBookmarkDir")
2375endfun
2376
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002377" ---------------------------------------------------------------------
2378" NetObtain: obtain file under cursor (for remote browsing support) {{{2
2379fun! s:NetObtain()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002380 let fname= expand("<cWORD>")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002381
2382 " NetrwStatusLine support - for obtaining support
2383 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.fname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002384
2385" call Dfunc("NetObtain() method=".w:netrw_method)
2386 if exists("w:netrw_method") && w:netrw_method =~ '[235]'
2387 if executable("ftp")
2388 let curdir = expand("%")
2389 let path = substitute(curdir,'ftp://[^/]\+/','','e')
2390 let curline= line(".")
2391 let endline= line("$")+1
2392 set ma
2393 keepjumps $
2394
2395 ".........................................
2396 if w:netrw_method == 2
2397 " ftp + <.netrc>: Method #2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002398 setlocal ff=unix
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002399 if path != ""
2400 put ='cd '.path
2401" call Decho("ftp: cd ".path)
2402 endif
2403 put ='get '.fname
2404" call Decho("ftp: get ".fname)
2405 if exists("g:netrw_port") && g:netrw_port != ""
2406" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
2407 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
2408 else
2409" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
2410 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
2411 endif
2412
2413 ".........................................
2414 elseif w:netrw_method == 3
2415 " ftp + machine,id,passwd,filename: Method #3
2416 setlocal ff=unix
2417 if exists("g:netrw_port") && g:netrw_port != ""
2418 put ='open '.g:netrw_machine.' '.g:netrw_port
2419" call Decho('ftp: open '.g:netrw_machine.' '.g:netrw_port)
2420 else
2421 put ='open '.g:netrw_machine
2422" call Decho('ftp: open '.g:netrw_machine
2423 endif
2424
2425 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2426 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002427 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002428" call Decho('ftp: g:netrw_uid')
2429" call Decho('ftp: g:netrw_passwd')
2430 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002431 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002432" call Decho('user '.g:netrw_uid.' '.g:netrw_passwd)
2433 endif
2434
2435 if a:path != ""
2436 put ='cd '.a:path
2437" call Decho('cd '.a:path)
2438 endif
2439 exe "put ='".a:cmd."'"
2440" call Decho("ftp: ".a:cmd)
2441
2442 " perform ftp:
2443 " -i : turns off interactive prompting from ftp
2444 " -n unix : DON'T use <.netrc>, even though it exists
2445 " -n win32: quit being obnoxious about password
2446" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
2447 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i -n"
2448
2449 ".........................................
2450 else
2451 echo "***warning*** unable to comply with your request<" . choice . ">"
2452 endif
2453 " restore
2454 exe "silent! ".endline.",$d"
2455 exe "keepjumps ".curline
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002456 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002457 else
2458 if !exists("g:netrw_quiet")
2459 echohl Error | echo "***netrw*** this system doesn't support ftp" | echohl None
2460 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2461 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002462 let &stl = s:netrw_users_stl
2463 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002464" call Dret("NetObtain")
2465 return
2466 endif
2467
2468 ".........................................
2469 else
2470 " scp: Method#4
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002471 let curdir = expand("%")
2472 let path = substitute(curdir,'scp://[^/]\+/','','e')
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002473 if exists("g:netrw_port") && g:netrw_port != ""
2474 let useport= " -P ".g:netrw_port
2475 else
2476 let useport= ""
2477 endif
2478 if g:netrw_cygwin == 1
2479 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002480" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2481 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002482 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002483" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2484 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002485 endif
2486 endif
2487
2488 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002489 let &stl = s:netrw_users_stl
2490 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002491 redraw!
2492
2493" call Dret("NetObtain")
2494endfun
2495
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002496" ---------------------------------------------------------------------
2497" NetPrevWinOpen: opoen file/directory in previous window. {{{2
2498" If there's only one window, then the window will first be split.
2499fun! s:NetPrevWinOpen(islocal)
2500" call Dfunc("NetPrevWinOpen(islocal=".a:islocal.")")
2501
2502 " get last window number and the word currently under the cursor
2503 let lastwinnr = winnr("$")
2504 let curword = s:NetGetWord()
2505 let curdir = b:netrw_curdir
2506" call Decho("lastwinnr=".lastwinnr." curword<".curword.">")
2507
2508 let didsplit = 0
2509 if lastwinnr == 1
2510 " if only one window, open a new one first
2511" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
2512 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
2513 let didsplit = 1
2514
2515 else
2516 wincmd p
2517 " if the previous window's buffer has been changed (is modified),
2518 " and it doesn't appear in any other extant window, then ask the
2519 " user if s/he wants to abandon modifications therein.
2520 let bnr = winbufnr(0)
2521 let bnrcnt = 0
2522 if &mod
2523 windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif
2524" call Decho("bnr=".bnr." bnrcnt=".bnrcnt)
2525 if bnrcnt == 1
2526 let bufname= bufname(winbufnr(winnr()))
2527 let choice= confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel")
2528
2529 if choice == 1
2530 " Yes -- write file & then browse
2531 let v:errmsg= ""
2532 silent w
2533 if v:errmsg != ""
2534 echohl Error | echo "***netrw*** "unable to write <".bufname.">!" | echohl None
2535 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2536 if didsplit
2537 q
2538 else
2539 wincmd p
2540 endif
2541" call Dret("NetPrevWinOpen : unable to write <".bufname.">")
2542 return
2543 endif
2544
2545 elseif choice == 2
2546 " No -- don't worry about changed file, just browse anyway
2547 set nomod
2548 echohl WarningMsg | echo "***netrw*** ".bufname." changes abandoned" | echohl None
2549
2550 else
2551 " Cancel -- don't do this
2552 if didsplit
2553 q
2554 else
2555 wincmd p
2556 endif
2557" call Dret("NetPrevWinOpen : cancelled")
2558 return
2559 endif
2560 endif
2561 endif
2562 endif
2563
2564 if a:islocal
2565 call s:LocalBrowse(s:LocalBrowseChgDir(curdir,curword))
2566 else
2567 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),curword))
2568 endif
2569" call Dret("NetPrevWinOpen")
2570endfun
2571
Bram Moolenaar83bab712005-08-01 21:58:57 +00002572" ==========================================
2573" Local Directory Browsing Support: {{{1
2574" ==========================================
Bram Moolenaar8299df92004-07-10 09:47:34 +00002575
2576" ---------------------------------------------------------------------
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002577" LocalBrowse: {{{2
2578fun! s:LocalBrowse(dirname)
2579 " unfortunate interaction -- debugging calls can't be used here;
2580 " the BufEnter event causes triggering when attempts to write to
2581 " the DBG buffer are made.
2582 if isdirectory(a:dirname)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002583 silent! call netrw#DirBrowse(a:dirname)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002584 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002585 " not a directory, ignore it
2586endfun
Bram Moolenaar8299df92004-07-10 09:47:34 +00002587
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002588" ---------------------------------------------------------------------
2589" DirBrowse: supports local file/directory browsing {{{2
2590fun! netrw#DirBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002591 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002592" call Dfunc("DirBrowse(dirname<".a:dirname.">) buf#".bufnr("%")." winnr=".winnr()." sortby=".g:netrw_sort_by)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002593" call Dredir("ls!")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002594
Bram Moolenaar488c6512005-08-11 20:09:58 +00002595 if exists("s:netrw_skipbrowse")
2596 unlet s:netrw_skipbrowse
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002597" call Dret("DirBrowse")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002598 return
2599 endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002600
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002601 call s:NetOptionSave()
Bram Moolenaar488c6512005-08-11 20:09:58 +00002602
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002603 if v:version < 603
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002604 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002605 echohl Error | echo "***netrw*** vim version<".v:version."> too old for browsing with netrw" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002606 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002607 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002608 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002609" call Dret("DirBrowse : vim version<".v:version."> too old")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002610 return
2611 endif
2612
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002613 " use buffer-oriented WinVars if buffer ones exist but window ones don't
2614 call s:UseBufWinVars()
2615
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002616 " find buffer number of buffer named precisely the same as a:dirname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002617 let bufnum= bufnr(escape(a:dirname,'\'))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002618" call Decho("findbuf: bufnum=".bufnum)
2619 if bufnum > 0 && bufname(bufnum) != a:dirname
2620 let ibuf= 1
2621 let buflast= bufnr("$")
2622 while bufname(ibuf) !~ '^'.a:dirname.'\=$' && ibuf <= buflast
2623" call Decho("findbuf: ibuf=".ibuf. " bufname<".bufname(ibuf)."> dirname<".a:dirname.">")
2624 let ibuf= ibuf + 1
2625 endwhile
2626 if ibuf > buflast
2627 let bufnum= -1
2628 else
2629 let bufnum= ibuf
2630 endif
2631" call Decho("findbuf: bufnum=".bufnum." (final)")
2632 endif
2633
2634 " get cleared buffer
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002635 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002636 keepjumps keepalt enew!
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002637" call Decho("enew buffer")
2638 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002639 exe "keepalt b ".bufnum
Bram Moolenaar572cb562005-08-05 21:35:02 +00002640 if exists("s:last_sort_by") && g:netrw_sort_by == s:last_sort_by
2641 if getline(2) =~ '^" Directory Listing '
2642 if !g:netrw_keepdir
2643" call Decho("change directory: cd ".b:netrw_curdir)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002644 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar572cb562005-08-05 21:35:02 +00002645 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002646 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002647" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002648 return
2649 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002650 endif
2651 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00002652 let s:last_sort_by= g:netrw_sort_by
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002653
2654 " get the new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002655 if has("win32") || has("win95") || has("win64") || has("win16")
2656 let b:netrw_curdir= substitute(a:dirname,'\\','/','ge')
2657 else
2658 let b:netrw_curdir= a:dirname
2659 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002660 if b:netrw_curdir =~ '[/\\]$'
2661 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2662 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002663 if b:netrw_curdir == ''
2664 " under unix, when the root directory is encountered, the result
2665 " from the preceding substitute is an empty string.
2666 let b:netrw_curdir= '/'
2667 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002668" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002669
Bram Moolenaar83bab712005-08-01 21:58:57 +00002670 " make netrw's idea of the current directory vim's if the user wishes
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002671 if !g:netrw_keepdir
Bram Moolenaar83bab712005-08-01 21:58:57 +00002672" call Decho("change directory: cd ".b:netrw_curdir)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002673 try
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002674 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002675 catch /^Vim\%((\a\+)\)\=:E472/
2676 echohl Error | echo "***netrw*** unable to change directory to <".b:netrw_curdir."> (permissions?)" | echohl None
2677 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2678 if exists("w:netrw_prvdir")
2679 let b:netrw_curdir= w:netrw_prvdir
2680 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002681 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002682" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002683 return
2684 endif
2685 endtry
Bram Moolenaar83bab712005-08-01 21:58:57 +00002686 endif
2687
2688 " change the name of the buffer to reflect the b:netrw_curdir
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002689 " Hmm. When another vim is open to the same directory, I get
2690 " a "Press ENTER" ... ok, setting "noswf" avoids it.
2691" call Decho('exe silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002692 exe 'silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002693
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002694 " make this buffer not-a-file, modifiable, not line-numbered, etc
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002695 setlocal bh=hide bt=nofile nobl ma nonu noswf
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002696 keepalt silent! %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002697
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002698 " ---------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002699 " Perform Directory Listing:
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002700 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2701 echo "(netrw) Processing your browsing request..."
2702 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002703
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002704 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002705 call s:NetBookmarkDir(3,b:netrw_curdir)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002706
Bram Moolenaar8299df92004-07-10 09:47:34 +00002707 " set up all the maps
Bram Moolenaar269ec652004-07-29 08:43:53 +00002708" call Decho("Setting up local browser maps")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002709 nnoremap <buffer> <silent> <cr> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002710 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002711 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,'../'))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002712 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 +00002713 if w:netrw_longlist != 2
2714 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2715 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
2716 endif
2717 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2718 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002719 nnoremap <buffer> <silent> c :exe "cd ".b:netrw_curdir<cr>
2720 nnoremap <buffer> <silent> d :call <SID>NetMakeDir("")<cr>
2721 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(1)<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002722 nnoremap <buffer> <silent> i :call <SID>NetLongList(1)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002723 nnoremap <buffer> <silent> o :call <SID>NetSplit(2)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002724 nnoremap <buffer> <silent> O :call <SID>LocalObtain()<cr>
2725 nnoremap <buffer> <silent> p :call <SID>LocalPreview(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),1))<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002726 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002727 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002728 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 +00002729 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>
2730 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002731 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
2732 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002733 nnoremap <buffer> <silent> v :call <SID>NetSplit(3)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002734 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),0),0)"<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002735 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar572cb562005-08-05 21:35:02 +00002736 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
2737 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002738 exe 'nnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002739 exe 'vnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002740 exe 'nnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002741 exe 'vnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002742 exe 'nnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002743 exe 'vnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00002744 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetMakeDir("")<cr>'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002745 nnoremap <buffer> ? :he netrw-dir<cr>
2746
2747 " Set up the banner
Bram Moolenaar269ec652004-07-29 08:43:53 +00002748" call Decho("set up banner")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002749 keepjumps put ='\" ============================================================================'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002750 keepjumps 1d
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002751 keepjumps put ='\" Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002752 keepjumps put ='\" '.b:netrw_curdir
Bram Moolenaar488c6512005-08-11 20:09:58 +00002753 let w:netrw_bannercnt= 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002754
2755 let sortby= g:netrw_sort_by
2756 if g:netrw_sort_direction =~ "^r"
2757 let sortby= sortby." reversed"
2758 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00002759
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002760 " Sorted by...
Bram Moolenaar8299df92004-07-10 09:47:34 +00002761 if g:netrw_sort_by =~ "^n"
Bram Moolenaar269ec652004-07-29 08:43:53 +00002762" call Decho("directories will be sorted by name")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002763 " sorted by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002764 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar8299df92004-07-10 09:47:34 +00002765 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar488c6512005-08-11 20:09:58 +00002766 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8299df92004-07-10 09:47:34 +00002767 else
Bram Moolenaar269ec652004-07-29 08:43:53 +00002768" call Decho("directories will be sorted by size or date")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002769 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002770 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar488c6512005-08-11 20:09:58 +00002771 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002772 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002773
2774 " Hiding... -or- Showing...
Bram Moolenaar269ec652004-07-29 08:43:53 +00002775 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002776 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002777 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002778 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002779 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002780 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002781 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002782 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002783 keepjumps put ='\" Quick Help: ?:help -:go up dir D:delete R:rename s:sort-by x:exec'
2784 keepjumps put ='\" ============================================================================'
Bram Moolenaar488c6512005-08-11 20:09:58 +00002785 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002786
2787 " bannercnt should index the line just after the banner
Bram Moolenaar488c6512005-08-11 20:09:58 +00002788 let w:netrw_bannercnt= w:netrw_bannercnt + 1
2789" call Decho("bannercnt=".w:netrw_bannercnt)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002790
2791 " generate the requested directory listing
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002792 call s:LocalBrowseList()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002793
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002794 " set up syntax highlighting
2795 if has("syntax")
2796 setlocal ft=netrwlist
Bram Moolenaar572cb562005-08-05 21:35:02 +00002797 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002798 setlocal ft=
2799 endif
2800 endif
2801
Bram Moolenaar8299df92004-07-10 09:47:34 +00002802 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002803 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00002804 if g:netrw_hide && g:netrw_list_hide != ""
2805 call s:NetrwListHide()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002806 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002807 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002808
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002809 if g:netrw_sort_by =~ "^n"
2810 call s:SetSort()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002811
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002812 if w:netrw_bannercnt < line("$")
2813 if g:netrw_sort_direction =~ 'n'
2814 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
2815 else
2816 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
2817 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002818 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002819 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002820
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002821 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002822 if w:netrw_bannercnt < line("$")
2823 if g:netrw_sort_direction =~ 'n'
2824 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
2825 else
2826 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
2827 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002828 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002829 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002830 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002831
Bram Moolenaar8299df92004-07-10 09:47:34 +00002832 endif
2833 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002834
2835 call s:NetrwWideListing()
Bram Moolenaar488c6512005-08-11 20:09:58 +00002836 if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002837 " place cursor on the top-left corner of the file listing
2838 exe 'silent '.w:netrw_bannercnt
2839 norm! 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00002840 endif
2841
2842 " record previous current directory
2843 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaar8299df92004-07-10 09:47:34 +00002844
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002845 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002846 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002847 call s:NetOptionRestore()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002848 setlocal noma nomod nonu bh=hide nobl
Bram Moolenaar8299df92004-07-10 09:47:34 +00002849
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002850" call Dret("DirBrowse : file<".expand("%:p")."> bufname<".bufname("%").">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002851endfun
2852
2853" ---------------------------------------------------------------------
2854" LocalBrowseList: does the job of "ls" for local directories {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002855fun! s:LocalBrowseList()
Bram Moolenaar83bab712005-08-01 21:58:57 +00002856" call Dfunc("LocalBrowseList() b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002857
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002858 " get the list of files contained in the current directory
Bram Moolenaar83bab712005-08-01 21:58:57 +00002859 let dirname = escape(b:netrw_curdir,s:netrw_glob_escape)
2860 let dirnamelen = strlen(b:netrw_curdir)
2861 let filelist = glob(dirname."/*")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002862" call Decho("glob(dirname<".dirname.">,*)=".filelist)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002863 if filelist != ""
2864 let filelist= filelist."\n"
2865 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002866 let filelist= filelist.glob(dirname."/.*")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002867" call Decho("glob(dirname<".dirname.">,.*)=".glob(dirname.".*"))
2868
2869 " if the directory name includes a "$", and possibly other characters,
2870 " the glob() doesn't include "." and ".." entries.
2871 if filelist !~ '[\\/]\.[\\/]\=\(\n\|$\)'
2872" call Decho("forcibly tacking on .")
2873 if filelist == ""
2874 let filelist= dirname."."
2875 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00002876 let filelist= filelist."\n".b:netrw_curdir."."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002877 endif
2878" call Decho("filelist<".filelist.">")
2879 endif
2880 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
2881" call Decho("forcibly tacking on ..")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002882 let filelist= filelist."\n".b:netrw_curdir.".."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002883" call Decho("filelist<".filelist.">")
2884 endif
2885 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002886 let filelist= substitute(filelist,'\','/','ge')
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002887
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002888" call Decho("dirname<".dirname.">")
2889" call Decho("dirnamelen<".dirnamelen.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002890" call Decho("filelist<".filelist.">")
2891
2892 while filelist != ""
2893 if filelist =~ '\n'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002894 let filename = substitute(filelist,'\n.*$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002895 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
2896 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00002897 let filename = filelist
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002898 let filelist = ""
Bram Moolenaar8299df92004-07-10 09:47:34 +00002899 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002900 let pfile= filename
2901 if isdirectory(filename)
2902 let pfile= filename."/"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002903 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002904 if pfile =~ '//$'
2905 let pfile= substitute(pfile,'//$','/','e')
2906 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002907 let pfile= strpart(pfile,dirnamelen)
Bram Moolenaar572cb562005-08-05 21:35:02 +00002908 let pfile= substitute(pfile,'^/','','e')
Bram Moolenaar83bab712005-08-01 21:58:57 +00002909" call Decho(" ")
2910" call Decho("filename<".filename.">")
2911" call Decho("pfile <".pfile.">")
2912
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002913 if w:netrw_longlist == 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00002914 let sz = getfsize(filename)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002915 let fsz = strpart(" ",1,15-strlen(sz)).sz
2916 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaar83bab712005-08-01 21:58:57 +00002917" call Decho("sz=".sz." fsz=".fsz)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002918 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002919
Bram Moolenaar8299df92004-07-10 09:47:34 +00002920 if g:netrw_sort_by =~ "^t"
2921 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002922" call Decho("getftime(".filename.")=".getftime(filename))
2923 let t = getftime(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002924 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar83bab712005-08-01 21:58:57 +00002925" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002926 let ftpfile= ft.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002927 keepjumps silent! put=ftpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002928
Bram Moolenaar8299df92004-07-10 09:47:34 +00002929 elseif g:netrw_sort_by =~ "^s"
2930 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002931" call Decho("getfsize(".filename.")=".getfsize(filename))
2932 let sz = getfsize(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002933 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar83bab712005-08-01 21:58:57 +00002934" call Decho("exe keepjumps put ='".fsz.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002935 let fszpfile= fsz.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002936 keepjumps silent! put =fszpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002937
Bram Moolenaar8299df92004-07-10 09:47:34 +00002938 else
2939 " sort by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002940" call Decho("exe keepjumps put ='".pfile."'")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002941 keepjumps silent! put=pfile
Bram Moolenaar8299df92004-07-10 09:47:34 +00002942 endif
2943 endwhile
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002944
2945 " cleanup any windows mess at end-of-line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002946 silent! keepjumps %s/\r$//e
Bram Moolenaar83bab712005-08-01 21:58:57 +00002947 setlocal ts=32
Bram Moolenaar8299df92004-07-10 09:47:34 +00002948
2949" call Dret("LocalBrowseList")
2950endfun
2951
2952" ---------------------------------------------------------------------
2953" LocalBrowseChgDir: constructs a new directory based on the current {{{2
2954" directory and a new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002955fun! s:LocalBrowseChgDir(dirname,newdir,...)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002956" call Dfunc("LocalBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">) a:0=".a:0)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002957
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002958 let dirname= substitute(a:dirname,'\\','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002959 let newdir = a:newdir
2960
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002961 if dirname !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002962 " apparently vim is "recognizing" that it is in the home directory and
2963 " is removing the "/". Bad idea, so I have to put it back.
2964 let dirname= dirname.'/'
2965" call Decho("adjusting dirname<".dirname.">")
2966 endif
2967
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002968 if newdir !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002969 " handling a file
2970 let dirname= dirname.newdir
2971" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002972 " this lets NetBrowseX avoid the edit
2973 if a:0 < 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00002974" call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape.">")
2975" call Decho("about to edit<".escape(dirname,s:netrw_cd_escape).">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002976 if g:netrw_browse_split == 1
2977 new
2978 wincmd _
2979 elseif g:netrw_browse_split == 2
2980 rightb vert new
2981 wincmd |
2982 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002983 exe "e! ".escape(dirname,s:netrw_cd_escape)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002984 set ma nomod
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002985 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002986
2987 elseif newdir == './'
2988 " refresh the directory list
2989" call Decho("refresh directory listing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002990
2991 elseif newdir == '../'
2992 " go up one directory
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002993 let dirname= substitute(dirname,'^\(.*/\)\([^/]\+[\/]$\)','\1','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002994" call Decho("go up one dir: dirname<".dirname.">")
2995
2996 else
2997 " go down one directory
2998 let dirname= dirname.newdir
2999" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
3000 endif
3001
3002" call Dret("LocalBrowseChgDir <".dirname.">")
3003 return dirname
3004endfun
3005
3006" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00003007" LocalBrowseRm: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003008fun! s:LocalBrowseRm(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003009" call Dfunc("LocalBrowseRm(path<".a:path.">)")
3010" call Decho("firstline=".a:firstline." lastline=".a:lastline)
3011
3012 " preparation for removing multiple files/directories
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003013 let ctr = a:firstline
3014 let ret = 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003015 let all= 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00003016
3017 " remove multiple files and directories
3018 while ctr <= a:lastline
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003019 exe "keepjumps ".ctr
3020
3021 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003022 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003023 let ctr= ctr + 1
3024 continue
3025 endif
3026 let curword= s:NetGetWord()
3027 if curword == "./" || curword == "../"
3028 let ctr= ctr + 1
3029 continue
3030 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003031
3032 norm! 0
Bram Moolenaar83bab712005-08-01 21:58:57 +00003033 let rmfile= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003034" call Decho("rmfile<".rmfile.">")
3035
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003036 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003037 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003038 if !all
3039 echohl Statement
3040 call inputsave()
3041 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3042 call inputrestore()
3043 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003044 if ok == ""
3045 let ok="no"
3046 endif
3047" call Decho("response: ok<".ok.">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003048 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003049" call Decho("response: ok<".ok."> (after sub)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003050 if ok =~ 'a\%[ll]'
3051 let all= 1
3052 endif
3053 endif
3054
3055 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003056 let ret= delete(rmfile)
3057" call Decho("errcode=".v:shell_error." ret=".ret)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003058 elseif ok =~ 'q\%[uit]'
3059 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003060 endif
3061
3062 else
3063 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003064 if !all
3065 echohl Statement
3066 call inputsave()
3067 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3068 call inputrestore()
3069 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003070 if ok == ""
3071 let ok="no"
3072 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003073 if ok =~ 'a\%[ll]'
3074 let all= 1
3075 endif
3076 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003077 let rmfile= substitute(rmfile,'[\/]$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003078
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003079 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003080" call Decho("1st attempt: system(".g:netrw_local_rmdir.' "'.rmfile.'")')
3081 call system(g:netrw_local_rmdir.' "'.rmfile.'"')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003082" call Decho("v:shell_error=".v:shell_error)
3083
3084 if v:shell_error != 0
3085" call Decho("2nd attempt to remove directory<".rmfile.">")
3086 let errcode= delete(rmfile)
3087" call Decho("errcode=".errcode)
3088
3089 if errcode != 0
3090 if has("unix")
3091" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003092call system("rm ".rmfile)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003093 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003094 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003095 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003096endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003097 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003098 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003099 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003100 endif
3101 endif
3102 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003103
3104 elseif ok =~ 'q\%[uit]'
3105 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003106 endif
3107 endif
3108
3109 let ctr= ctr + 1
3110 endwhile
3111
3112 " refresh the directory
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003113 let curline= line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003114" call Decho("refresh the directory")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003115 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003116 exe curline
3117
3118" call Dret("LocalBrowseRm")
3119endfun
3120
3121" ---------------------------------------------------------------------
3122" LocalBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003123fun! s:LocalBrowseRename(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003124" call Dfunc("LocalBrowseRename(path<".a:path.">)")
3125
3126 " preparation for removing multiple files/directories
3127 let ctr= a:firstline
3128
3129 " attempt to rename files/directories
3130 while ctr <= a:lastline
3131 exe "keepjumps ".ctr
3132
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003133 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003134 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003135 let ctr= ctr + 1
3136 continue
3137 endif
3138 let curword= s:NetGetWord()
3139 if curword == "./" || curword == "../"
3140 let ctr= ctr + 1
3141 continue
3142 endif
3143
Bram Moolenaar8299df92004-07-10 09:47:34 +00003144 norm! 0
Bram Moolenaar572cb562005-08-05 21:35:02 +00003145 let oldname= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003146" call Decho("oldname<".oldname.">")
3147
3148 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003149 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00003150 call inputrestore()
3151
Bram Moolenaar83bab712005-08-01 21:58:57 +00003152 let ret= rename(oldname,newname)
3153" call Decho("renaming <".oldname."> to <".newname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003154
3155 let ctr= ctr + 1
3156 endwhile
3157
3158 " refresh the directory
3159 let curline= line(".")
Bram Moolenaar269ec652004-07-29 08:43:53 +00003160" call Decho("refresh the directory listing")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003161 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003162 exe "keepjumps ".curline
3163" call Dret("LocalBrowseRename")
3164endfun
3165
3166" ---------------------------------------------------------------------
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003167" LocalObtain: copy selected file to current working directory {{{2
3168fun! s:LocalObtain()
3169" call Dfunc("LocalObtain()")
3170 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
3171 let fname= expand("<cWORD>")
3172 let fcopy= readfile(b:netrw_curdir."/".fname,"b")
3173 call writefile(fcopy,getcwd()."/".fname,"b")
3174 elseif !exists("b:netrw_curdir")
3175 echohl Error | echo "***netrw*** local browsing directory doesn't exist!"
3176 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3177 else
3178 echohl Error | echo "***netrw*** local browsing directory and current directory are identical"
3179 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3180 endif
3181" call Dret("LocalObtain")
3182endfun
3183
3184" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003185" LocalPreview: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003186fun! s:LocalPreview(path) range
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003187" call Dfunc("LocalPreview(path<".a:path.">)")
3188 if has("quickfix")
3189 if !isdirectory(a:path)
3190 exe "pedit ".a:path
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003191 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003192 echohl WarningMsg | echo "***netrw*** sorry, cannot preview a directory such as <".a:path.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003193 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003194 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003195 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003196 echohl WarningMsg | echo "***netrw*** sorry, to preview your vim needs the quickfix feature compiled in" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003197 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003198 endif
3199" call Dret("LocalPreview")
3200endfun
3201
3202" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003203" Explore: launch the local browser in the directory of the current file {{{2
3204" dosplit==0: the window will be split iff the current file has
3205" been modified
3206" dosplit==1: the window will be split before running the local
3207" browser
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003208fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003209" call Dfunc("Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.")")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003210
3211 " if dosplit or file has been modified
3212 if a:dosplit || &modified
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003213 call s:SaveWinVars()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003214
Bram Moolenaar83bab712005-08-01 21:58:57 +00003215 if a:style == 0 " Explore, Sexplore
3216 exe g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003217" call Decho("style=0: Explore or Sexplore")
3218
Bram Moolenaar83bab712005-08-01 21:58:57 +00003219 elseif a:style == 1 "Explore!, Sexplore!
3220 exe g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003221" call Decho("style=1: Explore! or Sexplore!")
3222
Bram Moolenaar83bab712005-08-01 21:58:57 +00003223 elseif a:style == 2 " Hexplore
3224 exe "bel ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003225" call Decho("style=2: Hexplore")
3226
Bram Moolenaar83bab712005-08-01 21:58:57 +00003227 elseif a:style == 3 " Hexplore!
3228 exe "abo ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003229" call Decho("style=3: Hexplore!")
3230
Bram Moolenaar83bab712005-08-01 21:58:57 +00003231 elseif a:style == 4 " Vexplore
3232 exe "lefta ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003233" call Decho("style=4: Vexplore")
3234
Bram Moolenaar83bab712005-08-01 21:58:57 +00003235 elseif a:style == 5 " Vexplore!
3236 exe "rightb ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003237" call Decho("style=5: Vexplore!")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003238 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003239 call s:CopyWinVars()
Bram Moolenaar83bab712005-08-01 21:58:57 +00003240 endif
3241 norm! 0
3242
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003243 if a:1 == "" && a:indx >= 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003244 " Explore Hexplore Vexplore Sexplore
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003245" call Decho("Explore Hexplore Vexplore Sexplore")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003246 let newdir= substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
3247 if newdir =~ '^scp:' || newdir =~ '^ftp:'
3248" call Decho("calling NetBrowse(newdir<".newdir.">)")
3249 call s:NetBrowse(newdir)
3250 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003251 if newdir == ""|let newdir= getcwd()|endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003252" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3253 call s:LocalBrowse(newdir)
3254 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003255
Bram Moolenaar572cb562005-08-05 21:35:02 +00003256 elseif a:1 =~ '\*\*/' || a:indx < 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003257 " Nexplore Pexplore -or- Explore **/...
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003258" call Decho("Nexplore Pexplore -or- Explore **/...")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003259
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003260 if has("path_extra")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003261 if !exists("w:netrw_explore_indx")
3262 let w:netrw_explore_indx= 0
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003263 endif
3264 let indx = a:indx
3265 if indx == -1
Bram Moolenaar488c6512005-08-11 20:09:58 +00003266 let indx= w:netrw_explore_indx + 1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003267 elseif indx == -2
Bram Moolenaar488c6512005-08-11 20:09:58 +00003268 let indx= w:netrw_explore_indx - 1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003269 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003270 let w:netrw_explore_indx = 0
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003271 if !exists("b:netrw_curdir")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003272 let b:netrw_curdir= getcwd()
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003273 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003274 let w:netrw_explore_list = split(expand(b:netrw_curdir."/".a:1),'\n')
3275 let w:netrw_explore_listlen = len(w:netrw_explore_list)
3276 if w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/'
Bram Moolenaar572cb562005-08-05 21:35:02 +00003277 echohl WarningMsg | echo "***netrw*** no files matched" | echohl None
3278 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3279" call Dret("Explore")
3280 return
3281 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003282 endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003283
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003284 " NetrwStatusLine support - for exploring support
Bram Moolenaar488c6512005-08-11 20:09:58 +00003285 let w:netrw_explore_indx= indx
Bram Moolenaar488c6512005-08-11 20:09:58 +00003286" call Decho("explorelist<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003287
3288 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003289 if indx >= w:netrw_explore_listlen || indx < 0
3290 let indx= (indx < 0)? 0 : ( w:netrw_explore_listlen - 1 )
Bram Moolenaar572cb562005-08-05 21:35:02 +00003291 echohl WarningMsg | echo "***netrw*** no more files match Explore pattern" | echohl None
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003292 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3293" call Dret("Explore")
3294 return
3295 endif
3296
Bram Moolenaar488c6512005-08-11 20:09:58 +00003297 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003298" call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003299 let newdir= substitute(dirfile,'/[^/]*$','','e')
3300" call Decho("newdir<".newdir.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003301
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003302" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3303 call s:LocalBrowse(newdir)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003304 if w:netrw_longlist == 0 || w:netrw_longlist == 1
3305 call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
3306 else
3307 call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
3308 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003309 let w:netrw_explore_mtchcnt = indx + 1
3310 let w:netrw_explore_bufnr = bufnr(".")
3311 let w:netrw_explore_line = line(".")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003312 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaar488c6512005-08-11 20:09:58 +00003313" 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 +00003314
3315 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003316 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003317 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 +00003318 endif
3319 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3320 endif
3321
Bram Moolenaar83bab712005-08-01 21:58:57 +00003322 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003323" call Decho("Explore newdir<".a:1.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003324 let newdir= a:1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003325 call s:LocalBrowse(newdir)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003326 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003327
3328" call Dret("Explore")
3329endfun
3330
3331" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003332" SetupNetrwStatusLine: {{{2
3333fun! s:SetupNetrwStatusLine(statline)
3334" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
3335
3336 if !exists("s:netrw_setup_statline")
3337 let s:netrw_setup_statline= 1
3338" call Decho("do first-time status line setup")
3339
3340 if !exists("s:netrw_users_stl")
3341 let s:netrw_users_stl= &stl
3342 endif
3343 if !exists("s:netrw_users_ls")
3344 let s:netrw_users_ls= &laststatus
3345 endif
3346
3347 " set up User9 highlighting as needed
3348 let keepa= @a
3349 redir @a
3350 try
3351 hi User9
3352 catch /^Vim\%((\a\+)\)\=:E411/
3353 if &bg == "dark"
3354 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
3355 else
3356 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
3357 endif
3358 endtry
3359 redir END
3360 let @a= keepa
3361 endif
3362
3363 " set up status line (may use User9 highlighting)
3364 " insure that windows have a statusline
3365 " make sure statusline is displayed
3366 let &stl=a:statline
3367 set laststatus=2
3368" call Decho("stl=".&stl)
3369 redraw!
3370
3371" call Dret("SetupNetrwStatusLine : stl=".&stl)
3372endfun
3373
3374" ---------------------------------------------------------------------
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003375" NetrwStatusLine: {{{2
3376fun! NetrwStatusLine()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003377
3378 " vvv NetrwStatusLine() debugging vvv
3379" let g:stlmsg=""
3380" if !exists("w:netrw_explore_bufnr")
3381" let g:stlmsg="!X<explore_bufnr>"
3382" elseif w:netrw_explore_bufnr != bufnr(".")
3383" let g:stlmsg="explore_bufnr!=".bufnr(".")
3384" endif
3385" if !exists("w:netrw_explore_line")
3386" let g:stlmsg=" !X<explore_line>"
3387" elseif w:netrw_explore_line != line(".")
3388" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
3389" endif
3390" if !exists("w:netrw_explore_list")
3391" let g:stlmsg=" !X<explore_list>"
3392" endif
3393 " ^^^ NetrwStatusLine() debugging ^^^
3394
Bram Moolenaar488c6512005-08-11 20:09:58 +00003395 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 +00003396 " restore user's status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003397 let &stl = s:netrw_users_stl
3398 let &laststatus = s:netrw_users_ls
Bram Moolenaar488c6512005-08-11 20:09:58 +00003399 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
3400 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003401 return ""
3402 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003403 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003404 endif
3405endfun
3406
3407" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003408" NetGetcwd: get the current directory. {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003409" Change backslashes to forward slashes, if any.
3410" If doesc is true, escape certain troublesome characters
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003411fun! s:NetGetcwd(doesc)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003412" call Dfunc("NetGetcwd(doesc=".a:doesc.")")
3413 let curdir= substitute(getcwd(),'\\','/','ge')
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003414 if curdir !~ '[\/]$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003415 let curdir= curdir.'/'
3416 endif
3417 if a:doesc
3418 let curdir= escape(curdir,s:netrw_cd_escape)
3419 endif
3420" call Dret("NetGetcwd <".curdir.">")
3421 return curdir
3422endfun
3423
3424" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003425" NetMethod: determine method of transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426" method == 1: rcp
3427" 2: ftp + <.netrc>
3428" 3: ftp + machine, id, password, and [path]filename
3429" 4: scp
3430" 5: http (wget)
3431" 6: cadaver
3432" 7: rsync
3433" 8: fetch
3434" 9: sftp
3435fun! s:NetMethod(choice) " globals: method machine id passwd fname
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003436" call Dfunc("NetMethod(a:choice<".a:choice.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003437
3438 " initialization
3439 let b:netrw_method = 0
3440 let g:netrw_machine = ""
3441 let b:netrw_fname = ""
3442 let g:netrw_port = ""
3443
3444 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003445 " mipf : a:machine a:id password filename Use ftp
3446 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003447 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003448 " rcpurm : rcp://[user@]host/filename Use rcp
3449 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003450 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003451 " httpurm : http://[user@]host/filename Use wget
3452 " davurm : [s]dav://host[:port]/path Use cadaver
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003453 " rsyncurm : rsync://host[:port]/path Use rsync
3454 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3455 " sftpurm : sftp://[user@]host/filename Use scp
3456 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3457 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
3458 let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003459 let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003460 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003461 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003462 let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003463 let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003464 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
3465 let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
3466 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
3467
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003468" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003469 " Determine Method
3470 " rcp://user@hostname/...path-to-file
3471 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003472" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003473 let b:netrw_method = 1
3474 let userid = substitute(a:choice,rcpurm,'\1',"")
3475 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3476 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003477 if userid != ""
3478 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003480
3481 " scp://user@hostname/...path-to-file
3482 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003483" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003484 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003485 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3486 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3487 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003488
3489 " http://user@hostname/...path-to-file
3490 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003491" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003492 let b:netrw_method = 5
3493 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3494 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
3495
3496 " dav://hostname[:port]/..path-to-file..
3497 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003498" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003499 let b:netrw_method= 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003500 if a:choice =~ '^s'
3501 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3502 else
3503 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3504 endif
3505 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003506
3507 " rsync://user@hostname/...path-to-file
3508 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003509" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003510 let b:netrw_method = 7
3511 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3512 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
3513
3514 " ftp://[user@]hostname[[:#]port]/...path-to-file
3515 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003516" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003517 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003518 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3519 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3520 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003521 if userid != ""
3522 let g:netrw_uid= userid
3523 endif
3524 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3525 let b:netrw_method = 3
3526 else
3527 if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc")
3528 let b:netrw_method= 2
3529 else
3530 if !exists("g:netrw_uid") || g:netrw_uid == ""
3531 call NetUserPass()
3532 elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
3533 call NetUserPass(g:netrw_uid)
3534 " else just use current g:netrw_uid and g:netrw_passwd
3535 endif
3536 let b:netrw_method= 3
3537 endif
3538 endif
3539
3540 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003541" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003542 let b:netrw_method = 8
3543 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3544 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3545 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3546 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
3547
3548 " Issue an ftp : "machine id password [path/]filename"
3549 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003550" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003551 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003552 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3553 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
3554 let g:netrw_passwd = substitute(a:choice,mipf,'\3',"")
3555 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
3556
3557 " Issue an ftp: "hostname [path/]filename"
3558 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003559" call Decho("(ftp) host file")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003560 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3561 let b:netrw_method = 3
3562 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3563 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3564
3565 elseif filereadable(expand("$HOME/.netrc"))
3566 let b:netrw_method = 2
3567 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3568 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3569 endif
3570
3571 " sftp://user@hostname/...path-to-file
3572 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003573" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003574 let b:netrw_method = 9
3575 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3576 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
3577
3578 " Issue an rcp: hostname:filename" (this one should be last)
3579 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003580" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003581 let b:netrw_method = 1
3582 let userid = substitute(a:choice,rcphf,'\2',"")
3583 let g:netrw_machine= substitute(a:choice,rcphf,'\3',"")
3584 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003585" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
3586" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
3587" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
3588" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003589 if userid != ""
3590 let g:netrw_uid= userid
3591 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003592 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003593 " don't let PCs try <.netrc>
3594 let b:netrw_method = 3
3595 endif
3596
3597 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003598 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003599 echohl Error | echo "***netrw*** cannot determine method" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003600 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003601 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003602 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 endif
Bram Moolenaar81695252004-12-29 20:58:21 +00003604
3605 " remove any leading [:#] from port number
3606 if g:netrw_port != ""
3607 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3608 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003609
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003610" call Decho("a:choice <".a:choice.">")
3611" call Decho("b:netrw_method <".b:netrw_method.">")
3612" call Decho("g:netrw_machine<".g:netrw_machine.">")
3613" call Decho("g:netrw_port <".g:netrw_port.">")
3614" if exists("g:netrw_uid") "Decho
3615" call Decho("g:netrw_uid <".g:netrw_uid.">")
3616" endif "Decho
3617" if exists("g:netrw_passwd") "Decho
3618" call Decho("g:netrw_passwd <".g:netrw_passwd.">")
3619" endif "Decho
3620" call Decho("b:netrw_fname <".b:netrw_fname.">")
3621" call Dret("NetMethod")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623
3624" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003625" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626" Usage: :call NetUserPass() -- will prompt for userid and password
3627" :call NetUserPass("uid") -- will prompt for password
3628" :call NetUserPass("uid","password") -- sets global userid and password
3629fun! NetUserPass(...)
3630
3631 " get/set userid
3632 if a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003633" call Dfunc("NetUserPass(a:0<".a:0.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634 if !exists("g:netrw_uid") || g:netrw_uid == ""
3635 " via prompt
3636 let g:netrw_uid= input('Enter username: ')
3637 endif
3638 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003639" call Dfunc("NetUserPass(a:1<".a:1.">) {")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003640 let g:netrw_uid= a:1
3641 endif
3642
3643 " get password
3644 if a:0 <= 1 " via prompt
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003645" call Decho("a:0=".a:0." case <=1:")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 let g:netrw_passwd= inputsecret("Enter Password: ")
3647 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003648" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 let g:netrw_passwd=a:2
3650 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003651
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003652" call Dret("NetUserPass")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654
3655" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003656" NetOptionSave: save options and set to "standard" form {{{2
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003657fun! s:NetOptionSave()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003658" call Dfunc("NetOptionSave()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003659 if !exists("w:netoptionsave")
3660 let w:netoptionsave= 1
3661 else
3662" call Dret("NetOptionSave : netoptionsave=".w:netoptionsave)
3663 return
3664 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003666 " Get Temporary Filename
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003667 let w:aikeep = &ai
3668 " record autochdir setting and then insure its unset (tnx to David Fishburn)
3669 if has("netbeans_intg") || has("sun_workshop")
3670 let w:acdkeep = &autochdir
3671 set noautochdir
3672 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003673 let w:cinkeep = &cin
3674 let w:cinokeep = &cino
3675 let w:comkeep = &com
3676 let w:cpokeep = &cpo
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003677 if !g:netrw_keepdir
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003678 let w:dirkeep = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003679 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003680 let w:gdkeep = &gd
3681 let w:repkeep = &report
3682 let w:spellkeep = &spell
3683 let w:twkeep = &tw
Bram Moolenaar8299df92004-07-10 09:47:34 +00003684 setlocal cino =
3685 setlocal com =
3686 setlocal cpo -=aA
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003687 setlocal nocin noai nospell
Bram Moolenaar8299df92004-07-10 09:47:34 +00003688 setlocal tw =0
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003689 setlocal report=10000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003690 if has("win32") && !has("win95")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003691 let w:swfkeep= &swf
Bram Moolenaar8299df92004-07-10 09:47:34 +00003692 setlocal noswf
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003693" call Decho("setting w:swfkeep to <".&swf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003694 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003696" call Dret("NetOptionSave")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003697endfun
3698
3699" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003700" NetOptionRestore: restore options {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701fun! s:NetOptionRestore()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003702" call Dfunc("NetOptionRestore()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003703 if !exists("w:netoptionsave")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003704" call Dret("NetOptionRestore : w:netoptionsave doesn't exist")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003705 return
3706 endif
3707 unlet w:netoptionsave
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003708
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003709 if exists("w:aikeep")| let &ai= w:aikeep|endif
3710 if (has("netbeans_intg") || has("sun_workshop")) && exists("w:acdkeep")
3711 let &acd= w:acdkeep
3712 unlet w:acdkeep
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003713 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003714 if exists("w:cinkeep") |let &cin = w:cinkeep |unlet w:cinkeep |endif
3715 if exists("w:cinokeep") |let &cino = w:cinokeep |unlet w:cinokeep |endif
3716 if exists("w:comkeep") |let &com = w:comkeep |unlet w:comkeep |endif
3717 if exists("w:cpokeep") |let &cpo = w:cpokeep |unlet w:cpokeep |endif
3718 if exists("w:dirkeep") |exe "lcd ".w:dirkeep |unlet w:dirkeep |endif
3719 if exists("w:gdkeep") |let &gd = w:gdkeep |unlet w:gdkeep |endif
3720 if exists("w:repkeep") |let &report = w:repkeep |unlet w:repkeep |endif
3721 if exists("w:spellkeep")|let &spell = w:spellkeep |unlet w:spellkeep|endif
3722 if exists("w:twkeep") |let &tw = w:twkeep |unlet w:twkeep |endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003723 if exists("w:swfkeep")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003724 if &directory == "" && exists("w:swfkeep")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003725 " user hasn't specified a swapfile directory;
3726 " netrw will temporarily make the swapfile
3727 " directory the current local one.
3728 let &directory = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003729 silent! let &swf = w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003730 set directory=
3731 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003732 let &swf= w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003733 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003734 unlet w:swfkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003735 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003736
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003737" call Dret("NetOptionRestore")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738endfun
3739
3740" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003741" NetReadFixup: this sort of function is typically written by the user {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003742" to handle extra junk that their system's ftp dumps
3743" into the transfer. This function is provided as an
3744" example and as a fix for a Windows 95 problem: in my
3745" experience, win95's ftp always dumped four blank lines
3746" at the end of the transfer.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003747if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 fun! NetReadFixup(method, line1, line2)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003749" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 if method == 3 " ftp (no <.netrc>)
3751 let fourblanklines= line2 - 3
3752 silent fourblanklines.",".line2."g/^\s*/d"
3753 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003754" call Dret("NetReadFixup")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 endfun
3756endif
3757
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003758" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003759" NetSort: Piet Delport's BISort2() function, modified to take a range {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00003760if v:version < 700
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003761 fun! s:NetSort() range
Bram Moolenaar83bab712005-08-01 21:58:57 +00003762" " call Dfunc("NetSort()")
3763
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003764 let i = a:firstline + 1
3765 while i <= a:lastline
3766 " find insertion point via binary search
3767 let i_val = getline(i)
3768 let lo = a:firstline
3769 let hi = i
3770 while lo < hi
Bram Moolenaar83bab712005-08-01 21:58:57 +00003771 let mid = (lo + hi) / 2
3772 let mid_val = getline(mid)
3773 if g:netrw_sort_direction =~ '^n'
3774 " normal sorting order
3775 if i_val < mid_val
3776 let hi = mid
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003777 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003778 let lo = mid + 1
3779 if i_val == mid_val | break | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003780 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003781 else
3782 " reverse sorting order
3783 if i_val > mid_val
3784 let hi = mid
3785 else
3786 let lo = mid + 1
3787 if i_val == mid_val | break | endif
3788 endif
3789 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003790 endwhile
3791 " do insert
3792 if lo < i
Bram Moolenaar83bab712005-08-01 21:58:57 +00003793 exe 'keepjumps '.i.'d_'
3794 keepjumps call append(lo - 1, i_val)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003795 endif
3796 let i = i + 1
3797 endwhile
Bram Moolenaar83bab712005-08-01 21:58:57 +00003798
3799" " call Dret("NetSort")
3800 endfun
3801endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003802
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003803" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003804" SetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00003805" What this function does is to compute a priority for the patterns
3806" in the g:netrw_sort_sequence. It applies a substitute to any
3807" "files" that satisfy each pattern, putting the priority / in
3808" front. An "*" pattern handles the default priority.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003809fun! s:SetSort()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003810" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003811 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00003812 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
3813 else
3814 let seqlist = g:netrw_sort_sequence
3815 endif
3816 " sanity check -- insure that * appears somewhere
3817 if seqlist == ""
3818 let seqlist= '*'
3819 elseif seqlist !~ '\*'
3820 let seqlist= seqlist.',*'
3821 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003822 let priority = 1
3823 while seqlist != ""
3824 if seqlist =~ ','
3825 let seq = substitute(seqlist,',.*$','','e')
3826 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
3827 else
3828 let seq = seqlist
3829 let seqlist = ""
3830 endif
3831 let eseq= escape(seq,'/')
3832 if priority < 10
3833 let spriority= "00".priority.'\/'
3834 elseif priority < 100
3835 let spriority= "0".priority.'\/'
3836 else
3837 let spriority= priority.'\/'
3838 endif
3839" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
3840
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003841 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003842 if w:netrw_bannercnt > line("$")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003843 " apparently no files were left after a Hiding pattern was used
3844" call Dret("SetSort : no files left after hiding")
3845 return
3846 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003847 if seq == '*'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003848 exe 'silent keepjumps '.w:netrw_bannercnt.',$v/^\d\{3}\//s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003849 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003850 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/'.eseq.'/s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003851 endif
3852 let priority = priority + 1
3853 endwhile
3854
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003855 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{3}\/\)\%(\d\{3}\/\)\+/\1/e'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003856
3857" call Dret("SetSort")
3858endfun
3859
Bram Moolenaar488c6512005-08-11 20:09:58 +00003860" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003861" SaveWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00003862fun! s:SaveWinVars()
3863" call Dfunc("SaveWinVars()")
3864 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
3865 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
3866 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
3867 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
3868 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
3869 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
3870 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
3871 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003872 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003873" call Dret("SaveWinVars")
3874endfun
3875
3876" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003877" CopyWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00003878fun! s:CopyWinVars()
3879" call Dfunc("CopyWinVars()")
3880 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
3881 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
3882 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
3883 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
3884 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
3885 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
3886 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
3887 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 +00003888 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 +00003889" call Dret("CopyWinVars")
3890endfun
3891
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003892" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003893" SetBufWinVars: (used by NetBrowse() and LocalBrowse()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003894" To allow separate windows to have their own activities, such as
3895" Explore **/pattern, several variables have been made window-oriented.
3896" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003897" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003898" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003899fun! s:SetBufWinVars()
3900" call Dfunc("SetBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003901 if exists("w:netrw_longlist") |let b:netrw_longlist = w:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003902 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
3903 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
3904 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
3905 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
3906 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen = w:netrw_explore_listlen|endif
3907 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = w:netrw_explore_mtchcnt|endif
3908 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
3909 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
3910 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003911" call Dret("SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003912endfun
3913
3914" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003915" UseBufWinVars: (used by NetBrowse() and LocalBrowse() {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003916" Matching function to BufferWinVars()
3917fun! s:UseBufWinVars()
3918" call Dfunc("UseBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003919 if exists("b:netrw_longlist") && !exists("w:netrw_longlist") |let w:netrw_longlist = b:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003920 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
3921 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
3922 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
3923 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
3924 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
3925 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
3926 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
3927 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
3928 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
3929" call Dret("UseBufWinVars")
3930endfun
3931
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003932" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003933" RFC2396: converts %xx into characters {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003934fun! netrw#RFC2396(fname)
3935" call Dfunc("RFC2396(fname<".a:fname.">)")
3936 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
3937" call Dret("RFC2396 ".fname)
3938 return fname
3939endfun
3940
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003941" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003942" Settings Restoration: {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00003943let &cpo= s:keepcpo
3944unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003945
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003947" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948" vim:ts=8 fdm=marker