blob: f0767abeaa71876182483e35da2fe10bd571dd85 [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 Moolenaar57657d82006-04-21 22:12:41 +00003" Date: Apr 21, 2006
4" Version: 91
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 Moolenaar57657d82006-04-21 22:12:41 +000026let g:loaded_netrw = "v91"
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
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +000079if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +000080 \ && 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 Moolenaar4ea8fe12006-03-09 22:32:39 +0000194if !exists("g:netrw_fastbrowse")
195 let g:netrw_fastbrowse= 1
196endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000197if !exists("g:netrw_sort_by")
198 " alternatives: date size
199 let g:netrw_sort_by= "name"
200endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000201if !exists("g:netrw_sort_direction")
202 " alternative: reverse (z y x ...)
203 let g:netrw_sort_direction= "normal"
204endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000205if !exists("g:netrw_sort_sequence")
206 let g:netrw_sort_sequence= '[\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000207endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000208if !exists("g:netrw_ssh_browse_reject")
209 let g:netrw_ssh_browse_reject='^total\s\+\d\+$'
210endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000211" Default values - t-w ---------- {{{3
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000212if !exists("g:netrw_timefmt")
213 let g:netrw_timefmt= "%c"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000214endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000215if !exists("g:netrw_win95ftp")
216 let g:netrw_win95ftp= 1
217endif
218if !exists("g:netrw_winsize")
219 let g:netrw_winsize= ""
220endif
221" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000222" Default values for netrw's script variables: {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000223if !exists("s:netrw_cd_escape")
224 if has("win32") || has("win95") || has("win64") || has("win16")
225 let s:netrw_cd_escape="#% "
226 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000227 let s:netrw_cd_escape="[]#*$%'\" ?`!&();<>\\"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000228 endif
229endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000230if !exists("g:netrw_fname_escape")
231 let g:netrw_fname_escape= ' ?&;'
232endif
233if !exists("g:netrw_tmpfile_escape")
234 let g:netrw_tmpfile_escape= ' ?&;'
235endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000236if !exists("s:netrw_glob_escape")
237 if has("win32") || has("win95") || has("win64") || has("win16")
238 let s:netrw_glob_escape= ""
239 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000240 let s:netrw_glob_escape= '[]*?`{~$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000241 endif
242endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000243
244" BufEnter event ignored by decho when following variable is true
245" Has a side effect that doau BufReadPost doesn't work, so
246" files read by network transfer aren't appropriately highlighted.
247"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000249" ==============================
250" Netrw Utility Functions: {{{1
251" ==============================
252
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000254" NetSavePosn: saves position of cursor on screen {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000255fun! netrw#NetSavePosn()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000256" call Dfunc("NetSavePosn()")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257 " Save current line and column
Bram Moolenaar488c6512005-08-11 20:09:58 +0000258 let w:netrw_winnr= winnr()
259 let w:netrw_line = line(".")
260 let w:netrw_col = virtcol(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261
262 " Save top-of-screen line
263 norm! H0
Bram Moolenaar488c6512005-08-11 20:09:58 +0000264 let w:netrw_hline= line(".")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000266 call netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000267" 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 +0000268endfun
269
270" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000271" NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000272fun! netrw#NetRestorePosn()
Bram Moolenaar488c6512005-08-11 20:09:58 +0000273" 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 +0000274 let eikeep= &ei
275 set ei=all
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276
Bram Moolenaar81695252004-12-29 20:58:21 +0000277 " restore window
Bram Moolenaar488c6512005-08-11 20:09:58 +0000278" call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w")
279 exe "silent! ".w:netrw_winnr."wincmd w"
Bram Moolenaar572cb562005-08-05 21:35:02 +0000280" if v:shell_error == 0
281" " as suggested by Bram M: redraw on no error
282" " allows protocol error messages to remain visible
283" redraw!
284" endif
Bram Moolenaar81695252004-12-29 20:58:21 +0000285
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286 " restore top-of-screen line
Bram Moolenaar488c6512005-08-11 20:09:58 +0000287" call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z")
288 exe "norm! ".w:netrw_hline."G0z\<CR>"
Bram Moolenaar81695252004-12-29 20:58:21 +0000289
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290 " restore position
Bram Moolenaar488c6512005-08-11 20:09:58 +0000291" call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|")
292 exe "norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293
Bram Moolenaar572cb562005-08-05 21:35:02 +0000294 let &ei= eikeep
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000295" call Dret("NetRestorePosn")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000296endfun
297
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000298" ===============================
299" Netrw Transfer Functions: {{{1
300" ===============================
301
Bram Moolenaar071d4272004-06-13 20:20:40 +0000302" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000303" NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000304fun! netrw#NetRead(mode,...)
305" call Dfunc("NetRead(mode=".a:mode.",...) a:0=".a:0)
306
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000307 " save options
308 call s:NetOptionSave()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000309
310 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000311 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000312 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000313 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000314 elseif a:mode == 2 " replace with remote file
315 let readcmd = "%r"
316 else
317 exe a:mode
318 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000320 let ichoice = (a:0 == 0)? 0 : 1
321" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
322
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000323 " get name of a temporary file and set up shell-quoting character {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000324 let tmpfile= tempname()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000325 let tmpfile= escape(substitute(tmpfile,'\','/','ge'),g:netrw_tmpfile_escape)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000326 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000327 echohl Error | echo "***netrw*** your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!" | echohl None
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000328 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
329" call Dret("NetRead")
330 return
331 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000332" call Decho("tmpfile<".tmpfile.">")
333
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000334 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000335
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000336 " attempt to repeat with previous host-file-etc
337 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000339 let choice = b:netrw_lastfile
340 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000341
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000342 else
343 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000345
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000346 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000347 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000348 echomsg 'NetRead Usage:'
349 echomsg ':Nread machine:path uses rcp'
350 echomsg ':Nread "machine path" uses ftp with <.netrc>'
351 echomsg ':Nread "machine id password path" uses ftp'
352 echomsg ':Nread dav://machine[:port]/path uses cadaver'
353 echomsg ':Nread fetch://machine/path uses fetch'
354 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
355 echomsg ':Nread http://[user@]machine/path uses http wget'
356 echomsg ':Nread rcp://[user@]machine/path uses rcp'
357 echomsg ':Nread rsync://machine[:port]/path uses rsync'
358 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
359 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000360 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000361
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000362 elseif match(choice,"^\"") != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000363 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000364" call Decho("reconstructing choice")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000365 if match(choice,"\"$") != -1
366 " case "..."
367 let choice=strpart(choice,1,strlen(choice)-2)
368 else
369 " case "... ... ..."
370 let choice = strpart(choice,1,strlen(choice)-1)
371 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000372
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000373 while match(choice,"\"$") == -1
374 let wholechoice = wholechoice . " " . choice
375 let ichoice = ichoice + 1
376 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000377 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000378 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000379 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000380 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000381" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000382 return
383 endif
384 let choice= a:{ichoice}
385 endwhile
386 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
387 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388 endif
389 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000391" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000392 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000393
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000394 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000395 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000396 let choice = substitute(choice,'\\','/','ge')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000397" call Decho("fixing up windows url to <".choice."> tmpfile<".tmpfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398
Bram Moolenaar57657d82006-04-21 22:12:41 +0000399 exe 'cd ' . fnamemodify(tmpfile,':h')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000400 let tmpfile = fnamemodify(tmpfile,':t')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000401 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000402
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000403 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000404 call s:NetMethod(choice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000405
Bram Moolenaar843ee412004-06-30 16:16:41 +0000406 " Check if NetBrowse() should be handling this request
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000407" call Decho("checking if NetBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000408 if choice =~ "^.*[\/]$"
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000409" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000410 keepjumps call s:NetBrowse(choice)
411" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000412 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000414
415 " use filename's suffix for the temporary file
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000416 if b:netrw_fname =~ '\.[^./]\+$'
417 let suffix = substitute(b:netrw_fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000418 let tmpfile= substitute(tmpfile,"$",suffix,'e')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000419" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000420 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000421
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000422 " ============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000423 " Perform Protocol-Based Read {{{3
424 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000425 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
426 echo "(netrw) Processing your read request..."
427 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000428
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000429 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000430 " rcp: NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000431 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000432" call Decho("read via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000433 " ER: noting done with g:netrw_uid yet?
434 " ER: on Win2K" rcp machine[.user]:file tmpfile
435 " ER: if machine contains '.' adding .user is required (use $USERNAME)
436 " ER: the tmpfile is full path: rcp sees C:\... as host C
437 if s:netrw_has_nt_rcp == 1
438 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
439 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
440 else
441 " Any way needed it machine contains a '.'
442 let uid_machine = g:netrw_machine .'.'. $USERNAME
443 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000445 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
446 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
447 else
448 let uid_machine = g:netrw_machine
449 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000451" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile)
452 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000453 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
454 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000455
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000456 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000457 " ftp + <.netrc>: NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000458 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000459" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000460 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000461 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000462 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000463 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000464" call Decho("filter input: ".getline("."))
465 exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'"
466" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000467 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000468" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000469 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
470 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000471" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000472 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
473 endif
474 " 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 +0000475 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000476 let debugkeep= &debug
477 set debug=msg
Bram Moolenaar572cb562005-08-05 21:35:02 +0000478 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000479 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000480 let &debug= debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000481 endif
482 bd!
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000483 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000484 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000485
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000486 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000487 " ftp + machine,id,passwd,filename: NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000488 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
489 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000490" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000491 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000493 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000494 if exists("g:netrw_port") && g:netrw_port != ""
495 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000496" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000497 else
498 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000499" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000500 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000501
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000502 if exists("g:netrw_ftp") && g:netrw_ftp == 1
503 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000504" call Decho("filter input: ".getline("."))
505 put ='\"'.g:netrw_passwd.'\"'
506" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000507 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000508 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
509" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000510 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000511
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000512 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
513 put =g:netrw_ftpmode
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000514" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000515 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000516 put ='get \"'.netrw_fname.'\" '.tmpfile
517" call Decho("filter input: ".getline("."))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000518
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000519 " perform ftp:
520 " -i : turns off interactive prompting from ftp
521 " -n unix : DON'T use <.netrc>, even though it exists
522 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000523 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000524" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000525 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
526 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
527 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000528" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000529 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000530 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000531 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000532 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000533 endif
534 bd!
535 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
536 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000537
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000538 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000539 " scp: NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000540 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000541" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000542 if exists("g:netrw_port") && g:netrw_port != ""
543 let useport= " -P ".g:netrw_port
544 else
545 let useport= ""
546 endif
547 if g:netrw_cygwin == 1
548 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000549" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".cygtmpfile)
550 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000551 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000552" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".tmpfile)
553 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000554 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000555 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000556 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000557
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000558 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000559 " http: NetRead Method #5 (wget) {{{3
560 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000561" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000562 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000563 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000564 echohl Error | echo "***netrw*** neither wget nor fetch command is available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000565 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000566 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000567" call Dret("NetRead")
568 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000571 if match(b:netrw_fname,"#") == -1
572 " simple wget
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000573 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
574" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname)
575 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000576 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000577
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000578 else
579 " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000580 let netrw_html= substitute(netrw_fname,"#.*$","","")
581 let netrw_tag = substitute(netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000582" call Decho("netrw_html<".netrw_html.">")
583" call Decho("netrw_tag <".netrw_tag.">")
584" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000585 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html
586 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000587" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000588 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
589 endif
590 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000591
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000592 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000593 " cadaver: NetRead Method #6 {{{3
594 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000595" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000596
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000597 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000598 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000599 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000600 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000601 if exists("g:netrw_port") && g:netrw_port != ""
602 put ='open '.g:netrw_machine.' '.g:netrw_port
603 else
604 put ='open '.g:netrw_machine
605 endif
606 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000607
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000608 if g:netrw_cygwin == 1
609 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
610 put ='get '.netrw_fname.' '.cygtmpfile
611 else
612 put ='get '.netrw_fname.' '.tmpfile
613 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000614 put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000615
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000616 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000617 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000618" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000619 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
620 bd!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000621 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000622 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000623
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000624 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000625 " rsync: NetRead Method #7 {{{3
626 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000627" call Decho("read via rsync (method #7)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000628 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000629 if g:netrw_cygwin == 1
630 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000631" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
632 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000633 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000634" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile)
635 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000636 endif
637 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
638 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000639
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000640 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000641 " fetch: NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000642 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000643 elseif b:netrw_method == 8
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000644 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000645 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000646 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000647 echohl Error | echo "***netrw*** fetch command not available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000648 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000649 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000650" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000651 endif
652 if exists("g:netrw_option") && g:netrw_option == ":http"
653 let netrw_option= "http"
654 else
655 let netrw_option= "ftp"
656 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000657" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000658
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000659 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000660" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname)
661 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000662 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000663" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname)
664 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000665 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000666
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000667 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
668 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000669
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000670 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000671 " sftp: NetRead Method #9 {{{3
672 elseif b:netrw_method == 9
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000673" call Decho("read via sftp (method #4)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000674 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000675 if g:netrw_cygwin == 1
676 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000677" call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
678" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
679 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000680 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000681" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile)
682 exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000683 endif
684 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
685 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000686
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000687 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000688 " Complain {{{3
689 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000690 echo "***warning*** unable to comply with your request<" . choice . ">"
691 endif
692 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000693
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000694 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000695" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000696 if exists("b:netrw_method")
697 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000698 unlet b:netrw_fname
699 endif
700 call s:NetOptionRestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +0000701
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000702" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000703endfun
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000704
705" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000706" NetGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000707" readcmd == %r : replace buffer with newly read file
708" == 0r : read file at top of buffer
709" == r : read file after current line
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000710fun! s:NetGetFile(readcmd, tfile, method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000711" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000712
713 " get name of remote filename (ie. url and all)
714 let rfile= bufname("%")
715" call Decho("rfile<".rfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000717 if exists("*NetReadFixup")
718 " for the use of NetReadFixup (not otherwise used internally)
719 let line2= line("$")
720 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000721
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000722 " transform paths from / to \ for Windows (except for cygwin)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000723 if &term == "win32"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000724 if g:netrw_cygwin
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000725 let tfile= a:tfile
726" call Decho("(win32 && cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000727 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000728 let tfile= substitute(a:tfile,'/','\\\\','ge')
729" call Decho("(win32 && !cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000730 endif
731 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000732 let tfile= a:tfile
733" call Decho("tfile=a:tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000734 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000735
736 if a:readcmd[0] == '%'
Bram Moolenaar81695252004-12-29 20:58:21 +0000737 " get file into buffer
Bram Moolenaar83bab712005-08-01 21:58:57 +0000738
Bram Moolenaar83bab712005-08-01 21:58:57 +0000739" call Dredir("ls!","starting buffer list")
740
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000741 " rename the current buffer to the temp file (ie. tfile)
742 keepalt exe "file ".tfile
743" call Dredir("ls!","after renaming current buffer to <".tfile.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +0000744
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000745 " edit temporary file (ie. read the temporary file in)
746 if rfile =~ '\.zip$'
747 call zip#Browse(tfile)
748 elseif rfile =~ '\.tar$'
749 call tar#Browse(tfile)
750 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000751" call Decho("edit temporary file")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000752 e
753 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +0000754
Bram Moolenaar81695252004-12-29 20:58:21 +0000755 " rename buffer back to remote filename
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000756 keepalt exe "file ".escape(rfile,' ')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000757 filetype detect
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000758" call Dredir("ls!","renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">")
Bram Moolenaar81695252004-12-29 20:58:21 +0000759 let line1 = 1
760 let line2 = line("$")
761
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000762 elseif filereadable(tfile)
Bram Moolenaar81695252004-12-29 20:58:21 +0000763 " read file after current line
764 let curline = line(".")
765 let lastline= line("$")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000766" call Decho("exe<".a:readcmd." ".v:cmdarg." ".tfile."> line#".curline)
767 exe a:readcmd." ".v:cmdarg." ".tfile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000768 let line1= curline + 1
769 let line2= line("$") - lastline + 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000770
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000771 else
Bram Moolenaar81695252004-12-29 20:58:21 +0000772 " not readable
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000773 echohl WarningMsg | echo "***netrw*** file <".tfile."> not readable"| echohl None
774 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
775" call Dret("NetGetFile : tfile<".tfile."> not readable")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000776 return
777 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000778
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000779 " User-provided (ie. optional) fix-it-up command
780 if exists("*NetReadFixup")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000781" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000782 call NetReadFixup(a:method, line1, line2)
Bram Moolenaar83bab712005-08-01 21:58:57 +0000783" else " Decho
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000784" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000785 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000786
787 " update the Buffers menu
788 if has("gui") && has("gui_running")
789 silent! emenu Buffers.Refresh\ menu
790 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000791
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000792" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".filereadable(a:tfile))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000793
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000794 " make sure file is being displayed
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000795 redraw!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000796" call Dret("NetGetFile")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000797endfun
798
799" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000800" NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000801fun! netrw#NetWrite(...) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000802" call Dfunc("NetWrite(a:0=".a:0.")")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000804 " option handling
805 let mod= 0
806 call s:NetOptionSave()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000807
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000808 " Get Temporary Filename {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000809 let tmpfile= escape(tempname(),g:netrw_tmpfile_escape)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000810 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
811 echohl Error | echo "***netrw*** your ".substitute(tmpfile,'[^/]\+$','','e')." directory is missing!"
812 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000813" call Dret("NetWrite")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000814 return
815 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000816
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000817 if a:0 == 0
818 let ichoice = 0
819 else
820 let ichoice = 1
821 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000822
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000823 if &binary
824 " for binary writes, write entire file. Line numbers don't really make sense.
825 " Supports the writing of tar and zip files.
826" call Decho("silent exe w! ".v:cmdarg." ".tmpfile)
827 silent exe "w! ".v:cmdarg." ".tmpfile
828 else
829 " write (selected portion of) file to temporary
830" call Decho("silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile)
831 silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
832 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000833
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000834 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000835
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000836 " Process arguments: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000837 " attempt to repeat with previous host-file-etc
838 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000839" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000840 let choice = b:netrw_lastfile
841 let ichoice= ichoice + 1
842 else
843 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000844
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000845 " Reconstruct Choice if choice starts with '"'
846 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000847 echomsg 'NetWrite Usage:"'
848 echomsg ':Nwrite machine:path uses rcp'
849 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
850 echomsg ':Nwrite "machine id password path" uses ftp'
851 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
852 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
853 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
854 echomsg ':Nwrite rcp://machine/path uses rcp'
855 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
856 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
857 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000858 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000859
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000860 elseif match(choice,"^\"") != -1
861 if match(choice,"\"$") != -1
862 " case "..."
863 let choice=strpart(choice,1,strlen(choice)-2)
864 else
865 " case "... ... ..."
866 let choice = strpart(choice,1,strlen(choice)-1)
867 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000868
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000869 while match(choice,"\"$") == -1
870 let wholechoice= wholechoice . " " . choice
871 let ichoice = ichoice + 1
872 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000873 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000874 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000875 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000876 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000877" call Dret("NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000878 return
879 endif
880 let choice= a:{ichoice}
881 endwhile
882 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
883 endif
884 endif
885 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000886" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000887 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000888
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000889 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000890 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000891 let choice= substitute(choice,'\\','/','ge')
892 "ER: see NetRead()
Bram Moolenaar57657d82006-04-21 22:12:41 +0000893 exe 'cd ' . fnamemodify(tmpfile,':h')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000894 let tmpfile = fnamemodify(tmpfile,':t')
895 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000896
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000897 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000898 call s:NetMethod(choice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000899
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000900 " =============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000901 " Perform Protocol-Based Write {{{3
902 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000903 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
904 echo "(netrw) Processing your write request..."
905 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000906
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000907 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000908 " rcp: NetWrite Method #1 {{{3
909 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000910" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000911 if s:netrw_has_nt_rcp == 1
912 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
913 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
914 else
915 let uid_machine = g:netrw_machine .'.'. $USERNAME
916 endif
917 else
918 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
919 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
920 else
921 let uid_machine = g:netrw_machine
922 endif
923 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000924 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
925" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".netrw_fname)
926 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000927 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000928
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000929 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000930 " ftp + <.netrc>: NetWrite Method #2 {{{3
931 elseif b:netrw_method == 2
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000932 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000933 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000934 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000936" call Decho(" filter input: ".getline("."))
937 exe "put ='"."put ".tmpfile.' \"'.netrw_fname.'\"'."'"
938" call Decho(" filter input: ".getline("."))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000939 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000940" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000941 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000943" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000944 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 endif
946 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
947 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000948 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000949 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000950 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000951 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000952 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 endif
954 bd!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000956
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000957 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000958 " ftp + machine, id, passwd, filename: NetWrite Method #3 {{{3
959 elseif b:netrw_method == 3
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000960 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000961 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000962 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000963 if exists("g:netrw_port") && g:netrw_port != ""
964 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000965" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000966 else
967 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000968" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000969 endif
970 if exists("g:netrw_ftp") && g:netrw_ftp == 1
971 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000972" call Decho("filter input: ".getline("."))
973 put ='\"'.g:netrw_passwd.'\"'
974" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000975 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000976 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
977" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000978 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000979 put ='put '.tmpfile.' \"'.netrw_fname.'\"'
980" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000981 " save choice/id/password for future use
982 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000983
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000984 " perform ftp:
985 " -i : turns off interactive prompting from ftp
986 " -n unix : DON'T use <.netrc>, even though it exists
987 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000988 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000989" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000990 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
991 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
992 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000993 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000994 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000995 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000996 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000997 let mod=1
998 endif
999 bd!
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001001 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001002 " scp: NetWrite Method #4 {{{3
1003 elseif b:netrw_method == 4
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001004 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001005 if exists("g:netrw_port") && g:netrw_port != ""
1006 let useport= " -P ".g:netrw_port
1007 else
1008 let useport= ""
1009 endif
1010 if g:netrw_cygwin == 1
1011 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001012" call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".netrw_fname."'")
1013 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".netrw_fname."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001014 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001015" call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".netrw_fname."'")
1016 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".netrw_fname."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001017 endif
1018 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001019
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001020 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001021 " http: NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001022 elseif b:netrw_method == 5
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001023 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001024 echohl Error | echo "***netrw*** currently <netrw.vim> does not support writing using http:" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001025 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001026 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001027
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001028 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001029 " dav: NetWrite Method #6 (cadaver) {{{3
1030 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001031" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001032
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001033 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001034 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001035 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001036 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001037 if exists("g:netrw_port") && g:netrw_port != ""
1038 put ='open '.g:netrw_machine.' '.g:netrw_port
1039 else
1040 put ='open '.g:netrw_machine
1041 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001043
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001044 if g:netrw_cygwin == 1
1045 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
1046 put ='put '.cygtmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001048 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001050
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001051 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001052 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001053" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001054 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
1055 bd!
1056 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001057
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001058 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001059 " rsync: NetWrite Method #7 {{{3
1060 elseif b:netrw_method == 7
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001061 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001062 if g:netrw_cygwin == 1
1063 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001064" call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".netrw_fname)
1065 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001067" call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname)
1068 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001070 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001072 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001073 " sftp: NetWrite Method #9 {{{3
1074 elseif b:netrw_method == 9
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001075 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1077 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1078 else
1079 let uid_machine = g:netrw_machine
1080 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001081 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001082 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001084 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001085" call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001086 exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine
1087 bd!
1088 let b:netrw_lastfile= choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001089
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001090 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001091 " Complain {{{3
1092 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001093 echo "***warning*** unable to comply with your request<" . choice . ">"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001095 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001096
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001097 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001098" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001099 let result=delete(tmpfile)
1100 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001101
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001102 if a:firstline == 1 && a:lastline == line("$")
1103 let &mod= mod " usually equivalent to set nomod
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001105
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001106" call Dret("NetWrite")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108
Bram Moolenaar83bab712005-08-01 21:58:57 +00001109" ===========================================
1110" Remote Directory Browsing Support: {{{1
1111" ===========================================
1112
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001113" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001114" NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001115" of the contents of a remote directory. It is assumed that the
1116" g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted
1117" with the requested remote hostname first.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001118fun! s:NetBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001119 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
1120" call Dfunc("NetBrowse(dirname<".a:dirname.">) longlist=".w:netrw_longlist)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001121
Bram Moolenaar488c6512005-08-11 20:09:58 +00001122 if exists("s:netrw_skipbrowse")
1123 unlet s:netrw_skipbrowse
1124" call Dret("NetBrowse")
1125 return
1126 endif
1127
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001128 call s:NetOptionSave()
1129
Bram Moolenaar843ee412004-06-30 16:16:41 +00001130 " sanity check
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001131 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
1132" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001133 if !executable("ftp")
1134 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001135 echohl Error | echo "***netrw*** this system doesn't support remote directory listing via ftp" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001136 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001137 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001138 call s:NetOptionRestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001139" call Dret("NetBrowse")
1140 return
1141 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001142 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001143 if !exists("g:netrw_quiet")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001144 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 +00001145 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001146 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001147
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001148 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001149" call Dret("NetBrowse")
1150 return
Bram Moolenaar843ee412004-06-30 16:16:41 +00001151 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001152
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001153 " use buffer-oriented WinVars if buffer ones exist but window ones don't
1154 call s:UseBufWinVars()
1155
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001156 " set up menus
1157 let b:netrw_browser_active= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001158 call s:NetMenu(1)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001159
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001160 " make this buffer modifiable
Bram Moolenaar83bab712005-08-01 21:58:57 +00001161 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001162
1163 " analyze a:dirname and g:netrw_list_cmd
1164 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001165 let dirname = substitute(a:dirname,'\\','/','ge')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001166" call Decho("dirname<".dirname.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001167 if dirname !~ dirpat
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001168 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001169 echohl Error | echo "***netrw*** netrw doesn't understand your dirname<".dirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001170 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001171 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001172 call s:NetOptionRestore()
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001173" call Dret("NetBrowse : badly formatted dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001174 return
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001175 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001176
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001177 let method = substitute(dirname,dirpat,'\1','')
1178 let user = substitute(dirname,dirpat,'\2','')
1179 let machine = substitute(dirname,dirpat,'\3','')
1180 let path = substitute(dirname,dirpat,'\4','')
1181 let fname = substitute(dirname,'^.*/\ze.','','')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001182" call Decho("set up method <".method .">")
1183" call Decho("set up user <".user .">")
1184" call Decho("set up machine<".machine.">")
1185" call Decho("set up path <".path .">")
1186" call Decho("set up fname <".fname .">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001187
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001188 if method == "ftp" || method == "http"
1189 let method = "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001190 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001191 else
1192 let listcmd = substitute(g:netrw_list_cmd,'\<HOSTNAME\>',user.machine,'')
1193 endif
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001194
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001195 if exists("b:netrw_method")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001196" call Decho("setting w:netrw_method<".b:netrw_method.">")
1197 let w:netrw_method= b:netrw_method
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001198 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001199
Bram Moolenaar8299df92004-07-10 09:47:34 +00001200 " optionally sort by time (-t) or by size (-S)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001201 if listcmd == "dir" && g:netrw_sort_by =~ "^[ts]"
Bram Moolenaar572cb562005-08-05 21:35:02 +00001202 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 +00001203 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001204 else
1205 if g:netrw_sort_by =~ "^t"
1206 let listcmd= listcmd."t"
1207 elseif g:netrw_sort_by =~ "^s"
1208 let listcmd= listcmd."S"
1209 endif
1210 " optionally sort in reverse
1211 if g:netrw_sort_direction =~ "^r" && listcmd == "dir"
1212 let listcmd= listcmd."r"
1213 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001214 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001215
1216" call Decho("set up listcmd<".listcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001217 if fname =~ '@$' && fname !~ '^"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001218" call Decho("attempt transfer of symlink as file")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001219 call s:NetBrowse(substitute(dirname,'@$','','e'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001220 redraw!
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001221 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001222" call Dret("NetBrowse : symlink")
1223 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001224
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001225 elseif fname !~ '[\/]$' && fname !~ '^"'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001226 " looks like a regular file, attempt transfer
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001227" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001228
1229 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001230 " "this is a directory" indicator (/). There shouldn't be one of those,
1231 " anyway.
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001232 let path= substitute(path,'[*=@|]\r\=$','','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001233" call Decho("new path<".path.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001234
1235 " remote-read the requested file into current buffer
Bram Moolenaar57657d82006-04-21 22:12:41 +00001236 mark '
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001237 keepjumps keepalt enew!
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001238 set ma
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001239" call Decho("exe file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001240 exe "file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001241 exe "silent doau BufReadPre ".fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001242 silent call netrw#NetRead(2,method."://".user.machine."/".path)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001243 exe "silent doau BufReadPost ".fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001244
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001245 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001246 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001247 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001248 setlocal nomod nowrap
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001249
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001250" call Dret("NetBrowse : file<".fname.">")
1251 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001252 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001253
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001254 " ---------------------------------------------------------------------
1255 " Perform Directory Listing:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001256" call Decho("Perform directory listing...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001257 " set up new buffer and map
1258 let bufname = method.'://'.user.machine.'/'.path
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001259 let bufnamenr = bufnr(bufname.'$')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001260" call Decho("bufname<".bufname."> bufnamenr=".bufnamenr)
Bram Moolenaar57657d82006-04-21 22:12:41 +00001261 mark '
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001262 if bufnamenr != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001263 " buffer already exists, switch to it!
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001264" call Decho("buffer already exists, switching to it")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001265 exe "b ".bufnamenr
1266 if line("$") >= 5
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001267 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001268" call Dret("NetBrowse")
1269 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001270 endif
1271 else
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001272" call Decho("generate a new buffer")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001273 keepjumps keepalt enew!
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001274 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001275
1276 " rename file to reflect where its from
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001277 setlocal bt=nofile bh=wipe nobl noswf
1278 exe "setlocal ts=".g:netrw_maxfilenamelen
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001279" call Decho("exe file ".escape(bufname,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001280 exe 'file '.escape(bufname,s:netrw_cd_escape)
Bram Moolenaar269ec652004-07-29 08:43:53 +00001281" call Decho("renaming file to bufname<".bufname.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001282 setlocal bt=nofile nobl nonu noswf
1283 if g:netrw_fastbrowse >= 1
1284 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001285 else
1286 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001287 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001288
1289 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001290 call s:NetBookmarkDir(3,expand("%"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001291
1292 " set up buffer-local mappings
1293" call Decho("set up buffer-local mappings")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001294 nnoremap <buffer> <silent> <cr> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001295 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>NetBrowseChgDir(expand("%"),'./'),0)<cr>
Bram Moolenaar843ee412004-06-30 16:16:41 +00001296 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'../'))<cr>
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001297 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 +00001298 if w:netrw_longlist != 2
1299 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1300 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,expand("%"))<cr>
1301 endif
1302 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1303 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001304 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(0)<cr>
1305 nnoremap <buffer> <silent> i :call <SID>NetLongList(0)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001306 nnoremap <buffer> <silent> o :call <SID>NetSplit(0)<cr>
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001307 nnoremap <buffer> <silent> O :call netrw#NetObtain()<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001308 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(0)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001309 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,expand("%"))<cr>
1310 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>
1311 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>
1312 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001313 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
1314 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001315 nnoremap <buffer> <silent> v :call <SID>NetSplit(1)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001316 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()),1)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001317 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001318 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001319 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001320 exe 'nnoremap <buffer> <silent> d :call <SID>NetMakeDir("'.user.machine.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001321 exe 'nnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001322 exe 'vnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001323 exe 'nnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00001324 exe 'vnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar433f7c82006-03-21 21:29:36 +00001325 nnoremap <buffer> <F1> :he netrw-browse-cmds<cr>
Bram Moolenaar83bab712005-08-01 21:58:57 +00001326 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001327
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001328 " Set up the banner
Bram Moolenaar57657d82006-04-21 22:12:41 +00001329" call Decho("set up the banner: sortby<".g:netrw_sort_by."> method<".method."> direction<".g:netrw_sort_direction.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001330 keepjumps put ='\" ==========================================================================='
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001331 keepjumps put ='\" Netrw Remote Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001332 keepjumps put ='\" '.bufname
Bram Moolenaar488c6512005-08-11 20:09:58 +00001333 let w:netrw_bannercnt = 7
1334 let sortby = g:netrw_sort_by
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001335 if g:netrw_sort_direction =~ "^r"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001336 let sortby = sortby." reversed"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001337 endif
1338
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001339 if g:netrw_sort_by =~ "^n"
1340 " sorted by name
Bram Moolenaar488c6512005-08-11 20:09:58 +00001341 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001342 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001343 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
1344 else
1345 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001346 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001347 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001348 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001349" call Decho("g:netrw_hide=".g:netrw_hide)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001350 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001351 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001352 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001353 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001354 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00001355 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar843ee412004-06-30 16:16:41 +00001356 endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001357 keepjumps put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001358 keepjumps put ='\" ==========================================================================='
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001359
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001360 " remote read the requested directory listing
1361 " Use ftp if that was the file-transfer method selected, otherwise use ssh
1362 " Note that not all ftp servers honor the options for ls
1363 if method == "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001364 " use ftp to get remote file listing
1365" call Decho("use ftp to get remote file listing")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001366 call s:NetBrowseFtpCmd(path,listcmd)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001367 keepjumps 1d
1368
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001369 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001370 " shorten the listing
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001371" call Decho("generate short listing")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001372 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001373
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001374 " cleanup
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001375 if g:netrw_ftp_browse_reject != ""
1376 exe "silent! g/".g:netrw_ftp_browse_reject."/keepjumps d"
1377 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001378 silent! keepjumps %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001379
1380 " if there's no ../ listed, then put ./ and ../ in
1381 let line1= line(".")
1382 keepjumps 1
1383 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1384 let line2= line(".")
1385 if line2 == 0
1386 keepjumps put='../'
1387 keepjumps put='./'
1388 endif
1389 exe "keepjumps ".line1
1390 keepjumps norm! 0
1391
1392 " more cleanup
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001393 exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
1394 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
1395 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001396 endif
1397
1398 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001399 " use ssh to get remote file listing
1400" call Decho("use ssh to get remote file listing")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001401 let shq= &shq? &shq : ( &sxq? &sxq : "'")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001402" call Decho("exe silent r! ".listcmd." '".shq.escape(path,s:netrw_cd_escape).shq."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001403 exe "silent r! ".listcmd." ".shq.escape(path,s:netrw_cd_escape).shq
1404 keepjumps 1d
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001405 " cleanup
1406 if g:netrw_ftp_browse_reject != ""
1407 exe "silent! g/".g:netrw_ssh_browse_reject."/keepjumps d"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001408 endif
1409 endif
1410
1411 " set up syntax highlighting
1412 if has("syntax")
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001413 setlocal ft=netrw
Bram Moolenaar572cb562005-08-05 21:35:02 +00001414 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001415 setlocal ft=
Bram Moolenaar572cb562005-08-05 21:35:02 +00001416 " Ugly workaround -- when syntax highlighting is off and laststatus==2,
1417 " sometimes the laststatus highlight bleeds into the entire display.
1418 " Only seems to happen with remote browsing. Weird.
1419 redraw
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001420 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001421 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001422
1423 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001424 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00001425 if g:netrw_hide && g:netrw_list_hide != ""
1426 call s:NetrwListHide()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001427 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001428
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001429 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00001430 " do a long listing; these substitutions need to be done prior to sorting
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001431" call Decho("manipulate long listing")
1432
1433 if method == "ftp"
1434 " cleanup
Bram Moolenaar488c6512005-08-11 20:09:58 +00001435 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar572cb562005-08-05 21:35:02 +00001436 while getline(".") =~ g:netrw_ftp_browse_reject
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001437 keepjumps d
1438 endwhile
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001439 " if there's no ../ listed, then put ./ and ../ in
1440 let line1= line(".")
1441 keepjumps 1
1442 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1443 let line2= line(".")
1444 if line2 == 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00001445 exe 'keepjumps '.w:netrw_bannercnt."put='./'"
1446 exe 'keepjumps '.w:netrw_bannercnt."put='../'"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001447 endif
1448 exe "keepjumps ".line1
1449 keepjumps norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001450 endif
1451
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001452 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/ -> .*$//e'
1453 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
1454 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar8299df92004-07-10 09:47:34 +00001455 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001456
Bram Moolenaar488c6512005-08-11 20:09:58 +00001457 if line("$") >= w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001458 if g:netrw_sort_by =~ "^n"
1459 call s:SetSort()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001460 if g:netrw_sort_direction =~ 'n'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001461 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001462 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001463 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
Bram Moolenaar83bab712005-08-01 21:58:57 +00001464 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001465 " remove priority pattern prefix
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001466 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001467 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001468 if w:netrw_longlist == 1
1469 " shorten the list to keep its width <= winwidth characters
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001470 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\t[-dstrwx]\+/\t/e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001471 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001472 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001473 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001474
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001475 call s:NetrwWideListing()
1476 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001477 " place cursor on the top-left corner of the file listing
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001478 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001479 norm! 0
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001480 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001481
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001482 call s:NetOptionRestore()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001483 setlocal nomod noma nonu
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001484
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001485" call Dret("NetBrowse")
1486 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001487endfun
1488
1489" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001490" NetBrowseChgDir: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001491fun! s:NetBrowseChgDir(dirname,newdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001492" call Dfunc("NetBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001493
1494 let dirname= a:dirname
Bram Moolenaar843ee412004-06-30 16:16:41 +00001495 let newdir = a:newdir
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001496
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001497 if newdir !~ '[\/]$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001498 " handling a file
1499 let dirname= dirname.newdir
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001500 let didfile= 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001501 if g:netrw_browse_split == 1
1502 new
1503 wincmd _
1504 elseif g:netrw_browse_split == 2
1505 rightb vert new
1506 wincmd |
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001507 else
1508 " handling a file, didn't split, so possibly remove menu
1509 call s:NetMenu(0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001510 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001511" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001512
1513 elseif newdir == './'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001514 " refresh the directory list
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001515" call Decho("refresh directory listing")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001516 setlocal ma nobl
1517 if g:netrw_fastbrowse >= 1
1518 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001519 else
1520 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001521 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001522 %d
1523
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001524 elseif newdir == '../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001525 " go up one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001526 let trailer= substitute(a:dirname,'^\(\w\+://\%(\w\+@\)\=\w\+/\)\(.*\)$','\2','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001527
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001528 if trailer =~ '^\%(\.\./\)*$'
1529 " tack on a ../"
1530 let dirname= dirname.'../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001531
1532 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001533 " strip off a directory name from dirname
1534 let dirname= substitute(dirname,'^\(.*/\)[^/]\+/','\1','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001535 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001536" call Decho("go up one dir: dirname<".dirname."> trailer<".trailer.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001537
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001538 else
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001539 " go down one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001540 let dirname= dirname.newdir
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001541" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001542 endif
1543
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001544" call Dret("NetBrowseChgDir <".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001545 return dirname
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001546endfun
1547
Bram Moolenaar843ee412004-06-30 16:16:41 +00001548" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001549" NetGetWord: it gets the directory named under the cursor {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001550fun! s:NetGetWord()
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001551" call Dfunc("NetGetWord() line#".line(".")." longlist=".g:netrw_longlist." virtcol=".virtcol("."))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001552 call s:UseBufWinVars()
1553
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001554 " insure that w:netrw_longlist is set up
1555 if !exists("w:netrw_longlist")
1556 if exists("g:netrw_longlist")
1557 let w:netrw_longlist= g:netrw_longlist
1558 else
1559 let w:netrw_longlist= 0
1560 endif
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001561" call Decho("w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001562 endif
1563
Bram Moolenaar488c6512005-08-11 20:09:58 +00001564 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001565 " Active Banner support
1566" call Decho("active banner handling")
1567 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001568 let dirname= "./"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001569 let curline= getline(".")
1570 if curline =~ '"\s*Sorted by\s'
1571 norm s
1572 let s:netrw_skipbrowse= 1
1573 echo 'Pressing "s" also works'
1574 elseif curline =~ '"\s*Sort sequence:'
1575 let s:netrw_skipbrowse= 1
1576 echo 'Press "S" to edit sorting sequence'
1577 elseif curline =~ '"\s*Quick Help:'
1578 norm ?
1579 let s:netrw_skipbrowse= 1
1580 echo 'Pressing "?" also works'
1581 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
1582 norm a
1583 let s:netrw_skipbrowse= 1
1584 echo 'Pressing "a" also works'
1585 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001586 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00001587 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001588
1589 elseif w:netrw_longlist == 0
1590" call Decho("thin column handling")
1591 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001592 let dirname= getline(".")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001593
1594 elseif w:netrw_longlist == 1
1595" call Decho("long column handling")
1596 norm! 0
1597 let dirname= substitute(getline("."),'^\(\%(\S\+\s\)*\S\+\).\{-}$','\1','e')
1598
1599 else
1600" call Decho("obtain word from wide listing")
1601 let dirname= getline(".")
1602
1603 if !exists("b:netrw_cpf")
1604 let b:netrw_cpf= 0
1605 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
1606" call Decho("computed cpf")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001607 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001608
1609 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001610" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001611" call Decho("1: dirname<".dirname.">")
1612 if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif
1613" call Decho("2: dirname<".dirname.">")
1614 let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e')
1615" call Decho("3: dirname<".dirname.">")
1616 let dirname = substitute(dirname,'\s\+$','','e')
1617" call Decho("4: dirname<".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001618 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001619
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001620" call Dret("NetGetWord <".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001621 return dirname
1622endfun
1623
1624" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001625" NetBrowseRm: remove/delete a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001626fun! s:NetBrowseRm(usrhost,path) range
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001627" call Dfunc("NetBrowseRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001628" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001629
1630 " preparation for removing multiple files/directories
1631 let ctr= a:firstline
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001632 let all= 0
Bram Moolenaar843ee412004-06-30 16:16:41 +00001633
1634 " remove multiple files and directories
1635 while ctr <= a:lastline
1636 exe ctr
1637
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001638 let rmfile= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001639" call Decho("rmfile<".rmfile.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001640
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001641 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar843ee412004-06-30 16:16:41 +00001642 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001643 if !all
1644 echohl Statement
1645 call inputsave()
1646 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1647 call inputrestore()
1648 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001649 if ok == ""
1650 let ok="no"
1651 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001652 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1653 if ok =~ 'a\%[ll]'
1654 let all= 1
1655 endif
1656 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001657
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001658 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001659 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001660 silent! keepjumps .,$d
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001661 call s:NetBrowseFtpCmd(a:path,"delete ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001662 else
1663 let netrw_rm_cmd= substitute(g:netrw_rm_cmd,'HOSTNAME',a:usrhost,'').' "'.escape(a:path.rmfile,s:netrw_cd_escape).'"'
1664" call Decho("attempt to remove file: system(".netrw_rm_cmd.")")
1665 let ret= system(netrw_rm_cmd)
1666" call Decho("returned=".ret." errcode=".v:shell_error)
1667 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001668 elseif ok =~ 'q\%[uit]'
1669 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001670 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001671
Bram Moolenaar843ee412004-06-30 16:16:41 +00001672 else
1673 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001674 if !all
1675 call inputsave()
1676 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1677 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001678 if ok == ""
1679 let ok="no"
1680 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001681 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1682 if ok =~ 'a\%[ll]'
1683 let all= 1
1684 endif
1685 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001686
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001687 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001688 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001689 call s:NetBrowseFtpCmd(a:path,"rmdir ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001690 else
1691 let rmfile = a:path.rmfile
1692 let netrw_rmdir_cmd= substitute(g:netrw_rmdir_cmd,'HOSTNAME',a:usrhost,'').' '."'".'"'.rmfile.'"'."'"
1693" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
1694 let ret= system(netrw_rmdir_cmd)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001695" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001696
1697 if v:shell_error != 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001698 let netrw_rmf_cmd= substitute(g:netrw_rmf_cmd,'HOSTNAME',a:usrhost,'').' '.substitute(rmfile,'[\/]$','','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001699" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
1700 let ret= system(netrw_rmf_cmd)
1701" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001702
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001703 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001704 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001705 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001706 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001707 endif
1708 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001709
1710 elseif ok =~ 'q\%[uit]'
1711 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001712 endif
1713 endif
1714
1715 let ctr= ctr + 1
1716 endwhile
1717
1718 " refresh the directory
1719 let curline= line(".")-1
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001720" call Decho("refresh the directory")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001721 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar843ee412004-06-30 16:16:41 +00001722 exe curline
1723
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001724" call Dret("NetBrowseRm")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001725endfun
1726
1727" ---------------------------------------------------------------------
1728" NetBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001729fun! s:NetBrowseRename(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001730" call Dfunc("NetBrowseRename(usrhost<".a:usrhost."> path<".a:path.">)")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001731
1732 " preparation for removing multiple files/directories
1733 let ctr = a:firstline
1734 let rename_cmd = substitute(g:netrw_rename_cmd,'\<HOSTNAME\>',a:usrhost,'')
1735
1736 " attempt to rename files/directories
1737 while ctr <= a:lastline
Bram Moolenaar8299df92004-07-10 09:47:34 +00001738 exe "keepjumps ".ctr
Bram Moolenaar843ee412004-06-30 16:16:41 +00001739
1740 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001741 let oldname= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001742" call Decho("oldname<".oldname.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001743
1744 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001745 let newname= input("Moving ".oldname." to : ",oldname)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001746 call inputrestore()
1747
Bram Moolenaar488c6512005-08-11 20:09:58 +00001748 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001749 call s:NetBrowseFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001750 else
1751 let oldname= a:path.oldname
1752 let newname= a:path.newname
1753" call Decho("system(rename_cmd".' "'.escape(oldname," ").'" "'.escape(newname,s:netrw_cd_escape).'"')
1754 let ret= system(rename_cmd.' "'.escape(oldname,s:netrw_cd_escape).'" "'.escape(newname,s:netrw_cd_escape).'"')
1755 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001756
1757 let ctr= ctr + 1
1758 endwhile
1759
1760 " refresh the directory
1761 let curline= line(".")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001762 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001763 exe "keepjumps ".curline
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001764" call Dret("NetBrowseRename")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001765endfun
1766
1767" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00001768" NetRefresh: {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001769fun! s:NetRefresh(dirname,islocal)
1770" call Dfunc("NetRefresh(dirname<".a:dirname.">,islocal=".a:islocal.")")
1771 call netrw#NetSavePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001772 set ma
1773 %d
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001774 if a:islocal
1775 call s:LocalBrowse(a:dirname)
1776 else
1777 call s:NetBrowse(a:dirname)
1778 endif
1779 call netrw#NetRestorePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001780 redraw!
1781" call Dret("NetRefresh")
1782endfun
1783
1784" ---------------------------------------------------------------------
Bram Moolenaar488c6512005-08-11 20:09:58 +00001785" NetSplit: mode {{{2
1786" =0 : net and o
1787" =1 : net and v
1788" =2 : local and o
1789" =3 : local and v
1790fun! s:NetSplit(mode)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001791" call Dfunc("NetSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001792
1793 call s:SaveWinVars()
1794 if a:mode == 0
1795 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1796 call s:CopyWinVars()
1797 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001798 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001799 elseif a:mode ==1
1800 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1801 call s:CopyWinVars()
1802 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001803 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001804 elseif a:mode ==2
1805 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
1806 call s:CopyWinVars()
1807 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001808 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001809 else
1810 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1811 call s:CopyWinVars()
1812 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001813 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001814 endif
1815
1816" call Dret("NetSplit")
1817endfun
1818
1819" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001820" NetBrowseX: allows users to write custom functions to operate on {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00001821" files given their extension. Passes 0=local, 1=remote
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001822fun! netrw#NetBrowseX(fname,remote)
1823" call Dfunc("NetBrowseX(fname<".a:fname."> remote=".a:remote.")")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001824
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001825 " set up the filename
1826 " (lower case the extension, make a local copy of a remote file)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001827 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001828 if has("win32") || has("win95") || has("win64") || has("win16")
1829 let exten= substitute(exten,'^.*$','\L&\E','')
1830 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001831 let fname= escape(a:fname,"%#")
1832" call Decho("fname<".fname."> after escape()")
1833
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001834 " seems kde systems often have gnome-open due to dependencies, even though
1835 " gnome-open's subsidiary display tools are largely absent. Kde systems
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001836 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
1837 if !exists("s:haskdeinit")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001838 if has("unix")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001839 silent! let s:haskdeinit= system('ps -e') =~ 'kdeinit'
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001840 if v:shell_error
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001841 let s:haskdeinit = 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001842 endif
1843 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001844 let s:haskdeinit= 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001845 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001846" call Decho("setting s:haskdeinit=".s:haskdeinit)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001847 endif
1848
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001849 if a:remote == 1
1850 " create a local copy
1851 let fname= tempname().".".exten
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001852" call Decho("a:remote==1: create a local copy of <".a:fname."> as <".fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001853 exe "silent keepjumps bot 1new ".a:fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001854 set bh=delete
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001855 exe "w! ".fname
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001856 q
1857 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001858" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001859
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001860 " set up redirection
1861 if &srr =~ "%s"
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00001862 let redir= substitute(&srr,"%s","/dev/null","")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001863 else
1864 let redir= &srr . "/dev/null"
1865 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001866" call Decho("redir{".redir."} srr{".&srr."}")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001867
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001868 if exists("g:netrw_browsex_viewer") && executable(g:netrw_browsex_viewer)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001869" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001870 if g:netrw_browsex_viewer == '-'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001871 let ret= netrwFileHandlers#Invoke(exten,fname)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001872 else
1873" call Decho("exe silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."' ".redir)
1874 exe "silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."'".redir
1875 let ret= v:shell_error
1876 endif
1877
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001878 " execute the file handler
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001879 elseif has("win32") || has("win64")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001880" call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"')
1881 exe 'silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"'
1882 let ret= v:shell_error
1883
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001884 elseif has("unix") && executable("gnome-open") && !s:haskdeinit
Bram Moolenaara5792f52005-11-23 21:25:05 +00001885" call Decho("exe silent !gnome-open '".escape(fname,'%#')."' ".redir)
1886 exe "silent !gnome-open '".escape(fname,'%#')."'".redir
1887 let ret= v:shell_error
1888
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001889 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001890" call Decho("exe silent !kfmclient exec '".escape(fname,'%#')."' ".redir)
1891 exe "silent !kfmclient exec '".escape(fname,'%#')."' ".redir
1892 let ret= v:shell_error
1893
1894 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001895 " netrwFileHandlers#Invoke() always returns 0
1896 let ret= netrwFileHandlers#Invoke(exten,fname)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001897 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001898
1899 " if unsuccessful, attempt netrwFileHandlers#Invoke()
1900 if ret
1901 let ret= netrwFileHandlers#Invoke(exten,fname)
1902 endif
1903
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001904 redraw!
Bram Moolenaar8299df92004-07-10 09:47:34 +00001905
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001906 " cleanup: remove temporary file,
1907 " delete current buffer if success with handler,
1908 " return to prior buffer (directory listing)
1909 if a:remote == 1 && fname != a:fname
1910" call Decho("deleting temporary file<".fname.">")
1911 call delete(fname)
1912 endif
1913
1914 if a:remote == 1
Bram Moolenaar572cb562005-08-05 21:35:02 +00001915 set bh=delete bt=nofile noswf
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001916 exe "norm! \<c-o>"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001917 redraw!
Bram Moolenaar843ee412004-06-30 16:16:41 +00001918 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001919
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001920" call Dret("NetBrowseX")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001921endfun
1922
1923" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001924" NetBrowseFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
1925" This function assumes that a long listing will be received. Size, time,
1926" and reverse sorts will be requested of the server but not otherwise
1927" enforced here.
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001928fun! s:NetBrowseFtpCmd(path,listcmd)
1929" call Dfunc("NetBrowseFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001930
1931 " because WinXX ftp uses unix style input
1932 " curline is one more than the bannercnt in order to account
1933 " for the unwanted first blank line (doing a :put to an empty
1934 " buffer yields a blank first line)
1935 let ffkeep= &ff
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001936 setlocal ma ff=unix
Bram Moolenaar488c6512005-08-11 20:09:58 +00001937 let curline= w:netrw_bannercnt+1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001938 exe "silent! keepjumps ".curline.",$d"
1939
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001940 ".........................................
1941 if w:netrw_method == 2 || w:netrw_method == 5
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001942 " ftp + <.netrc>: Method #2
1943 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001944 put ='cd \"'.a:path.'\"'
1945" call Decho('ftp: '.getline("."))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001946 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001947 exe "put ='".a:listcmd."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001948" call Decho("ftp: ".getline("."))
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001949" redraw!|call inputsave()|call input("Pausing...")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001950 if exists("g:netrw_port") && g:netrw_port != ""
1951" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
1952 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
1953 else
1954" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
1955 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
1956 endif
1957
1958 ".........................................
Bram Moolenaar488c6512005-08-11 20:09:58 +00001959 elseif w:netrw_method == 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001960 " ftp + machine,id,passwd,filename: Method #3
1961 setlocal ff=unix
1962 if exists("g:netrw_port") && g:netrw_port != ""
1963 put ='open '.g:netrw_machine.' '.g:netrw_port
1964 else
1965 put ='open '.g:netrw_machine
1966 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001967
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001968 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1969 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001970 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001971 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001972 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001973 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001974
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001975 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001976 put ='cd \"'.a:path.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001977 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001978 exe "put ='".a:listcmd."'"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001979
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001980 " perform ftp:
1981 " -i : turns off interactive prompting from ftp
1982 " -n unix : DON'T use <.netrc>, even though it exists
1983 " -n win32: quit being obnoxious about password
1984" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
1985 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n"
1986
1987 ".........................................
1988 else
1989 echo "***warning*** unable to comply with your request<" . choice . ">"
1990 endif
1991
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001992 " cleanup for Windows
1993 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001994 silent! keepjumps! %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001995 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001996 if a:listcmd == "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001997 " infer directory/link based on the file permission string
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001998 silent! keepjumps g/d\%([-r][-w][-x]\)\{3}/s@$@/@
1999 silent! keepjumps g/l\%([-r][-w][-x]\)\{3}/s/$/@/
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002000 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002001 exe "silent! keepjumps ".curline.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002002 endif
2003 endif
2004
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002005 " ftp's ls doesn't seem to include ./ or ../
2006 if !search('^\.\/$','wn')
2007 exe 'keepjumps '.curline
2008 if a:path !~ '^$'
2009 put ='../'
2010 endif
2011 put ='./'
2012 exe 'keepjumps '.curline
2013 endif
2014
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002015 " restore settings
2016 let &ff= ffkeep
2017" call Dret("NetBrowseFtpCmd")
2018endfun
2019
2020" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00002021" NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
2022" separated patterns given in g:netrw_list_hide
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002023fun! s:NetrwListHide()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002024" call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00002025
2026 let listhide= g:netrw_list_hide
2027 while listhide != ""
2028 if listhide =~ ','
2029 let hide = substitute(listhide,',.*$','','e')
2030 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
2031 else
2032 let hide = listhide
2033 let listhide= ""
2034 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002035
2036 " Prune the list by hiding any files which match
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002037 if g:netrw_hide == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002038" call Decho("hiding<".hide."> listhide<".listhide.">")
2039" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d')
2040 exe 'silent keepjumps '.w:netrw_bannercnt.',$g~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002041 elseif g:netrw_hide == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002042" call Decho("showing<".hide."> listhide<".listhide.">")
2043" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d')
2044 exe 'silent keepjumps '.w:netrw_bannercnt.',$v~'.hide.'~d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002045 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00002046 endwhile
2047
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002048" call Dret("NetrwListHide")
2049endfun
2050
2051" ---------------------------------------------------------------------
2052" NetHideEdit: allows user to edit the file/directory hiding list
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002053fun! s:NetHideEdit(islocal)
2054" call Dfunc("NetHideEdit(islocal=".a:islocal.")")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002055
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002056 " get new hiding list from user
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002057 call inputsave()
2058 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
2059 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002060 let g:netrw_list_hide= newhide
2061" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002062
2063 " refresh the listing
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002064 if a:islocal == 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00002065 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2066 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002067 silent call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,"./"),a:islocal)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002068 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002069
2070" call Dret("NetHideEdit")
Bram Moolenaar843ee412004-06-30 16:16:41 +00002071endfun
2072
Bram Moolenaar8299df92004-07-10 09:47:34 +00002073" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002074" NetSortSequence: allows user to edit the sorting sequence
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002075fun! s:NetSortSequence(mode)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002076" call Dfunc("NetSortSequence(mode=".a:mode.")")
2077
2078 call inputsave()
2079 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
2080 call inputrestore()
2081
2082 " refresh the listing
2083 let g:netrw_sort_sequence= newsortseq
2084 if a:mode == 0
2085 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2086 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002087 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002088 endif
2089
2090" call Dret("NetSortSequence")
2091endfun
2092
2093" ---------------------------------------------------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002094" NetLongList: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002095fun! s:NetLongList(mode)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002096" call Dfunc("NetLongList(mode=".a:mode.") netrw_longlist=".w:netrw_longlist)
2097 let fname = s:NetGetWord()
2098 let w:netrw_longlist = (w:netrw_longlist + 1) % 3
2099" call Decho("fname<".fname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002100
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002101 if w:netrw_longlist == 0
2102 " use one column listing
2103" call Decho("use one column list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002104 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2105
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002106 elseif w:netrw_longlist == 1
2107 " use long list
2108" call Decho("use long list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002109 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002110
2111 else
2112 " give wide list
2113" call Decho("use wide list")
2114 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002115 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002116 setlocal ma
Bram Moolenaar572cb562005-08-05 21:35:02 +00002117
2118 " clear buffer - this will cause NetBrowse/LocalBrowse to do a refresh
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002119 %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002120
2121 " refresh the listing
2122 if a:mode == 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002123 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002124 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002125 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002126 endif
2127
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002128 " keep cursor on the filename
2129 silent keepjumps $
2130 if fname =~ '/$'
2131 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2132 else
2133 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2134 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002135
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002136" call Dret("NetLongList : w:netrw_longlist=".w:netrw_longlist)
2137endfun
2138
2139" ---------------------------------------------------------------------
2140" NetrwWideListing: {{{2
2141fun! s:NetrwWideListing()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002142
2143 if w:netrw_longlist == 2
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002144" call Dfunc("NetrwWideListing() w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002145 " look for longest filename (cpf=characters per filename)
2146 " cpf: characters per file
2147 " fpl: files per line
2148 " fpc: files per column
2149 set ma
2150 let b:netrw_cpf= 0
2151 if line("$") >= w:netrw_bannercnt
2152 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar57657d82006-04-21 22:12:41 +00002153 else
2154" call Dret("NetrwWideListing")
2155 return
2156 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002157" call Decho("max file strlen+1=".b:netrw_cpf)
2158 let b:netrw_cpf= b:netrw_cpf + 1
2159
2160 " determine qty files per line (fpl)
2161 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002162 if w:netrw_fpl <= 0
2163 let w:netrw_fpl= 1
2164 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002165" call Decho("fpl= ".winwidth(0)."/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
2166
2167 " make wide display
Bram Moolenaar57657d82006-04-21 22:12:41 +00002168 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^.*$/\=printf("%-'.b:netrw_cpf.'s",escape(submatch(0),"\\"))/'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002169 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
2170 let newcolstart = w:netrw_bannercnt + fpc
2171 let newcolend = newcolstart + fpc - 1
2172" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
2173 while line("$") >= newcolstart
2174 if newcolend > line("$") | let newcolend= line("$") | endif
2175 let newcolqty= newcolend - newcolstart
2176 exe newcolstart
2177 if newcolqty == 0
2178 exe "silent keepjumps norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
2179 else
2180 exe "silent keepjumps norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
2181 endif
2182 exe "silent keepjumps ".newcolstart.','.newcolend.'d'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002183 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002184 endwhile
2185 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002186 setlocal noma nomod
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002187" call Dret("NetrwWideListing")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002188 endif
2189
Bram Moolenaar8299df92004-07-10 09:47:34 +00002190endfun
2191
2192" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002193" NetSaveWordPosn: used by the "s" command in both remote and local {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002194" browsing. Along with NetRestoreWordPosn(), it keeps the cursor on
2195" the same word even though the sorting has changed its order of appearance.
2196fun! s:NetSaveWordPosn()
2197" call Dfunc("NetSaveWordPosn()")
2198 let s:netrw_saveword= '^'.escape(getline("."),s:netrw_cd_escape).'$'
2199" call Dret("NetSaveWordPosn : saveword<".s:netrw_saveword.">")
2200endfun
2201
2202" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002203" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002204fun! s:NetRestoreWordPosn()
2205" call Dfunc("NetRestoreWordPosn()")
2206 silent! call search(s:netrw_saveword,'w')
2207" call Dret("NetRestoreWordPosn")
2208endfun
2209
2210" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002211" NetMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002212fun! s:NetMakeDir(usrhost)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002213" call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)")
2214
2215 " get name of new directory from user. A bare <CR> will skip.
2216 " if its currently a directory, also request will be skipped, but with
2217 " a message.
2218 call inputsave()
2219 let newdirname= input("Please give directory name: ")
2220 call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002221" call Decho("newdirname<".newdirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002222
2223 if newdirname == ""
2224" call Dret("NetMakeDir : user aborted with bare <cr>")
2225 return
2226 endif
2227
2228 if a:usrhost == ""
2229
2230 " Local mkdir:
2231 " sanity checks
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002232 let fullnewdir= b:netrw_curdir.'/'.newdirname
2233" call Decho("fullnewdir<".fullnewdir.">")
2234 if isdirectory(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002235 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002236 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a directory!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002237 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002238 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002239" call Dret("NetMakeDir : directory<".newdirname."> exists previously")
2240 return
2241 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002242 if filereadable(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002243 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002244 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a file!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002245 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002246 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002247" call Dret("NetMakeDir : file<".newdirname."> exists previously")
2248 return
2249 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002250
2251 " requested new local directory is neither a pre-existing file or
2252 " directory, so make it!
2253 if exists("*mkdir")
2254 call mkdir(fullnewdir,"p")
2255 else
2256 let netrw_origdir= s:NetGetcwd(1)
Bram Moolenaar57657d82006-04-21 22:12:41 +00002257 exe 'keepjumps cd '.b:netrw_curdir
2258" call Decho("netrw_origdir<".netrw_origdir.">: cd b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002259" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.newdirname.'"')
2260 exe "silent! !".g:netrw_local_mkdir.' "'.newdirname.'"'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002261 if !g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002262 if !g:netrw_keepdir
2263 exe 'keepjumps cd '.netrw_origdir
2264" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".netrw_origdir)
2265 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002266 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002267
Bram Moolenaar8299df92004-07-10 09:47:34 +00002268 if v:shell_error == 0
2269 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002270" call Decho("refresh listing")
2271 let linenum= line(".")
2272 norm! H0
2273 let hline = line(".")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002274 set ma|norm! 2D
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002275 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,'./'))
2276 exe "norm! ".hline."G0z\<CR>"
2277 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002279 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002280 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002281 endif
2282 redraw!
2283
2284 else
2285 " Remote mkdir:
2286 let mkdircmd = substitute(g:netrw_mkdir_cmd,'\<HOSTNAME\>',a:usrhost,'')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002287 let newdirname= "'".'"'.substitute(expand("%"),'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname.'"'."'"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002288" call Decho("exe silent! !".mkdircmd." ".newdirname)
2289 exe "silent! !".mkdircmd." ".newdirname
2290 if v:shell_error == 0
2291 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002292 let linenum= line(".")
2293 norm! H0
2294 let hline = line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002295 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002296 exe "norm! ".hline."G0z\<CR>"
2297 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002298 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002299 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002300 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002301 endif
2302 redraw!
2303 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaar8299df92004-07-10 09:47:34 +00002305" call Dret("NetMakeDir")
2306endfun
2307
2308" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002309" NetBookmarkDir: {{{2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002310" 0: (user: <b>) bookmark current directory
2311" 1: (user: <B>) change to the bookmarked directory
2312" 2: (user: <q>) list bookmarks
2313" 3: (LocalBrowse) record current directory history
2314" 4: (user: <u>) go up (previous) bookmark
2315" 5: (user: <U>) go down (next) bookmark
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002316fun! s:NetBookmarkDir(chg,curdir)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002317" call Dfunc("NetBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002318 if exists("w:netrw_bannercnt") && line(".") <= w:netrw_bannercnt
2319 " looks like a "b" was pressed while in the banner region
2320 if line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002321 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00002322 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002323 if &ch > 1
2324 " "clear" the message
2325 echo ""
2326 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002327" call Dret("NetBookmarkDir - ignoring")
2328 return
2329 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002330
2331 if a:chg == 0
2332 " bookmark the current directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002333 let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir
2334 if !exists("g:NETRW_BOOKMARKMAX")
2335 let g:NETRW_BOOKMARKMAX= v:count
2336 elseif v:count > g:NETRW_BOOKMARKMAX
2337 let g:NETRW_BOOKMARKMAX= v:count
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002338 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002339 echo "bookmarked the current directory"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002340
2341 elseif a:chg == 1
2342 " change to the bookmarked directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002343 if exists("g:NETRW_BOOKMARKDIR_{v:count}")
2344 exe "e ".g:NETRW_BOOKMARKDIR_{v:count}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002345 else
2346 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2347 endif
2348
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002349 elseif a:chg == 2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002350 " list user's bookmarks
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002351 if exists("g:NETRW_BOOKMARKMAX")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002352" call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]")
2353 let cnt= 0
2354 while cnt <= g:NETRW_BOOKMARKMAX
2355 if exists("g:NETRW_BOOKMARKDIR_{cnt}")
2356" call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt})
2357 echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}
2358 endif
2359 let cnt= cnt + 1
2360 endwhile
2361 endif
2362
2363 " list directory history
2364 let cnt = g:NETRW_DIRHIST_CNT
2365 let first = 1
2366 let histcnt = 0
2367 while ( first || cnt != g:NETRW_DIRHIST_CNT )
2368" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT)
2369 let histcnt= histcnt + 1
2370 if exists("g:NETRW_DIRHIST_{cnt}")
2371" call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt})
2372 echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002373 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002374 let first = 0
2375 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2376 if cnt < 0
2377 let cnt= cnt + g:netrw_dirhistmax
2378 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002379 endwhile
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002380
2381 elseif a:chg == 3
Bram Moolenaar572cb562005-08-05 21:35:02 +00002382 " saves most recently visited directories (when they differ)
2383 if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir
2384 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2385 let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e')
2386" call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2387 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002388
2389 elseif a:chg == 4
2390 " u: change to the previous directory stored on the history list
2391 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2392 if g:NETRW_DIRHIST_CNT < 0
2393 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2394 endif
2395 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2396" call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2397 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2398 else
2399 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2400 echo "Sorry, no predecessor directory exists yet"
2401 endif
2402
2403 elseif a:chg == 5
2404 " U: change to the subsequent directory stored on the history list
2405 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2406 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2407" call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2408 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2409 else
2410 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2411 if g:NETRW_DIRHIST_CNT < 0
2412 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2413 endif
2414 echo "Sorry, no successor directory exists yet"
2415 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002416 endif
2417" call Dret("NetBookmarkDir")
2418endfun
2419
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002420" ---------------------------------------------------------------------
2421" NetObtain: obtain file under cursor (for remote browsing support) {{{2
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002422fun! netrw#NetObtain(...)
2423" call Dfunc("NetObtain() a:0=".a:0)
2424
2425 if a:0==0
2426 " no arguments -- use word under cursor
2427 let fname= expand("<cWORD>")
2428" call Decho("no arguments, use <".fname.">")
2429 elseif a:0 > 1
2430 " more than one argument, recurse with each argument separately
2431" call Decho("more than 1 argument, use recursion")
2432 let i=1
2433 while i <= a:0
2434 call netrw#NetObtain(a:{i})
2435 let i=i+1
2436 endwhile
2437 return
2438 else
2439 " one argument provided
2440 let fname = a:1
2441 let keep_netrw_choice = exists("b:netrw_choice")? b:netrw_choice : ""
2442 let keep_netrw_fname = exists("b:netrw_fname")? b:netrw_fname : ""
2443 let keep_netrw_wmethod = exists("w:netrw_method")? w:netrw_method : ""
2444 call s:NetMethod(fname)
2445 let w:netrw_method= b:netrw_method
2446 let fname = b:netrw_fname
2447" call Decho("g:netrw_scp_cmd<".g:netrw_scp_cmd.">")
2448" call Decho("g:netrw_machine<".g:netrw_machine.">")
2449" call Decho("fname<".fname.">")
2450 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002451
2452 " NetrwStatusLine support - for obtaining support
2453 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.fname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002454
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002455" call Decho("method=".w:netrw_method)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002456 if exists("w:netrw_method") && w:netrw_method =~ '[235]'
2457 if executable("ftp")
2458 let curdir = expand("%")
2459 let path = substitute(curdir,'ftp://[^/]\+/','','e')
2460 let curline= line(".")
2461 let endline= line("$")+1
2462 set ma
2463 keepjumps $
2464
2465 ".........................................
2466 if w:netrw_method == 2
2467 " ftp + <.netrc>: Method #2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002468 setlocal ff=unix
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002469 if path != ""
2470 put ='cd '.path
2471" call Decho("ftp: cd ".path)
2472 endif
2473 put ='get '.fname
2474" call Decho("ftp: get ".fname)
2475 if exists("g:netrw_port") && g:netrw_port != ""
2476" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
2477 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
2478 else
2479" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
2480 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
2481 endif
2482
2483 ".........................................
2484 elseif w:netrw_method == 3
2485 " ftp + machine,id,passwd,filename: Method #3
2486 setlocal ff=unix
2487 if exists("g:netrw_port") && g:netrw_port != ""
2488 put ='open '.g:netrw_machine.' '.g:netrw_port
2489" call Decho('ftp: open '.g:netrw_machine.' '.g:netrw_port)
2490 else
2491 put ='open '.g:netrw_machine
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002492" call Decho('ftp: open '.g:netrw_machine)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002493 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002494
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002495 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2496 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002497 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002498" call Decho('ftp: g:netrw_uid')
2499" call Decho('ftp: g:netrw_passwd')
2500 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002501 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002502" call Decho('user '.g:netrw_uid.' '.g:netrw_passwd)
2503 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002505 if a:path != ""
2506 put ='cd '.a:path
2507" call Decho('cd '.a:path)
2508 endif
2509 exe "put ='".a:cmd."'"
2510" call Decho("ftp: ".a:cmd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002511
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002512 " perform ftp:
2513 " -i : turns off interactive prompting from ftp
2514 " -n unix : DON'T use <.netrc>, even though it exists
2515 " -n win32: quit being obnoxious about password
2516" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
2517 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i -n"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002518
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002519 ".........................................
2520 else
2521 echo "***warning*** unable to comply with your request<" . choice . ">"
2522 endif
2523 " restore
2524 exe "silent! ".endline.",$d"
2525 exe "keepjumps ".curline
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002526 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002527 else
2528 if !exists("g:netrw_quiet")
2529 echohl Error | echo "***netrw*** this system doesn't support ftp" | echohl None
2530 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2531 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002533 let &stl = s:netrw_users_stl
2534 let &laststatus = s:netrw_users_ls
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535 " restore NetMethod
2536 if exists("keep_netrw_method")
2537 call s:NetMethod(keep_netrw_choice)
2538 let w:netrw_method = keep_netrw_wmethod
2539 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002540" call Dret("NetObtain")
2541 return
2542 endif
2543
2544 ".........................................
2545 else
2546 " scp: Method#4
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002547 let curdir = expand("%")
2548 let path = substitute(curdir,'scp://[^/]\+/','','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002549" call Decho("path<".path.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002550 if exists("g:netrw_port") && g:netrw_port != ""
2551 let useport= " -P ".g:netrw_port
2552 else
2553 let useport= ""
2554 endif
2555 if g:netrw_cygwin == 1
2556 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002557" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2558 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002559 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002560" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2561 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002562 endif
2563 endif
2564
2565 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002566 let &stl = s:netrw_users_stl
2567 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002568 redraw!
2569
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570 " restore NetMethod
2571 if exists("keep_netrw_method")
2572 call s:NetMethod(keep_netrw_choice)
2573 let w:netrw_method = keep_netrw_wmethod
2574 endif
2575
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002576" call Dret("NetObtain")
2577endfun
2578
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002579" ---------------------------------------------------------------------
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002580" NetPrevWinOpen: open file/directory in previous window. {{{2
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002581" If there's only one window, then the window will first be split.
2582fun! s:NetPrevWinOpen(islocal)
2583" call Dfunc("NetPrevWinOpen(islocal=".a:islocal.")")
2584
2585 " get last window number and the word currently under the cursor
2586 let lastwinnr = winnr("$")
2587 let curword = s:NetGetWord()
2588 let curdir = b:netrw_curdir
2589" call Decho("lastwinnr=".lastwinnr." curword<".curword.">")
2590
2591 let didsplit = 0
2592 if lastwinnr == 1
2593 " if only one window, open a new one first
2594" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
2595 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
2596 let didsplit = 1
2597
2598 else
2599 wincmd p
2600 " if the previous window's buffer has been changed (is modified),
2601 " and it doesn't appear in any other extant window, then ask the
2602 " user if s/he wants to abandon modifications therein.
2603 let bnr = winbufnr(0)
2604 let bnrcnt = 0
2605 if &mod
2606 windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif
2607" call Decho("bnr=".bnr." bnrcnt=".bnrcnt)
2608 if bnrcnt == 1
2609 let bufname= bufname(winbufnr(winnr()))
2610 let choice= confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel")
2611
2612 if choice == 1
2613 " Yes -- write file & then browse
2614 let v:errmsg= ""
2615 silent w
2616 if v:errmsg != ""
2617 echohl Error | echo "***netrw*** "unable to write <".bufname.">!" | echohl None
2618 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2619 if didsplit
2620 q
2621 else
2622 wincmd p
2623 endif
2624" call Dret("NetPrevWinOpen : unable to write <".bufname.">")
2625 return
2626 endif
2627
2628 elseif choice == 2
2629 " No -- don't worry about changed file, just browse anyway
2630 set nomod
2631 echohl WarningMsg | echo "***netrw*** ".bufname." changes abandoned" | echohl None
2632
2633 else
2634 " Cancel -- don't do this
2635 if didsplit
2636 q
2637 else
2638 wincmd p
2639 endif
2640" call Dret("NetPrevWinOpen : cancelled")
2641 return
2642 endif
2643 endif
2644 endif
2645 endif
2646
2647 if a:islocal
2648 call s:LocalBrowse(s:LocalBrowseChgDir(curdir,curword))
2649 else
2650 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),curword))
2651 endif
2652" call Dret("NetPrevWinOpen")
2653endfun
2654
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002655" ---------------------------------------------------------------------
2656" NetMenu: generates the menu for gvim and netrw {{{2
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002657fun! s:NetMenu(domenu)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002658
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002659 if !exists("g:NetrwMenuPriority")
2660 let g:NetrwMenuPriority= 80
2661 endif
2662
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002663 if has("menu") && has("gui_running") && &go =~ 'm'
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002664" call Dfunc("NetMenu(domenu=".a:domenu.")")
2665 if !exists("s:netrw_menu_enabled") && a:domenu
2666" call Decho("initialize menu")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002667 let s:netrw_menu_enabled= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002668 if !exists("g:NetrwTopLvlMenu")
2669 let g:NetrwTopLvlMenu= "Netrw."
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002670 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002671 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
2672 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
2673 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory<tab>b Nb'
2674 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
2675 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory<tab>B NB'
2676 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory<tab>u u'
2677 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory<tab>U U'
2678 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
2679 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List<tab>'."<ctrl-h> \<c-h>"
2680 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory<tab><cr> '."\<cr>"
2681 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window<tab>o o'
2682 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window<tab>v v'
2683 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History<tab>q q'
2684 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)<tab>i i'
2685 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
2686 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Normal-Hide-Show<tab>a a'
2687 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
2688 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Preview\ File/Directory<tab>p p'
2689 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser<tab>P P'
2690 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
2691 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
2692 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order<tab>'."r r"
2693 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style<tab>s s'
2694 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit<tab>S S'
2695 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
2696 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002697 elseif !a:domenu
2698 let s:netrwcnt = 0
2699 let curwin = winnr()
2700 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
2701 exe curwin."wincmd w"
2702
2703 if s:netrwcnt <= 1
2704" call Decho("clear menus")
2705 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Help'
2706 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer'
2707 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory'
2708 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Go\ Up\ Directory'
2709 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory'
2710 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory'
2711 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory'
2712 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Delete\ File/Directory'
2713 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory'
2714 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window'
2715 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window'
2716 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List'
2717 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File'
2718 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory'
2719 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory\ (vertical\ split)'
2720 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History'
2721 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)'
2722 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Make\ Subdirectory'
2723 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Normal-Hide-Show'
2724 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Obtain\ File'
2725 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Preview\ File/Directory'
2726 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser'
2727 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Refresh\ Listing'
2728 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Rename\ File/Directory'
2729 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order'
2730 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style'
2731 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit'
2732 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Set\ Current\ Directory'
2733 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Settings/Options'
2734 unlet s:netrw_menu_enabled
2735 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002736 endif
2737" call Dret("NetMenu")
2738 endif
2739
2740endfun
2741
Bram Moolenaar83bab712005-08-01 21:58:57 +00002742" ==========================================
2743" Local Directory Browsing Support: {{{1
2744" ==========================================
Bram Moolenaar8299df92004-07-10 09:47:34 +00002745
2746" ---------------------------------------------------------------------
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002747" LocalBrowse: {{{2
2748fun! s:LocalBrowse(dirname)
2749 " unfortunate interaction -- debugging calls can't be used here;
2750 " the BufEnter event causes triggering when attempts to write to
2751 " the DBG buffer are made.
2752 if isdirectory(a:dirname)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002753 silent! call netrw#DirBrowse(a:dirname)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002754 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002755 " not a directory, ignore it
2756endfun
Bram Moolenaar8299df92004-07-10 09:47:34 +00002757
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002758" ---------------------------------------------------------------------
2759" DirBrowse: supports local file/directory browsing {{{2
2760fun! netrw#DirBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002761 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002762" call Dfunc("DirBrowse(dirname<".a:dirname.">) buf#".bufnr("%")." winnr=".winnr()." sortby=".g:netrw_sort_by)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002763" call Dredir("ls!")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002764
Bram Moolenaar488c6512005-08-11 20:09:58 +00002765 if exists("s:netrw_skipbrowse")
2766 unlet s:netrw_skipbrowse
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002767" call Dret("DirBrowse")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002768 return
2769 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002770 if &fo =~ '[ta]'
2771 set fo-=t
2772 set fo-=a
2773 echohl Warning
2774 echo '***warning*** directory browsing and formatoptions "ta" are incompatible'
2775 echohl None
2776 endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002777
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002778 call s:NetOptionSave()
Bram Moolenaar57657d82006-04-21 22:12:41 +00002779 if w:acdkeep
2780 exe 'cd '.escape(a:dirname,s:netrw_cd_escape)
2781" call Decho("cd ".escape(a:dirname,s:netrw_cd_escape))
2782" call Decho("getcwd<".getcwd().">")
2783 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002784
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002785 if v:version < 603
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002786 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002787 echohl Error | echo "***netrw*** vim version<".v:version."> too old for browsing with netrw" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002788 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002789 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002790 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002791" call Dret("DirBrowse : vim version<".v:version."> too old")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002792 return
2793 endif
2794
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002795 " use buffer-oriented WinVars if buffer ones exist but window ones don't
2796 call s:UseBufWinVars()
2797
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002798 " set up menus
2799 let b:netrw_browser_active= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002800 call s:NetMenu(1)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002801
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002802 " find buffer number of buffer named precisely the same as a:dirname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002803 let bufnum= bufnr(escape(a:dirname,'\'))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002804" call Decho("findbuf: bufnum=".bufnum)
2805 if bufnum > 0 && bufname(bufnum) != a:dirname
2806 let ibuf= 1
2807 let buflast= bufnr("$")
2808 while bufname(ibuf) !~ '^'.a:dirname.'\=$' && ibuf <= buflast
2809" call Decho("findbuf: ibuf=".ibuf. " bufname<".bufname(ibuf)."> dirname<".a:dirname.">")
2810 let ibuf= ibuf + 1
2811 endwhile
2812 if ibuf > buflast
2813 let bufnum= -1
2814 else
2815 let bufnum= ibuf
2816 endif
2817" call Decho("findbuf: bufnum=".bufnum." (final)")
2818 endif
2819
2820 " get cleared buffer
Bram Moolenaar57657d82006-04-21 22:12:41 +00002821 mark '
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002822 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002823 keepjumps keepalt enew!
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002824" call Decho("enew buffer")
2825 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002826 exe "keepalt b ".bufnum
Bram Moolenaar572cb562005-08-05 21:35:02 +00002827 if exists("s:last_sort_by") && g:netrw_sort_by == s:last_sort_by
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002828 if getline(2) =~ '^" Netrw Directory Listing '
Bram Moolenaar572cb562005-08-05 21:35:02 +00002829 if !g:netrw_keepdir
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002830 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar57657d82006-04-21 22:12:41 +00002831" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar572cb562005-08-05 21:35:02 +00002832 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002833 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002834" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002835 return
2836 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002837 endif
2838 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00002839 let s:last_sort_by= g:netrw_sort_by
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002840
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00002841 " set up ShellCmdPost handling. Append current buffer to browselist
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00002842 call s:LocalFastBrowser()
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00002843
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002844 " get the new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002845 if has("win32") || has("win95") || has("win64") || has("win16")
2846 let b:netrw_curdir= substitute(a:dirname,'\\','/','ge')
2847 else
2848 let b:netrw_curdir= a:dirname
2849 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002850 if b:netrw_curdir =~ '[/\\]$'
2851 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2852 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002853 if b:netrw_curdir == ''
2854 " under unix, when the root directory is encountered, the result
2855 " from the preceding substitute is an empty string.
2856 let b:netrw_curdir= '/'
2857 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002858" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002859
Bram Moolenaar83bab712005-08-01 21:58:57 +00002860 " make netrw's idea of the current directory vim's if the user wishes
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002861 if !g:netrw_keepdir
Bram Moolenaar57657d82006-04-21 22:12:41 +00002862" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar488c6512005-08-11 20:09:58 +00002863 try
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002864 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002865 catch /^Vim\%((\a\+)\)\=:E472/
2866 echohl Error | echo "***netrw*** unable to change directory to <".b:netrw_curdir."> (permissions?)" | echohl None
2867 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2868 if exists("w:netrw_prvdir")
2869 let b:netrw_curdir= w:netrw_prvdir
2870 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002871 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002872" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002873 return
2874 endif
2875 endtry
Bram Moolenaar83bab712005-08-01 21:58:57 +00002876 endif
2877
2878 " change the name of the buffer to reflect the b:netrw_curdir
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002879 " Hmm. When another vim is open to the same directory, I get
2880 " a "Press ENTER" ... ok, setting "noswf" avoids it.
2881" call Decho('exe silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002882 exe 'silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002883
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002884 " make this buffer not-a-file, modifiable, not line-numbered, etc
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002885 setlocal bt=nofile nobl ma nonu noswf nowrap
2886 if g:netrw_fastbrowse >= 2
2887 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00002888 else
2889 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002890 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002891 keepalt silent! %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002892
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002893 " ---------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002894 " Perform Directory Listing:
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002895 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2896 echo "(netrw) Processing your browsing request..."
2897 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002898
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002899 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002900 call s:NetBookmarkDir(3,b:netrw_curdir)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002901
Bram Moolenaar8299df92004-07-10 09:47:34 +00002902 " set up all the maps
Bram Moolenaar269ec652004-07-29 08:43:53 +00002903" call Decho("Setting up local browser maps")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002904 nnoremap <buffer> <silent> <cr> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002905 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002906 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,'../'))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002907 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 +00002908 if w:netrw_longlist != 2
2909 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2910 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
2911 endif
2912 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2913 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002914 nnoremap <buffer> <silent> c :exe "cd ".b:netrw_curdir<cr>
2915 nnoremap <buffer> <silent> d :call <SID>NetMakeDir("")<cr>
2916 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(1)<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002917 nnoremap <buffer> <silent> i :call <SID>NetLongList(1)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002918 nnoremap <buffer> <silent> o :call <SID>NetSplit(2)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002919 nnoremap <buffer> <silent> O :call <SID>LocalObtain()<cr>
2920 nnoremap <buffer> <silent> p :call <SID>LocalPreview(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),1))<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002921 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002922 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002923 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 +00002924 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>
2925 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002926 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
2927 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002928 nnoremap <buffer> <silent> v :call <SID>NetSplit(3)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002929 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),0),0)"<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002930 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar57657d82006-04-21 22:12:41 +00002931 if s:didstarstar || !mapcheck("<s-down>","n")
2932 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
2933 endif
2934 if s:didstarstar || !mapcheck("<s-up>","n")
2935 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
2936 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002937 exe 'nnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002938 exe 'vnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002939 exe 'nnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002940 exe 'vnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002941 exe 'nnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002942 exe 'vnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00002943 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetMakeDir("")<cr>'
Bram Moolenaar433f7c82006-03-21 21:29:36 +00002944 nnoremap <buffer> <F1> :he netrw-dir<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002945
2946 " Set up the banner
Bram Moolenaar269ec652004-07-29 08:43:53 +00002947" call Decho("set up banner")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002948 keepjumps put ='\" ============================================================================'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002949 keepjumps 1d
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002950 keepjumps put ='\" Netrw Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002951 keepjumps put ='\" '.b:netrw_curdir
Bram Moolenaar488c6512005-08-11 20:09:58 +00002952 let w:netrw_bannercnt= 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002953
2954 let sortby= g:netrw_sort_by
2955 if g:netrw_sort_direction =~ "^r"
2956 let sortby= sortby." reversed"
2957 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00002958
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002959 " Sorted by...
Bram Moolenaar8299df92004-07-10 09:47:34 +00002960 if g:netrw_sort_by =~ "^n"
Bram Moolenaar269ec652004-07-29 08:43:53 +00002961" call Decho("directories will be sorted by name")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002962 " sorted by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002963 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar8299df92004-07-10 09:47:34 +00002964 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar488c6512005-08-11 20:09:58 +00002965 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8299df92004-07-10 09:47:34 +00002966 else
Bram Moolenaar269ec652004-07-29 08:43:53 +00002967" call Decho("directories will be sorted by size or date")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002968 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002969 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar488c6512005-08-11 20:09:58 +00002970 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002971 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002972
2973 " Hiding... -or- Showing...
Bram Moolenaar269ec652004-07-29 08:43:53 +00002974 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002975 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002976 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002977 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002978 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002979 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002980 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002981 endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002982 keepjumps put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002983 keepjumps put ='\" ============================================================================'
Bram Moolenaar488c6512005-08-11 20:09:58 +00002984 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002985
2986 " bannercnt should index the line just after the banner
Bram Moolenaar488c6512005-08-11 20:09:58 +00002987 let w:netrw_bannercnt= w:netrw_bannercnt + 1
2988" call Decho("bannercnt=".w:netrw_bannercnt)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002989
2990 " generate the requested directory listing
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002991 call s:LocalBrowseList()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002992
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002993 " set up syntax highlighting
2994 if has("syntax")
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002995 setlocal ft=netrw
Bram Moolenaar572cb562005-08-05 21:35:02 +00002996 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002997 setlocal ft=
2998 endif
2999 endif
3000
Bram Moolenaar8299df92004-07-10 09:47:34 +00003001 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00003002 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00003003 if g:netrw_hide && g:netrw_list_hide != ""
3004 call s:NetrwListHide()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003005 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003006 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003007
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003008 if g:netrw_sort_by =~ "^n"
3009 call s:SetSort()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003010
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003011 if w:netrw_bannercnt < line("$")
3012 if g:netrw_sort_direction =~ 'n'
3013 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
3014 else
3015 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
3016 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003017 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003018 " remove priority pattern prefix
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003019 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003020
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003021 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003022 if w:netrw_bannercnt < line("$")
3023 if g:netrw_sort_direction =~ 'n'
3024 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
3025 else
3026 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
3027 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003028 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003029 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003030 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003031
Bram Moolenaar8299df92004-07-10 09:47:34 +00003032 endif
3033 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003034
3035 call s:NetrwWideListing()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003036 if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003037 " place cursor on the top-left corner of the file listing
3038 exe 'silent '.w:netrw_bannercnt
3039 norm! 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003040 endif
3041
3042 " record previous current directory
3043 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaar8299df92004-07-10 09:47:34 +00003044
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003045 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003046 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003047 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003048 setlocal noma nomod nonu nobl nowrap
3049 if g:netrw_fastbrowse >= 2
3050 setlocal bh=hide
3051 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003052
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003053" call Dret("DirBrowse : file<".expand("%:p")."> bufname<".bufname("%").">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003054endfun
3055
3056" ---------------------------------------------------------------------
3057" LocalBrowseList: does the job of "ls" for local directories {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003058fun! s:LocalBrowseList()
Bram Moolenaar57657d82006-04-21 22:12:41 +00003059" call Dfunc("LocalBrowseList() b:netrw_curdir<".b:netrw_curdir."> sortby<".g:netrw_sort_by.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003060
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003061 " get the list of files contained in the current directory
Bram Moolenaar83bab712005-08-01 21:58:57 +00003062 let dirname = escape(b:netrw_curdir,s:netrw_glob_escape)
3063 let dirnamelen = strlen(b:netrw_curdir)
3064 let filelist = glob(dirname."/*")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003065" call Decho("glob(dirname<".dirname."/.*>)=".filelist)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003066 if filelist != ""
3067 let filelist= filelist."\n"
3068 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003069 let filelist= filelist.glob(dirname."/.*")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003070" call Decho("glob(dirname<".dirname."/.*>)=".glob(dirname.".*"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003071
3072 " if the directory name includes a "$", and possibly other characters,
3073 " the glob() doesn't include "." and ".." entries.
3074 if filelist !~ '[\\/]\.[\\/]\=\(\n\|$\)'
3075" call Decho("forcibly tacking on .")
3076 if filelist == ""
3077 let filelist= dirname."."
3078 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003079 let filelist= filelist."\n".b:netrw_curdir."."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003080 endif
3081" call Decho("filelist<".filelist.">")
3082 endif
3083 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
3084" call Decho("forcibly tacking on ..")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003085 let filelist= filelist."\n".b:netrw_curdir.".."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003086" call Decho("filelist<".filelist.">")
3087 endif
3088 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
Bram Moolenaar57657d82006-04-21 22:12:41 +00003089 if (has("win32") || has("win95") || has("win64") || has("win16"))
3090 let filelist= substitute(filelist,'\','/','ge')
3091 else
3092 let filelist= substitute(filelist,'\','\\','ge')
3093 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003094
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003095" call Decho("dirname<".dirname.">")
3096" call Decho("dirnamelen<".dirnamelen.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003097" call Decho("filelist<".filelist.">")
3098
3099 while filelist != ""
3100 if filelist =~ '\n'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003101 let filename = substitute(filelist,'\n.*$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003102 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
3103 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003104 let filename = filelist
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003105 let filelist = ""
Bram Moolenaar8299df92004-07-10 09:47:34 +00003106 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003107 let pfile= filename
3108 if isdirectory(filename)
3109 let pfile= filename."/"
Bram Moolenaar8299df92004-07-10 09:47:34 +00003110 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003111 if pfile =~ '//$'
3112 let pfile= substitute(pfile,'//$','/','e')
3113 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003114 let pfile= strpart(pfile,dirnamelen)
Bram Moolenaar572cb562005-08-05 21:35:02 +00003115 let pfile= substitute(pfile,'^/','','e')
Bram Moolenaar83bab712005-08-01 21:58:57 +00003116" call Decho(" ")
3117" call Decho("filename<".filename.">")
3118" call Decho("pfile <".pfile.">")
3119
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003120 if w:netrw_longlist == 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003121 let sz = getfsize(filename)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003122 let fsz = strpart(" ",1,15-strlen(sz)).sz
3123 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003124" call Decho("sz=".sz." fsz=".fsz)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003125 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003126
Bram Moolenaar8299df92004-07-10 09:47:34 +00003127 if g:netrw_sort_by =~ "^t"
3128 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003129" call Decho("getftime(".filename.")=".getftime(filename))
3130 let t = getftime(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003131 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar83bab712005-08-01 21:58:57 +00003132" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003133 let ftpfile= ft.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003134 keepjumps silent! put=ftpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003135
Bram Moolenaar8299df92004-07-10 09:47:34 +00003136 elseif g:netrw_sort_by =~ "^s"
3137 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003138" call Decho("getfsize(".filename.")=".getfsize(filename))
3139 let sz = getfsize(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003140 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar83bab712005-08-01 21:58:57 +00003141" call Decho("exe keepjumps put ='".fsz.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003142 let fszpfile= fsz.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003143 keepjumps silent! put =fszpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003144
Bram Moolenaar8299df92004-07-10 09:47:34 +00003145 else
3146 " sort by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003147" call Decho("exe keepjumps put ='".pfile."'")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003148 keepjumps silent! put=pfile
Bram Moolenaar8299df92004-07-10 09:47:34 +00003149 endif
3150 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003152 " cleanup any windows mess at end-of-line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003153 silent! keepjumps %s/\r$//e
Bram Moolenaar83bab712005-08-01 21:58:57 +00003154 setlocal ts=32
Bram Moolenaar8299df92004-07-10 09:47:34 +00003155
3156" call Dret("LocalBrowseList")
3157endfun
3158
3159" ---------------------------------------------------------------------
3160" LocalBrowseChgDir: constructs a new directory based on the current {{{2
3161" directory and a new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003162fun! s:LocalBrowseChgDir(dirname,newdir,...)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003163" call Dfunc("LocalBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">) a:0=".a:0)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003164
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003165 let dirname= substitute(a:dirname,'\\','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003166 let newdir = a:newdir
3167
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003168 if dirname !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00003169 " apparently vim is "recognizing" that it is in the home directory and
3170 " is removing the "/". Bad idea, so I have to put it back.
3171 let dirname= dirname.'/'
3172" call Decho("adjusting dirname<".dirname.">")
3173 endif
3174
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003175 if newdir !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00003176 " handling a file
3177 let dirname= dirname.newdir
3178" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003179 " this lets NetBrowseX avoid the edit
3180 if a:0 < 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003181" call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape.">")
3182" call Decho("about to edit<".escape(dirname,s:netrw_cd_escape).">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003183 if g:netrw_browse_split == 1
3184 new
3185 wincmd _
3186 elseif g:netrw_browse_split == 2
3187 rightb vert new
3188 wincmd |
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003189 else
3190 " handling a file, didn't split, so possibly remove menu
3191 call s:NetMenu(0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003192 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003193 exe "e! ".escape(dirname,s:netrw_cd_escape)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003194 set ma nomod
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003195 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003196
3197 elseif newdir == './'
3198 " refresh the directory list
3199" call Decho("refresh directory listing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003200
3201 elseif newdir == '../'
3202 " go up one directory
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003203 let dirname= substitute(dirname,'^\(.*/\)\([^/]\+[\/]$\)','\1','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003204" call Decho("go up one dir: dirname<".dirname.">")
3205
3206 else
3207 " go down one directory
3208 let dirname= dirname.newdir
3209" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
3210 endif
3211
3212" call Dret("LocalBrowseChgDir <".dirname.">")
3213 return dirname
3214endfun
3215
3216" ---------------------------------------------------------------------
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003217" LocalBrowseShellCmdRefresh: this function is called after a user has {{{2
3218" performed any shell command. The idea is to cause all local-browsing
3219" buffers to be refreshed after a user has executed some shell command,
3220" on the chance that s/he removed/created a file/directory with it.
3221fun! s:LocalBrowseShellCmdRefresh()
3222" call Dfunc("LocalBrowseShellCmdRefresh() browselist=".string(s:netrw_browselist))
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003223 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
3224 " | refresh any netrw window
3225 " | wipe out any non-displaying netrw buffer
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003226 let curwin = winnr()
3227 let ibl = 0
3228 for ibuf in s:netrw_browselist
3229 if bufwinnr(ibuf) == -1
3230" call Decho("wiping buf#".ibuf)
Bram Moolenaarc01140a2006-03-24 22:21:52 +00003231 exe "silent! bw ".ibuf
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003232 call remove(s:netrw_browselist,ibl)
3233" call Decho("browselist=".string(s:netrw_browselist))
3234 continue
3235 else
3236" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
3237 exe bufwinnr(ibuf)."wincmd w"
3238 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
3239 endif
3240 let ibl= ibl + 1
3241 endfor
3242 exe curwin."wincmd w"
3243
3244" call Dret("LocalBrowseShellCmdRefresh")
3245endfun
3246
3247" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00003248" LocalBrowseRm: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003249fun! s:LocalBrowseRm(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003250" call Dfunc("LocalBrowseRm(path<".a:path.">)")
3251" call Decho("firstline=".a:firstline." lastline=".a:lastline)
3252
3253 " preparation for removing multiple files/directories
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003254 let ctr = a:firstline
3255 let ret = 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003256 let all= 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00003257
3258 " remove multiple files and directories
3259 while ctr <= a:lastline
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003260 exe "keepjumps ".ctr
3261
3262 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003263 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003264 let ctr= ctr + 1
3265 continue
3266 endif
3267 let curword= s:NetGetWord()
3268 if curword == "./" || curword == "../"
3269 let ctr= ctr + 1
3270 continue
3271 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003272
3273 norm! 0
Bram Moolenaar83bab712005-08-01 21:58:57 +00003274 let rmfile= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003275" call Decho("rmfile<".rmfile.">")
3276
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003277 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003278 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003279 if !all
3280 echohl Statement
3281 call inputsave()
3282 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3283 call inputrestore()
3284 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003285 if ok == ""
3286 let ok="no"
3287 endif
3288" call Decho("response: ok<".ok.">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003289 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003290" call Decho("response: ok<".ok."> (after sub)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003291 if ok =~ 'a\%[ll]'
3292 let all= 1
3293 endif
3294 endif
3295
3296 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003297 let ret= delete(rmfile)
3298" call Decho("errcode=".v:shell_error." ret=".ret)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003299 elseif ok =~ 'q\%[uit]'
3300 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003301 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003302
Bram Moolenaar8299df92004-07-10 09:47:34 +00003303 else
3304 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003305 if !all
3306 echohl Statement
3307 call inputsave()
3308 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3309 call inputrestore()
3310 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003311 if ok == ""
3312 let ok="no"
3313 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003314 if ok =~ 'a\%[ll]'
3315 let all= 1
3316 endif
3317 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003318 let rmfile= substitute(rmfile,'[\/]$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003319
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003320 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003321" call Decho("1st attempt: system(".g:netrw_local_rmdir.' "'.rmfile.'")')
3322 call system(g:netrw_local_rmdir.' "'.rmfile.'"')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003323" call Decho("v:shell_error=".v:shell_error)
3324
3325 if v:shell_error != 0
3326" call Decho("2nd attempt to remove directory<".rmfile.">")
3327 let errcode= delete(rmfile)
3328" call Decho("errcode=".errcode)
3329
3330 if errcode != 0
3331 if has("unix")
3332" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003333call system("rm ".rmfile)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003334 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003335 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003336 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003337endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003338 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003339 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003340 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003341 endif
3342 endif
3343 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003344
3345 elseif ok =~ 'q\%[uit]'
3346 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003347 endif
3348 endif
3349
3350 let ctr= ctr + 1
3351 endwhile
3352
3353 " refresh the directory
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003354 let curline= line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003355" call Decho("refresh the directory")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003356 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003357 exe curline
3358
3359" call Dret("LocalBrowseRm")
3360endfun
3361
3362" ---------------------------------------------------------------------
3363" LocalBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003364fun! s:LocalBrowseRename(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003365" call Dfunc("LocalBrowseRename(path<".a:path.">)")
3366
3367 " preparation for removing multiple files/directories
3368 let ctr= a:firstline
3369
3370 " attempt to rename files/directories
3371 while ctr <= a:lastline
3372 exe "keepjumps ".ctr
3373
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003374 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003375 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003376 let ctr= ctr + 1
3377 continue
3378 endif
3379 let curword= s:NetGetWord()
3380 if curword == "./" || curword == "../"
3381 let ctr= ctr + 1
3382 continue
3383 endif
3384
Bram Moolenaar8299df92004-07-10 09:47:34 +00003385 norm! 0
Bram Moolenaar572cb562005-08-05 21:35:02 +00003386 let oldname= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003387" call Decho("oldname<".oldname.">")
3388
3389 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003390 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00003391 call inputrestore()
3392
Bram Moolenaar83bab712005-08-01 21:58:57 +00003393 let ret= rename(oldname,newname)
3394" call Decho("renaming <".oldname."> to <".newname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003395
3396 let ctr= ctr + 1
3397 endwhile
3398
3399 " refresh the directory
3400 let curline= line(".")
Bram Moolenaar269ec652004-07-29 08:43:53 +00003401" call Decho("refresh the directory listing")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003402 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003403 exe "keepjumps ".curline
3404" call Dret("LocalBrowseRename")
3405endfun
3406
3407" ---------------------------------------------------------------------
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00003408" LocalFastBrowser: handles setting up/taking down fast browsing for the {{{2
3409" local browser
3410fun! s:LocalFastBrowser()
3411" call Dfunc("LocalFastBrowser()")
3412
3413 " initialize browselist, a list of buffer numbers that the local browser has used
3414 if !exists("s:netrw_browselist")
3415 let s:netrw_browselist= []
3416 endif
3417
3418 " append current buffer to fastbrowse list
3419 if g:netrw_fastbrowse <= 1 && (empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1])
3420 call add(s:netrw_browselist,bufnr("%"))
3421" call Decho("browselist=".string(s:netrw_browselist))
3422 endif
3423
3424 " enable autocmd events to handle refreshing/removing local browser buffers
3425 " If local browse buffer is currently showing: refresh it
3426 " If local browse buffer is currently hidden : wipe it
3427 if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1
3428" call Decho("setting up local-browser shell command refresh")
3429 let s:netrw_browser_shellcmd= 1
3430 augroup AuNetrwShellCmd
3431 au!
3432 au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()
3433 augroup END
Bram Moolenaar8dff8182006-04-06 20:18:50 +00003434 endif
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00003435
3436 " user must have changed fastbrowse to its fast setting, so remove
3437 " the associated autocmd events
3438 if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd")
3439 unlet s:netrw_browser_shellcmd
3440 augroup AuNetrwShellCmd
3441 au!
3442 augroup END
3443 augroup! AuNetrwShellCmd
3444 endif
3445
3446" call Dret("LocalFastBrowser")
3447endfun
3448
3449" ---------------------------------------------------------------------
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003450" LocalObtain: copy selected file to current working directory {{{2
3451fun! s:LocalObtain()
3452" call Dfunc("LocalObtain()")
3453 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
3454 let fname= expand("<cWORD>")
3455 let fcopy= readfile(b:netrw_curdir."/".fname,"b")
3456 call writefile(fcopy,getcwd()."/".fname,"b")
3457 elseif !exists("b:netrw_curdir")
3458 echohl Error | echo "***netrw*** local browsing directory doesn't exist!"
3459 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3460 else
3461 echohl Error | echo "***netrw*** local browsing directory and current directory are identical"
3462 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3463 endif
3464" call Dret("LocalObtain")
3465endfun
3466
3467" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003468" LocalPreview: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003469fun! s:LocalPreview(path) range
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003470" call Dfunc("LocalPreview(path<".a:path.">)")
3471 if has("quickfix")
3472 if !isdirectory(a:path)
3473 exe "pedit ".a:path
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003474 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003475 echohl WarningMsg | echo "***netrw*** sorry, cannot preview a directory such as <".a:path.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003476 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003477 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003478 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003479 echohl WarningMsg | echo "***netrw*** sorry, to preview your vim needs the quickfix feature compiled in" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003480 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003481 endif
3482" call Dret("LocalPreview")
3483endfun
3484
3485" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003486" Explore: launch the local browser in the directory of the current file {{{2
3487" dosplit==0: the window will be split iff the current file has
3488" been modified
3489" dosplit==1: the window will be split before running the local
3490" browser
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003491fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003492" call Dfunc("Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.")")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003493
3494 " if dosplit or file has been modified
3495 if a:dosplit || &modified
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003496 call s:SaveWinVars()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003497
Bram Moolenaar83bab712005-08-01 21:58:57 +00003498 if a:style == 0 " Explore, Sexplore
3499 exe g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003500" call Decho("style=0: Explore or Sexplore")
3501
Bram Moolenaar83bab712005-08-01 21:58:57 +00003502 elseif a:style == 1 "Explore!, Sexplore!
3503 exe g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003504" call Decho("style=1: Explore! or Sexplore!")
3505
Bram Moolenaar83bab712005-08-01 21:58:57 +00003506 elseif a:style == 2 " Hexplore
3507 exe "bel ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003508" call Decho("style=2: Hexplore")
3509
Bram Moolenaar83bab712005-08-01 21:58:57 +00003510 elseif a:style == 3 " Hexplore!
3511 exe "abo ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003512" call Decho("style=3: Hexplore!")
3513
Bram Moolenaar83bab712005-08-01 21:58:57 +00003514 elseif a:style == 4 " Vexplore
3515 exe "lefta ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003516" call Decho("style=4: Vexplore")
3517
Bram Moolenaar83bab712005-08-01 21:58:57 +00003518 elseif a:style == 5 " Vexplore!
3519 exe "rightb ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003520" call Decho("style=5: Vexplore!")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003521 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003522 call s:CopyWinVars()
Bram Moolenaar83bab712005-08-01 21:58:57 +00003523 endif
3524 norm! 0
3525
Bram Moolenaar57657d82006-04-21 22:12:41 +00003526 if a:1 =~ '\*/'
3527 " Explore */pattern
3528 let pattern= substitute(a:1,'^\*/\(.*\)$','\1','')
3529" call Decho("Explore */".pattern)
3530 endif
3531
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003532 if a:1 == "" && a:indx >= 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003533 " Explore Hexplore Vexplore Sexplore
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003534" call Decho("Explore Hexplore Vexplore Sexplore")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003535 let newdir= substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
3536 if newdir =~ '^scp:' || newdir =~ '^ftp:'
3537" call Decho("calling NetBrowse(newdir<".newdir.">)")
3538 call s:NetBrowse(newdir)
3539 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003540 if newdir == ""|let newdir= getcwd()|endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003541" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3542 call s:LocalBrowse(newdir)
3543 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003544
Bram Moolenaar57657d82006-04-21 22:12:41 +00003545 elseif a:1 =~ '^\*\*/' || a:indx < 0 || a:1 =~ '^\*/'
3546 " Nexplore, Pexplore, Explore **/... , or Explore */pattern
3547" call Decho("Nexplore, Pexplore, <s-down>, <s-up>, Explore ".a:1)
3548 let s:didstarstar= 1
3549 if exists("b:netrw_curdir")
3550 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
3551 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
3552 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003553
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003554 if has("path_extra")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003555 if !exists("w:netrw_explore_indx")
3556 let w:netrw_explore_indx= 0
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003557 endif
3558 let indx = a:indx
Bram Moolenaar57657d82006-04-21 22:12:41 +00003559" call Decho("input indx=".indx)
3560"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003561 if indx == -1
Bram Moolenaar57657d82006-04-21 22:12:41 +00003562 if !exists("w:netrw_explore_list") " sanity check
3563 echohl WarningMsg | echo "***netrw*** using Nexplore or <s-down> improperly; see help for netrw-starstar" | echohl None
3564 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3565" call Dret("Explore")
3566 return
3567 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003568 let indx= w:netrw_explore_indx + 1
Bram Moolenaar57657d82006-04-21 22:12:41 +00003569" call Decho("indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
3570
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003571 elseif indx == -2
Bram Moolenaar57657d82006-04-21 22:12:41 +00003572 if !exists("w:netrw_explore_list") " sanity check
3573 echohl WarningMsg | echo "***netrw*** using Pexplore or <s-up> improperly; see help for netrw-starstar" | echohl None
3574 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3575" call Dret("Explore")
3576 return
3577 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003578 let indx= w:netrw_explore_indx - 1
Bram Moolenaar57657d82006-04-21 22:12:41 +00003579" call Decho("indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
3580
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003581 else
Bram Moolenaar57657d82006-04-21 22:12:41 +00003582 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar488c6512005-08-11 20:09:58 +00003583 let w:netrw_explore_indx = 0
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003584 if !exists("b:netrw_curdir")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003585 let b:netrw_curdir= getcwd()
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003586 endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003587" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
3588 if exists("pattern")
3589" call Decho("building list based on pattern<".pattern."> cwd<".getcwd().">")
3590 exe "vimgrep /".pattern."/gj ".b:netrw_curdir."/*"
3591 let w:netrw_explore_list = map(getqflist(),'b:netrw_curdir.bufname(v:val.bufnr)')
3592 else
3593" call Decho("building list based on ".b:netrw_curdir."/".a:1)
3594 let w:netrw_explore_list= split(expand(b:netrw_curdir."/".a:1),'\n')
3595 endif
3596
Bram Moolenaar488c6512005-08-11 20:09:58 +00003597 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaar57657d82006-04-21 22:12:41 +00003598" call Decho("w:netrw_explore_list<".string(w:netrw_explore_list)."> listlen=".w:netrw_explore_listlen)
3599
Bram Moolenaar488c6512005-08-11 20:09:58 +00003600 if w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/'
Bram Moolenaar572cb562005-08-05 21:35:02 +00003601 echohl WarningMsg | echo "***netrw*** no files matched" | echohl None
3602 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3603" call Dret("Explore")
3604 return
3605 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003606 endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003607
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003608 " NetrwStatusLine support - for exploring support
Bram Moolenaar488c6512005-08-11 20:09:58 +00003609 let w:netrw_explore_indx= indx
Bram Moolenaar488c6512005-08-11 20:09:58 +00003610" call Decho("explorelist<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003611
3612 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003613 if indx >= w:netrw_explore_listlen || indx < 0
3614 let indx= (indx < 0)? 0 : ( w:netrw_explore_listlen - 1 )
Bram Moolenaar572cb562005-08-05 21:35:02 +00003615 echohl WarningMsg | echo "***netrw*** no more files match Explore pattern" | echohl None
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003616 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3617" call Dret("Explore")
3618 return
3619 endif
3620
Bram Moolenaar488c6512005-08-11 20:09:58 +00003621 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003622" call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003623 let newdir= substitute(dirfile,'/[^/]*$','','e')
3624" call Decho("newdir<".newdir.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003625
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003626" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3627 call s:LocalBrowse(newdir)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003628 if w:netrw_longlist == 0 || w:netrw_longlist == 1
3629 call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
3630 else
3631 call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
3632 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003633 let w:netrw_explore_mtchcnt = indx + 1
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003634 let w:netrw_explore_bufnr = bufnr("%")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003635 let w:netrw_explore_line = line(".")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003636 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaar488c6512005-08-11 20:09:58 +00003637" 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 +00003638
3639 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003640 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003641 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 +00003642 endif
3643 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3644 endif
3645
Bram Moolenaar83bab712005-08-01 21:58:57 +00003646 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003647" call Decho("Explore newdir<".a:1.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003648 let newdir= a:1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003649 call s:LocalBrowse(newdir)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003650 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003651
3652" call Dret("Explore")
3653endfun
3654
3655" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003656" SetupNetrwStatusLine: {{{2
3657fun! s:SetupNetrwStatusLine(statline)
3658" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
3659
3660 if !exists("s:netrw_setup_statline")
3661 let s:netrw_setup_statline= 1
3662" call Decho("do first-time status line setup")
3663
3664 if !exists("s:netrw_users_stl")
3665 let s:netrw_users_stl= &stl
3666 endif
3667 if !exists("s:netrw_users_ls")
3668 let s:netrw_users_ls= &laststatus
3669 endif
3670
3671 " set up User9 highlighting as needed
3672 let keepa= @a
3673 redir @a
3674 try
3675 hi User9
3676 catch /^Vim\%((\a\+)\)\=:E411/
3677 if &bg == "dark"
3678 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
3679 else
3680 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
3681 endif
3682 endtry
3683 redir END
3684 let @a= keepa
3685 endif
3686
3687 " set up status line (may use User9 highlighting)
3688 " insure that windows have a statusline
3689 " make sure statusline is displayed
3690 let &stl=a:statline
3691 set laststatus=2
3692" call Decho("stl=".&stl)
3693 redraw!
3694
3695" call Dret("SetupNetrwStatusLine : stl=".&stl)
3696endfun
3697
3698" ---------------------------------------------------------------------
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003699" NetrwStatusLine: {{{2
3700fun! NetrwStatusLine()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003701
3702 " vvv NetrwStatusLine() debugging vvv
3703" let g:stlmsg=""
3704" if !exists("w:netrw_explore_bufnr")
3705" let g:stlmsg="!X<explore_bufnr>"
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003706" elseif w:netrw_explore_bufnr != bufnr("%")
3707" let g:stlmsg="explore_bufnr!=".bufnr("%")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003708" endif
3709" if !exists("w:netrw_explore_line")
3710" let g:stlmsg=" !X<explore_line>"
3711" elseif w:netrw_explore_line != line(".")
3712" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
3713" endif
3714" if !exists("w:netrw_explore_list")
3715" let g:stlmsg=" !X<explore_list>"
3716" endif
3717 " ^^^ NetrwStatusLine() debugging ^^^
3718
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003719 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 +00003720 " restore user's status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003721 let &stl = s:netrw_users_stl
3722 let &laststatus = s:netrw_users_ls
Bram Moolenaar488c6512005-08-11 20:09:58 +00003723 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
3724 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003725 return ""
3726 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003727 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003728 endif
3729endfun
3730
3731" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003732" NetGetcwd: get the current directory. {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003733" Change backslashes to forward slashes, if any.
3734" If doesc is true, escape certain troublesome characters
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003735fun! s:NetGetcwd(doesc)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003736" call Dfunc("NetGetcwd(doesc=".a:doesc.")")
3737 let curdir= substitute(getcwd(),'\\','/','ge')
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003738 if curdir !~ '[\/]$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003739 let curdir= curdir.'/'
3740 endif
3741 if a:doesc
3742 let curdir= escape(curdir,s:netrw_cd_escape)
3743 endif
3744" call Dret("NetGetcwd <".curdir.">")
3745 return curdir
3746endfun
3747
3748" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003749" NetMethod: determine method of transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750" method == 1: rcp
3751" 2: ftp + <.netrc>
3752" 3: ftp + machine, id, password, and [path]filename
3753" 4: scp
3754" 5: http (wget)
3755" 6: cadaver
3756" 7: rsync
3757" 8: fetch
3758" 9: sftp
3759fun! s:NetMethod(choice) " globals: method machine id passwd fname
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003760" call Dfunc("NetMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003762 " initialization
3763 let b:netrw_method = 0
3764 let g:netrw_machine = ""
3765 let b:netrw_fname = ""
3766 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003767 let g:netrw_choice = a:choice
3768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003769 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003770 " mipf : a:machine a:id password filename Use ftp
3771 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003772 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003773 " rcpurm : rcp://[user@]host/filename Use rcp
3774 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003775 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003776 " httpurm : http://[user@]host/filename Use wget
3777 " davurm : [s]dav://host[:port]/path Use cadaver
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003778 " rsyncurm : rsync://host[:port]/path Use rsync
3779 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3780 " sftpurm : sftp://[user@]host/filename Use scp
3781 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3782 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
3783 let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003784 let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003785 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003786 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003787 let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003788 let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003789 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
3790 let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
3791 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003792
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003793" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003794 " Determine Method
3795 " rcp://user@hostname/...path-to-file
3796 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003797" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003798 let b:netrw_method = 1
3799 let userid = substitute(a:choice,rcpurm,'\1',"")
3800 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3801 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003802 if userid != ""
3803 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003805
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003806 " scp://user@hostname/...path-to-file
3807 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003808" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003809 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003810 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3811 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3812 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003813
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003814 " http://user@hostname/...path-to-file
3815 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003816" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003817 let b:netrw_method = 5
3818 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3819 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003820
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003821 " dav://hostname[:port]/..path-to-file..
3822 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003823" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003824 let b:netrw_method= 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003825 if a:choice =~ '^s'
3826 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3827 else
3828 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3829 endif
3830 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003831
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003832 " rsync://user@hostname/...path-to-file
3833 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003834" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003835 let b:netrw_method = 7
3836 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3837 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003838
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003839 " ftp://[user@]hostname[[:#]port]/...path-to-file
3840 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003841" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003842 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003843 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3844 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3845 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003846 if userid != ""
3847 let g:netrw_uid= userid
3848 endif
3849 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3850 let b:netrw_method = 3
3851 else
3852 if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc")
3853 let b:netrw_method= 2
3854 else
3855 if !exists("g:netrw_uid") || g:netrw_uid == ""
3856 call NetUserPass()
3857 elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
3858 call NetUserPass(g:netrw_uid)
3859 " else just use current g:netrw_uid and g:netrw_passwd
3860 endif
3861 let b:netrw_method= 3
3862 endif
3863 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003864
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003865 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003866" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003867 let b:netrw_method = 8
3868 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3869 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3870 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3871 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003872
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003873 " Issue an ftp : "machine id password [path/]filename"
3874 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003875" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003877 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3878 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
3879 let g:netrw_passwd = substitute(a:choice,mipf,'\3',"")
3880 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003881
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003882 " Issue an ftp: "hostname [path/]filename"
3883 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003884" call Decho("(ftp) host file")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003885 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3886 let b:netrw_method = 3
3887 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3888 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003889
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003890 elseif filereadable(expand("$HOME/.netrc"))
3891 let b:netrw_method = 2
3892 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3893 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3894 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003895
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003896 " sftp://user@hostname/...path-to-file
3897 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003898" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003899 let b:netrw_method = 9
3900 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3901 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003902
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003903 " Issue an rcp: hostname:filename" (this one should be last)
3904 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003905" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003906 let b:netrw_method = 1
3907 let userid = substitute(a:choice,rcphf,'\2',"")
3908 let g:netrw_machine= substitute(a:choice,rcphf,'\3',"")
3909 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003910" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
3911" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
3912" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
3913" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003914 if userid != ""
3915 let g:netrw_uid= userid
3916 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003917 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003918 " don't let PCs try <.netrc>
3919 let b:netrw_method = 3
3920 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003921
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003922 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003923 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003924 echohl Error | echo "***netrw*** cannot determine method" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003925 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003926 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003927 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 endif
Bram Moolenaar81695252004-12-29 20:58:21 +00003929
3930 " remove any leading [:#] from port number
3931 if g:netrw_port != ""
3932 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3933 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003934
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003935" call Decho("a:choice <".a:choice.">")
3936" call Decho("b:netrw_method <".b:netrw_method.">")
3937" call Decho("g:netrw_machine<".g:netrw_machine.">")
3938" call Decho("g:netrw_port <".g:netrw_port.">")
3939" if exists("g:netrw_uid") "Decho
3940" call Decho("g:netrw_uid <".g:netrw_uid.">")
3941" endif "Decho
3942" if exists("g:netrw_passwd") "Decho
3943" call Decho("g:netrw_passwd <".g:netrw_passwd.">")
3944" endif "Decho
3945" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003946" call Dret("NetMethod : b:netrw_method=".b:netrw_method)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948
3949" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003950" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951" Usage: :call NetUserPass() -- will prompt for userid and password
3952" :call NetUserPass("uid") -- will prompt for password
3953" :call NetUserPass("uid","password") -- sets global userid and password
3954fun! NetUserPass(...)
3955
3956 " get/set userid
3957 if a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003958" call Dfunc("NetUserPass(a:0<".a:0.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 if !exists("g:netrw_uid") || g:netrw_uid == ""
3960 " via prompt
3961 let g:netrw_uid= input('Enter username: ')
3962 endif
3963 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003964" call Dfunc("NetUserPass(a:1<".a:1.">) {")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 let g:netrw_uid= a:1
3966 endif
3967
3968 " get password
3969 if a:0 <= 1 " via prompt
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003970" call Decho("a:0=".a:0." case <=1:")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 let g:netrw_passwd= inputsecret("Enter Password: ")
3972 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003973" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 let g:netrw_passwd=a:2
3975 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003976
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003977" call Dret("NetUserPass")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979
3980" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003981" NetOptionSave: save options and set to "standard" form {{{2
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003982fun! s:NetOptionSave()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003983" call Dfunc("NetOptionSave()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003984 if !exists("w:netoptionsave")
3985 let w:netoptionsave= 1
3986 else
3987" call Dret("NetOptionSave : netoptionsave=".w:netoptionsave)
3988 return
3989 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003991 " Get Temporary Filename
Bram Moolenaar57657d82006-04-21 22:12:41 +00003992 let w:acdkeep = &acd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003993 let w:aikeep = &ai
Bram Moolenaar57657d82006-04-21 22:12:41 +00003994 let w:fokeep = &fo
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003995 let w:cikeep = &ci
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003996 let w:cinkeep = &cin
3997 let w:cinokeep = &cino
3998 let w:comkeep = &com
3999 let w:cpokeep = &cpo
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00004000 let w:hidkeep = &hidden
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004001 let w:magickeep = &magic
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004002 let w:gdkeep = &gd
4003 let w:repkeep = &report
4004 let w:spellkeep = &spell
4005 let w:twkeep = &tw
Bram Moolenaar8299df92004-07-10 09:47:34 +00004006 setlocal cino =
4007 setlocal com =
4008 setlocal cpo -=aA
Bram Moolenaar57657d82006-04-21 22:12:41 +00004009 setlocal noacd nocin noai noci magic nospell fo=nroql2 nohid
Bram Moolenaar8299df92004-07-10 09:47:34 +00004010 setlocal tw =0
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004011 setlocal report=10000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004012 if has("win32") && !has("win95")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004013 let w:swfkeep= &swf
Bram Moolenaar8299df92004-07-10 09:47:34 +00004014 setlocal noswf
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004015" call Decho("setting w:swfkeep to <".&swf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004016 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004018" call Dret("NetOptionSave")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019endfun
4020
4021" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004022" NetOptionRestore: restore options {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023fun! s:NetOptionRestore()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004024" call Dfunc("NetOptionRestore()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004025 if !exists("w:netoptionsave")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004026" call Dret("NetOptionRestore : w:netoptionsave doesn't exist")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004027 return
4028 endif
4029 unlet w:netoptionsave
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004030
Bram Moolenaar57657d82006-04-21 22:12:41 +00004031 if exists("w:acdkeep") |let &acd = w:acdkeep |unlet w:acdkeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004032 if exists("w:aikeep") |let &ai = w:aikeep |unlet w:aikeep |endif
4033 if exists("w:cikeep") |let &ci = w:cikeep |unlet w:cikeep |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004034 if exists("w:cinkeep") |let &cin = w:cinkeep |unlet w:cinkeep |endif
4035 if exists("w:cinokeep") |let &cino = w:cinokeep |unlet w:cinokeep |endif
4036 if exists("w:comkeep") |let &com = w:comkeep |unlet w:comkeep |endif
4037 if exists("w:cpokeep") |let &cpo = w:cpokeep |unlet w:cpokeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004038 if exists("w:fokeep") |let &fo = w:fokeep |unlet w:fokeep |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004039 if exists("w:gdkeep") |let &gd = w:gdkeep |unlet w:gdkeep |endif
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00004040 if exists("w:hidkeep") |let &hidden = w:hidkeep |unlet w:hidkeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004041 if exists("w:magic") |let &magic = w:magic |unlet w:magic |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004042 if exists("w:repkeep") |let &report = w:repkeep |unlet w:repkeep |endif
4043 if exists("w:spellkeep")|let &spell = w:spellkeep |unlet w:spellkeep|endif
4044 if exists("w:twkeep") |let &tw = w:twkeep |unlet w:twkeep |endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004045 if exists("w:swfkeep")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004046 if &directory == "" && exists("w:swfkeep")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004047 " user hasn't specified a swapfile directory;
4048 " netrw will temporarily make the swapfile
4049 " directory the current local one.
4050 let &directory = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004051 silent! let &swf = w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004052 set directory=
4053 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004054 let &swf= w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004055 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004056 unlet w:swfkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004057 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004058
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004059" call Dret("NetOptionRestore")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060endfun
4061
4062" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004063" NetReadFixup: this sort of function is typically written by the user {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004064" to handle extra junk that their system's ftp dumps
4065" into the transfer. This function is provided as an
4066" example and as a fix for a Windows 95 problem: in my
4067" experience, win95's ftp always dumped four blank lines
4068" at the end of the transfer.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004069if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 fun! NetReadFixup(method, line1, line2)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004071" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 if method == 3 " ftp (no <.netrc>)
4073 let fourblanklines= line2 - 3
4074 silent fourblanklines.",".line2."g/^\s*/d"
4075 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004076" call Dret("NetReadFixup")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 endfun
4078endif
4079
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004080" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004081" NetSort: Piet Delport's BISort2() function, modified to take a range {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00004082if v:version < 700
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004083 fun! s:NetSort() range
Bram Moolenaar83bab712005-08-01 21:58:57 +00004084" " call Dfunc("NetSort()")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004085
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004086 let i = a:firstline + 1
4087 while i <= a:lastline
4088 " find insertion point via binary search
4089 let i_val = getline(i)
4090 let lo = a:firstline
4091 let hi = i
4092 while lo < hi
Bram Moolenaar83bab712005-08-01 21:58:57 +00004093 let mid = (lo + hi) / 2
4094 let mid_val = getline(mid)
4095 if g:netrw_sort_direction =~ '^n'
4096 " normal sorting order
4097 if i_val < mid_val
4098 let hi = mid
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004099 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00004100 let lo = mid + 1
4101 if i_val == mid_val | break | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004102 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00004103 else
4104 " reverse sorting order
4105 if i_val > mid_val
4106 let hi = mid
4107 else
4108 let lo = mid + 1
4109 if i_val == mid_val | break | endif
4110 endif
4111 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004112 endwhile
4113 " do insert
4114 if lo < i
Bram Moolenaar83bab712005-08-01 21:58:57 +00004115 exe 'keepjumps '.i.'d_'
4116 keepjumps call append(lo - 1, i_val)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004117 endif
4118 let i = i + 1
4119 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004120
Bram Moolenaar83bab712005-08-01 21:58:57 +00004121" " call Dret("NetSort")
4122 endfun
4123endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004124
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004125" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004126" SetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00004127" What this function does is to compute a priority for the patterns
4128" in the g:netrw_sort_sequence. It applies a substitute to any
4129" "files" that satisfy each pattern, putting the priority / in
4130" front. An "*" pattern handles the default priority.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004131fun! s:SetSort()
Bram Moolenaar488c6512005-08-11 20:09:58 +00004132" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004133 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00004134 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
4135 else
4136 let seqlist = g:netrw_sort_sequence
4137 endif
4138 " sanity check -- insure that * appears somewhere
4139 if seqlist == ""
4140 let seqlist= '*'
4141 elseif seqlist !~ '\*'
4142 let seqlist= seqlist.',*'
4143 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004144 let priority = 1
4145 while seqlist != ""
4146 if seqlist =~ ','
4147 let seq = substitute(seqlist,',.*$','','e')
4148 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
4149 else
4150 let seq = seqlist
4151 let seqlist = ""
4152 endif
4153 let eseq= escape(seq,'/')
4154 if priority < 10
4155 let spriority= "00".priority.'\/'
4156 elseif priority < 100
4157 let spriority= "0".priority.'\/'
4158 else
4159 let spriority= priority.'\/'
4160 endif
4161" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
4162
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004163 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00004164 if w:netrw_bannercnt > line("$")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004165 " apparently no files were left after a Hiding pattern was used
4166" call Dret("SetSort : no files left after hiding")
4167 return
4168 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004169 if seq == '*'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004170 exe 'silent keepjumps '.w:netrw_bannercnt.',$v/^\d\{3}\//s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004171 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004172 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/'.eseq.'/s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004173 endif
4174 let priority = priority + 1
4175 endwhile
4176
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00004177 " Following line associated with priority -- items that satisfy a priority
4178 " pattern get prefixed by ###/ which permits easy sorting by priority.
4179 " Sometimes files can satisfy multiple priority patterns -- only the latest
4180 " priority pattern needs to be retained. So, at this point, these excess
4181 " priority prefixes need to be removed, but not directories that happen to
4182 " be just digits themselves.
Bram Moolenaar8dff8182006-04-06 20:18:50 +00004183 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{3}\/\)\%(\d\{3}\/\)\+\ze./\1/e'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004184
4185" call Dret("SetSort")
4186endfun
4187
Bram Moolenaar488c6512005-08-11 20:09:58 +00004188" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004189" SaveWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00004190fun! s:SaveWinVars()
4191" call Dfunc("SaveWinVars()")
4192 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
4193 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
4194 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
4195 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
4196 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
4197 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
4198 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
4199 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004200 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00004201" call Dret("SaveWinVars")
4202endfun
4203
4204" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004205" CopyWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00004206fun! s:CopyWinVars()
4207" call Dfunc("CopyWinVars()")
4208 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
4209 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
4210 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
4211 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
4212 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
4213 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
4214 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
4215 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 +00004216 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 +00004217" call Dret("CopyWinVars")
4218endfun
4219
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004220" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004221" SetBufWinVars: (used by NetBrowse() and LocalBrowse()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004222" To allow separate windows to have their own activities, such as
4223" Explore **/pattern, several variables have been made window-oriented.
4224" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004225" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004226" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004227fun! s:SetBufWinVars()
4228" call Dfunc("SetBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004229 if exists("w:netrw_longlist") |let b:netrw_longlist = w:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004230 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
4231 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
4232 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
4233 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
4234 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen = w:netrw_explore_listlen|endif
4235 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = w:netrw_explore_mtchcnt|endif
4236 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
4237 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
4238 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004239" call Dret("SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004240endfun
4241
4242" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004243" UseBufWinVars: (used by NetBrowse() and LocalBrowse() {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004244" Matching function to BufferWinVars()
4245fun! s:UseBufWinVars()
4246" call Dfunc("UseBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004247 if exists("b:netrw_longlist") && !exists("w:netrw_longlist") |let w:netrw_longlist = b:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004248 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
4249 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
4250 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
4251 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
4252 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
4253 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
4254 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
4255 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
4256 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
4257" call Dret("UseBufWinVars")
4258endfun
4259
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004260" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004261" RFC2396: converts %xx into characters {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004262fun! netrw#RFC2396(fname)
4263" call Dfunc("RFC2396(fname<".a:fname.">)")
4264 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
4265" call Dret("RFC2396 ".fname)
4266 return fname
4267endfun
4268
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004269" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004270" Settings Restoration: {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00004271let &cpo= s:keepcpo
4272unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004273
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00004275" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00004276" vim:ts=8 fdm=marker