blob: 98f6c8b107eab47995ddd62da2c365bf57e7a5c5 [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 Moolenaar5a305422006-04-28 22:38:25 +00003" Date: Apr 28, 2006
4" Version: 95
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 Moolenaar5a305422006-04-28 22:38:25 +000026let g:loaded_netrw = "v95"
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
Bram Moolenaarf193fff2006-04-27 00:02:13 +0000145" call Decho(g:netrw_ssh_cmd." is not executable, can't do remote directory exploring")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000146 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 Moolenaar5a305422006-04-28 22:38:25 +0000325" call Decho("tmpfile<".tmpfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000326 let tmpfile= escape(substitute(tmpfile,'\','/','ge'),g:netrw_tmpfile_escape)
Bram Moolenaar5a305422006-04-28 22:38:25 +0000327" call Decho("tmpfile<".tmpfile.">")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000328 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000329 echohl Error | echo "***netrw*** your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!" | echohl None
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000330 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
331" call Dret("NetRead")
332 return
333 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000334" call Decho("tmpfile<".tmpfile.">")
335
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000336 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000337
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000338 " attempt to repeat with previous host-file-etc
339 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000340" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000341 let choice = b:netrw_lastfile
342 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000343
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000344 else
345 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000346" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000347
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000348 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000349 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000350 echomsg 'NetRead Usage:'
351 echomsg ':Nread machine:path uses rcp'
352 echomsg ':Nread "machine path" uses ftp with <.netrc>'
353 echomsg ':Nread "machine id password path" uses ftp'
354 echomsg ':Nread dav://machine[:port]/path uses cadaver'
355 echomsg ':Nread fetch://machine/path uses fetch'
356 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
357 echomsg ':Nread http://[user@]machine/path uses http wget'
358 echomsg ':Nread rcp://[user@]machine/path uses rcp'
359 echomsg ':Nread rsync://machine[:port]/path uses rsync'
360 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
361 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000362 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000363
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000364 elseif match(choice,"^\"") != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000365 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000366" call Decho("reconstructing choice")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000367 if match(choice,"\"$") != -1
368 " case "..."
369 let choice=strpart(choice,1,strlen(choice)-2)
370 else
371 " case "... ... ..."
372 let choice = strpart(choice,1,strlen(choice)-1)
373 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000374
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000375 while match(choice,"\"$") == -1
376 let wholechoice = wholechoice . " " . choice
377 let ichoice = ichoice + 1
378 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000379 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000380 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000381 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000382 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000383" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000384 return
385 endif
386 let choice= a:{ichoice}
387 endwhile
388 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
389 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390 endif
391 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000393" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000394 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000395
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000396 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000397 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000398 let choice = substitute(choice,'\\','/','ge')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000399" call Decho("fixing up windows url to <".choice."> tmpfile<".tmpfile)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000400
Bram Moolenaar57657d82006-04-21 22:12:41 +0000401 exe 'cd ' . fnamemodify(tmpfile,':h')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000402 let tmpfile = fnamemodify(tmpfile,':t')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000403 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000404
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000405 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000406 call s:NetMethod(choice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000407
Bram Moolenaar843ee412004-06-30 16:16:41 +0000408 " Check if NetBrowse() should be handling this request
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000409" call Decho("checking if NetBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000410 if choice =~ "^.*[\/]$"
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000411" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000412 keepjumps call s:NetBrowse(choice)
413" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000414 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000416
417 " use filename's suffix for the temporary file
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000418 if b:netrw_fname =~ '\.[^./]\+$'
419 let suffix = substitute(b:netrw_fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000420 let tmpfile= substitute(tmpfile,"$",suffix,'e')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000421" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000422 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000423
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000424 " ============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000425 " Perform Protocol-Based Read {{{3
426 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000427 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
428 echo "(netrw) Processing your read request..."
429 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000430
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000431 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000432 " rcp: NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000433 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000434" call Decho("read via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000435 " ER: noting done with g:netrw_uid yet?
436 " ER: on Win2K" rcp machine[.user]:file tmpfile
437 " ER: if machine contains '.' adding .user is required (use $USERNAME)
438 " ER: the tmpfile is full path: rcp sees C:\... as host C
439 if s:netrw_has_nt_rcp == 1
440 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
441 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
442 else
443 " Any way needed it machine contains a '.'
444 let uid_machine = g:netrw_machine .'.'. $USERNAME
445 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000447 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
448 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
449 else
450 let uid_machine = g:netrw_machine
451 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000453" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile)
454 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 +0000455 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
456 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000457
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000458 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000459 " ftp + <.netrc>: NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000460 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000461" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000462 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000463 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000464 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000465 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000466" call Decho("filter input: ".getline("."))
467 exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'"
468" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000469 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000470" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000471 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
472 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000473" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000474 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
475 endif
476 " 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 +0000477 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000478 let debugkeep= &debug
479 set debug=msg
Bram Moolenaar572cb562005-08-05 21:35:02 +0000480 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000481 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000482 let &debug= debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000483 endif
484 bd!
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000485 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000486 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000487
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000488 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000489 " ftp + machine,id,passwd,filename: NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000490 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
491 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000492" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000493 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000495 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000496 if exists("g:netrw_port") && g:netrw_port != ""
497 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000498" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000499 else
500 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000501" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000502 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000503
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000504 if exists("g:netrw_ftp") && g:netrw_ftp == 1
505 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000506" call Decho("filter input: ".getline("."))
507 put ='\"'.g:netrw_passwd.'\"'
508" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000509 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000510 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
511" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000512 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000513
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000514 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
515 put =g:netrw_ftpmode
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000516" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000517 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000518 put ='get \"'.netrw_fname.'\" '.tmpfile
519" call Decho("filter input: ".getline("."))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000520
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000521 " perform ftp:
522 " -i : turns off interactive prompting from ftp
523 " -n unix : DON'T use <.netrc>, even though it exists
524 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000525 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000526" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000527 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
528 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
529 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000530" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000531 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000532 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000533 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000534 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000535 endif
536 bd!
537 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
538 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000540 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000541 " scp: NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000542 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000543" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000544 if exists("g:netrw_port") && g:netrw_port != ""
545 let useport= " -P ".g:netrw_port
546 else
547 let useport= ""
548 endif
549 if g:netrw_cygwin == 1
550 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000551" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".cygtmpfile)
552 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 +0000553 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000554" call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".tmpfile)
555 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 +0000556 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000557 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000558 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000559
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000560 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000561 " http: NetRead Method #5 (wget) {{{3
562 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000563" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000564 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000565 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000566 echohl Error | echo "***netrw*** neither wget nor fetch command is available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000567 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000568 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000569" call Dret("NetRead")
570 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000571 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000572
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000573 if match(b:netrw_fname,"#") == -1
574 " simple wget
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000575 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
576" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname)
577 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000578 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000579
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000580 else
581 " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000582 let netrw_html= substitute(netrw_fname,"#.*$","","")
583 let netrw_tag = substitute(netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000584" call Decho("netrw_html<".netrw_html.">")
585" call Decho("netrw_tag <".netrw_tag.">")
586" call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000587 exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html
588 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000589" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000590 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
591 endif
592 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000593
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000594 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000595 " cadaver: NetRead Method #6 {{{3
596 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000597" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000598
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000599 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000600 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000601 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000602 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000603 if exists("g:netrw_port") && g:netrw_port != ""
604 put ='open '.g:netrw_machine.' '.g:netrw_port
605 else
606 put ='open '.g:netrw_machine
607 endif
608 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000609
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000610 if g:netrw_cygwin == 1
611 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
612 put ='get '.netrw_fname.' '.cygtmpfile
613 else
614 put ='get '.netrw_fname.' '.tmpfile
615 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000616 put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000617
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000618 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000619 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000620" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000621 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
622 bd!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000623 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000624 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000625
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000626 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000627 " rsync: NetRead Method #7 {{{3
628 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000629" call Decho("read via rsync (method #7)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000630 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000631 if g:netrw_cygwin == 1
632 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000633" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
634 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000635 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000636" call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile)
637 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000638 endif
639 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
640 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000641
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000642 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000643 " fetch: NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000644 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000645 elseif b:netrw_method == 8
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000646 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000647 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000648 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000649 echohl Error | echo "***netrw*** fetch command not available" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000650 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000651 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000652" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000653 endif
654 if exists("g:netrw_option") && g:netrw_option == ":http"
655 let netrw_option= "http"
656 else
657 let netrw_option= "ftp"
658 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000659" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000660
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000661 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000662" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname)
663 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 +0000664 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000665" call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname)
666 exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000667 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000668
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000669 let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method)
670 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000671
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000672 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000673 " sftp: NetRead Method #9 {{{3
674 elseif b:netrw_method == 9
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000675" call Decho("read via sftp (method #4)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000676 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000677 if g:netrw_cygwin == 1
678 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000679" call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
680" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile)
681 exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".cygtmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000682 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000683" call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile)
684 exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000685 endif
686 let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method)
687 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000688
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000689 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000690 " Complain {{{3
691 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000692 echo "***warning*** unable to comply with your request<" . choice . ">"
693 endif
694 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000695
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000696 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000697" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000698 if exists("b:netrw_method")
699 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000700 unlet b:netrw_fname
701 endif
702 call s:NetOptionRestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +0000703
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000704" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000705endfun
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000706
707" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000708" NetGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000709" readcmd == %r : replace buffer with newly read file
710" == 0r : read file at top of buffer
711" == r : read file after current line
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000712fun! s:NetGetFile(readcmd, tfile, method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000713" call Dfunc("NetGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000714
715 " get name of remote filename (ie. url and all)
716 let rfile= bufname("%")
717" call Decho("rfile<".rfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000718
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000719 if exists("*NetReadFixup")
720 " for the use of NetReadFixup (not otherwise used internally)
721 let line2= line("$")
722 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000723
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000724 " transform paths from / to \ for Windows (except for cygwin)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000725 if &term == "win32"
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000726 if g:netrw_cygwin
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000727 let tfile= a:tfile
728" call Decho("(win32 && cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000729 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000730 let tfile= substitute(a:tfile,'/','\\\\','ge')
731" call Decho("(win32 && !cygwin) tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000732 endif
733 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000734 let tfile= a:tfile
735" call Decho("tfile=a:tfile<".tfile.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000736 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000737
738 if a:readcmd[0] == '%'
Bram Moolenaar81695252004-12-29 20:58:21 +0000739 " get file into buffer
Bram Moolenaar83bab712005-08-01 21:58:57 +0000740
Bram Moolenaar83bab712005-08-01 21:58:57 +0000741" call Dredir("ls!","starting buffer list")
742
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000743 " rename the current buffer to the temp file (ie. tfile)
744 keepalt exe "file ".tfile
745" call Dredir("ls!","after renaming current buffer to <".tfile.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +0000746
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000747 " edit temporary file (ie. read the temporary file in)
748 if rfile =~ '\.zip$'
749 call zip#Browse(tfile)
750 elseif rfile =~ '\.tar$'
751 call tar#Browse(tfile)
752 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000753" call Decho("edit temporary file")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000754 e
755 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +0000756
Bram Moolenaar81695252004-12-29 20:58:21 +0000757 " rename buffer back to remote filename
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000758 keepalt exe "file ".escape(rfile,' ')
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000759 filetype detect
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000760" call Dredir("ls!","renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">")
Bram Moolenaar81695252004-12-29 20:58:21 +0000761 let line1 = 1
762 let line2 = line("$")
763
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000764 elseif filereadable(tfile)
Bram Moolenaar81695252004-12-29 20:58:21 +0000765 " read file after current line
766 let curline = line(".")
767 let lastline= line("$")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000768" call Decho("exe<".a:readcmd." ".v:cmdarg." ".tfile."> line#".curline)
769 exe a:readcmd." ".v:cmdarg." ".tfile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000770 let line1= curline + 1
771 let line2= line("$") - lastline + 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000773 else
Bram Moolenaar81695252004-12-29 20:58:21 +0000774 " not readable
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000775 echohl WarningMsg | echo "***netrw*** file <".tfile."> not readable"| echohl None
776 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
777" call Dret("NetGetFile : tfile<".tfile."> not readable")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000778 return
779 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000780
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000781 " User-provided (ie. optional) fix-it-up command
782 if exists("*NetReadFixup")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000783" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000784 call NetReadFixup(a:method, line1, line2)
Bram Moolenaar83bab712005-08-01 21:58:57 +0000785" else " Decho
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000786" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000787 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000788
789 " update the Buffers menu
790 if has("gui") && has("gui_running")
791 silent! emenu Buffers.Refresh\ menu
792 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000793
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000794" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".filereadable(a:tfile))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000795
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000796 " make sure file is being displayed
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000797 redraw!
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000798" call Dret("NetGetFile")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000799endfun
800
801" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000802" NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000803fun! netrw#NetWrite(...) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000804" call Dfunc("NetWrite(a:0=".a:0.")")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000805
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000806 " option handling
807 let mod= 0
808 call s:NetOptionSave()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000809
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000810 " Get Temporary Filename {{{3
Bram Moolenaar5a305422006-04-28 22:38:25 +0000811 let tmpfile= tempname()
812" call Decho("tmpfile<".tmpfile."> (raw)")
813 let tmpfile= escape(substitute(tmpfile,'\','/','ge'),g:netrw_tmpfile_escape)
814" call Decho("tmpfile<".tmpfile."> (escaped)")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000815 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaar5a305422006-04-28 22:38:25 +0000816 echohl Error | echo "***netrw*** your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000817 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000818" call Dret("NetWrite")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000819 return
820 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000821
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000822 if a:0 == 0
823 let ichoice = 0
824 else
825 let ichoice = 1
826 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000827
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000828 if &binary
829 " for binary writes, write entire file. Line numbers don't really make sense.
830 " Supports the writing of tar and zip files.
831" call Decho("silent exe w! ".v:cmdarg." ".tmpfile)
832 silent exe "w! ".v:cmdarg." ".tmpfile
833 else
834 " write (selected portion of) file to temporary
835" call Decho("silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile)
836 silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
837 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000838
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000839 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000840
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000841 " Process arguments: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000842 " attempt to repeat with previous host-file-etc
843 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000844" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000845 let choice = b:netrw_lastfile
846 let ichoice= ichoice + 1
847 else
848 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000849
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000850 " Reconstruct Choice if choice starts with '"'
851 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000852 echomsg 'NetWrite Usage:"'
853 echomsg ':Nwrite machine:path uses rcp'
854 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
855 echomsg ':Nwrite "machine id password path" uses ftp'
856 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
857 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
858 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
859 echomsg ':Nwrite rcp://machine/path uses rcp'
860 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
861 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
862 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000863 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000864
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000865 elseif match(choice,"^\"") != -1
866 if match(choice,"\"$") != -1
867 " case "..."
868 let choice=strpart(choice,1,strlen(choice)-2)
869 else
870 " case "... ... ..."
871 let choice = strpart(choice,1,strlen(choice)-1)
872 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000873
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000874 while match(choice,"\"$") == -1
875 let wholechoice= wholechoice . " " . choice
876 let ichoice = ichoice + 1
877 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000878 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000879 echohl Error | echo "***netrw*** Unbalanced string in filename '". wholechoice ."'" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000880 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000881 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000882" call Dret("NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000883 return
884 endif
885 let choice= a:{ichoice}
886 endwhile
887 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
888 endif
889 endif
890 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000891" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000892 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000893
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000894 " fix up windows urls
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000895 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000896 let choice= substitute(choice,'\\','/','ge')
897 "ER: see NetRead()
Bram Moolenaar57657d82006-04-21 22:12:41 +0000898 exe 'cd ' . fnamemodify(tmpfile,':h')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000899 let tmpfile = fnamemodify(tmpfile,':t')
900 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000901
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000902 " Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000903 call s:NetMethod(choice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000904
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000905 " =============
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000906 " Perform Protocol-Based Write {{{3
907 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000908 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
909 echo "(netrw) Processing your write request..."
910 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000911
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000912 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000913 " rcp: NetWrite Method #1 {{{3
914 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000915" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000916 if s:netrw_has_nt_rcp == 1
917 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
918 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
919 else
920 let uid_machine = g:netrw_machine .'.'. $USERNAME
921 endif
922 else
923 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
924 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
925 else
926 let uid_machine = g:netrw_machine
927 endif
928 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000929 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
930" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".netrw_fname)
931 exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000932 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000933
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000934 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000935 " ftp + <.netrc>: NetWrite Method #2 {{{3
936 elseif b:netrw_method == 2
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000937 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000938 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000939 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940 exe "put ='".g:netrw_ftpmode."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000941" call Decho(" filter input: ".getline("."))
942 exe "put ='"."put ".tmpfile.' \"'.netrw_fname.'\"'."'"
943" call Decho(" filter input: ".getline("."))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000945" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000946 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947 else
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000948" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000949 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 endif
951 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
952 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000953 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000954 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000955 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000956 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000957 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958 endif
959 bd!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000961
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000962 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000963 " ftp + machine, id, passwd, filename: NetWrite Method #3 {{{3
964 elseif b:netrw_method == 3
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000965 let netrw_fname= b:netrw_fname
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000966 new
Bram Moolenaar8299df92004-07-10 09:47:34 +0000967 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000968 if exists("g:netrw_port") && g:netrw_port != ""
969 put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000970" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000971 else
972 put ='open '.g:netrw_machine
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000973" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000974 endif
975 if exists("g:netrw_ftp") && g:netrw_ftp == 1
976 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000977" call Decho("filter input: ".getline("."))
978 put ='\"'.g:netrw_passwd.'\"'
979" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000980 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000981 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
982" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000983 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000984 put ='put '.tmpfile.' \"'.netrw_fname.'\"'
985" call Decho("filter input: ".getline("."))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000986 " save choice/id/password for future use
987 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000988
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000989 " perform ftp:
990 " -i : turns off interactive prompting from ftp
991 " -n unix : DON'T use <.netrc>, even though it exists
992 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000993 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000994" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000995 exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
996 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
997 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000998 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +0000999 echohl Error | echo "***netrw*** ".getline(1) | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001000 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001001 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001002 let mod=1
1003 endif
1004 bd!
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001005
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001006 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001007 " scp: NetWrite Method #4 {{{3
1008 elseif b:netrw_method == 4
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001009 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001010 if exists("g:netrw_port") && g:netrw_port != ""
1011 let useport= " -P ".g:netrw_port
1012 else
1013 let useport= ""
1014 endif
1015 if g:netrw_cygwin == 1
1016 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001017" call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".netrw_fname."'")
1018 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".cygtmpfile." '".g:netrw_machine.":".netrw_fname."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001019 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001020" call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".netrw_fname."'")
1021 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".tmpfile." '".g:netrw_machine.":".netrw_fname."'"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001022 endif
1023 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001024
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001025 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001026 " http: NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001027 elseif b:netrw_method == 5
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001028 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001029 echohl Error | echo "***netrw*** currently <netrw.vim> does not support writing using http:" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001030 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001031 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001032
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001033 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001034 " dav: NetWrite Method #6 (cadaver) {{{3
1035 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001036" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001037
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001038 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001039 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001040 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001041 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001042 if exists("g:netrw_port") && g:netrw_port != ""
1043 put ='open '.g:netrw_machine.' '.g:netrw_port
1044 else
1045 put ='open '.g:netrw_machine
1046 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 put ='user '.g:netrw_uid.' '.g:netrw_passwd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001048
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001049 if g:netrw_cygwin == 1
1050 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
1051 put ='put '.cygtmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001053 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001055
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001056 " perform cadaver operation:
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001057 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001058" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001059 exe g:netrw_silentxfer."%!".g:netrw_dav_cmd
1060 bd!
1061 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001062
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001063 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001064 " rsync: NetWrite Method #7 {{{3
1065 elseif b:netrw_method == 7
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001066 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001067 if g:netrw_cygwin == 1
1068 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001069" call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".netrw_fname)
1070 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001072" call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname)
1073 exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001075 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001077 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001078 " sftp: NetWrite Method #9 {{{3
1079 elseif b:netrw_method == 9
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001080 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1082 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1083 else
1084 let uid_machine = g:netrw_machine
1085 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001086 new
Bram Moolenaar8299df92004-07-10 09:47:34 +00001087 setlocal ff=unix
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001089 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001090" call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001091 exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine
1092 bd!
1093 let b:netrw_lastfile= choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001094
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001095 ".........................................
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001096 " Complain {{{3
1097 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001098 echo "***warning*** unable to comply with your request<" . choice . ">"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001100 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001101
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001102 " cleanup {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001103" call Decho("cleanup")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001104 let result=delete(tmpfile)
1105 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001107 if a:firstline == 1 && a:lastline == line("$")
1108 let &mod= mod " usually equivalent to set nomod
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001110
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001111" call Dret("NetWrite")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113
Bram Moolenaar83bab712005-08-01 21:58:57 +00001114" ===========================================
1115" Remote Directory Browsing Support: {{{1
1116" ===========================================
1117
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001118" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001119" NetBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001120" of the contents of a remote directory. It is assumed that the
1121" g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted
1122" with the requested remote hostname first.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001123fun! s:NetBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001124 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
1125" call Dfunc("NetBrowse(dirname<".a:dirname.">) longlist=".w:netrw_longlist)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001126
Bram Moolenaar488c6512005-08-11 20:09:58 +00001127 if exists("s:netrw_skipbrowse")
1128 unlet s:netrw_skipbrowse
1129" call Dret("NetBrowse")
1130 return
1131 endif
1132
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001133 call s:NetOptionSave()
1134
Bram Moolenaar843ee412004-06-30 16:16:41 +00001135 " sanity check
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001136 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
1137" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001138 if !executable("ftp")
1139 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001140 echohl Error | echo "***netrw*** this system doesn't support remote directory listing via ftp" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001141 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001142 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001143 call s:NetOptionRestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001144" call Dret("NetBrowse")
1145 return
1146 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001147 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001148 if !exists("g:netrw_quiet")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001149 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 +00001150 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001151 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001152
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001153 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001154" call Dret("NetBrowse")
1155 return
Bram Moolenaar843ee412004-06-30 16:16:41 +00001156 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001157
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001158 " use buffer-oriented WinVars if buffer ones exist but window ones don't
1159 call s:UseBufWinVars()
1160
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001161 " set up menus
1162 let b:netrw_browser_active= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001163 call s:NetMenu(1)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001164
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001165 " make this buffer modifiable
Bram Moolenaar83bab712005-08-01 21:58:57 +00001166 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001167
1168 " analyze a:dirname and g:netrw_list_cmd
1169 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001170 let dirname = substitute(a:dirname,'\\','/','ge')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001171" call Decho("dirname<".dirname.">")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001172 if dirname !~ dirpat
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001173 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001174 echohl Error | echo "***netrw*** netrw doesn't understand your dirname<".dirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001175 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001176 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001177 call s:NetOptionRestore()
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001178" call Dret("NetBrowse : badly formatted dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001179 return
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001180 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001181
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001182 let method = substitute(dirname,dirpat,'\1','')
1183 let user = substitute(dirname,dirpat,'\2','')
1184 let machine = substitute(dirname,dirpat,'\3','')
1185 let path = substitute(dirname,dirpat,'\4','')
1186 let fname = substitute(dirname,'^.*/\ze.','','')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001187" call Decho("set up method <".method .">")
1188" call Decho("set up user <".user .">")
1189" call Decho("set up machine<".machine.">")
1190" call Decho("set up path <".path .">")
1191" call Decho("set up fname <".fname .">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001192
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001193 if method == "ftp" || method == "http"
1194 let method = "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001195 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001196 else
1197 let listcmd = substitute(g:netrw_list_cmd,'\<HOSTNAME\>',user.machine,'')
1198 endif
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001199
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001200 if exists("b:netrw_method")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001201" call Decho("setting w:netrw_method<".b:netrw_method.">")
1202 let w:netrw_method= b:netrw_method
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001203 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001204
Bram Moolenaar8299df92004-07-10 09:47:34 +00001205 " optionally sort by time (-t) or by size (-S)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001206 if listcmd == "dir" && g:netrw_sort_by =~ "^[ts]"
Bram Moolenaar572cb562005-08-05 21:35:02 +00001207 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 +00001208 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001209 else
1210 if g:netrw_sort_by =~ "^t"
1211 let listcmd= listcmd."t"
1212 elseif g:netrw_sort_by =~ "^s"
1213 let listcmd= listcmd."S"
1214 endif
1215 " optionally sort in reverse
1216 if g:netrw_sort_direction =~ "^r" && listcmd == "dir"
1217 let listcmd= listcmd."r"
1218 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001219 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001220
1221" call Decho("set up listcmd<".listcmd.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001222 if fname =~ '@$' && fname !~ '^"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001223" call Decho("attempt transfer of symlink as file")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001224 call s:NetBrowse(substitute(dirname,'@$','','e'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001225 redraw!
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001226 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001227" call Dret("NetBrowse : symlink")
1228 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001229
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001230 elseif fname !~ '[\/]$' && fname !~ '^"'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001231 " looks like a regular file, attempt transfer
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001232" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001233
1234 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001235 " "this is a directory" indicator (/). There shouldn't be one of those,
1236 " anyway.
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001237 let path= substitute(path,'[*=@|]\r\=$','','e')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001238" call Decho("new path<".path.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001239
1240 " remote-read the requested file into current buffer
Bram Moolenaar57657d82006-04-21 22:12:41 +00001241 mark '
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001242 keepjumps keepalt enew!
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001243 set ma
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001244" call Decho("exe file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001245 exe "file ".method."://".user.machine."/".escape(path,s:netrw_cd_escape)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001246 exe "silent doau BufReadPre ".fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001247 silent call netrw#NetRead(2,method."://".user.machine."/".path)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001248 exe "silent doau BufReadPost ".fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001249
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001250 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001251 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001252 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001253 setlocal nomod nowrap
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001254
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001255" call Dret("NetBrowse : file<".fname.">")
1256 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001257 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001258
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001259 " ---------------------------------------------------------------------
1260 " Perform Directory Listing:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001261" call Decho("Perform directory listing...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001262 " set up new buffer and map
1263 let bufname = method.'://'.user.machine.'/'.path
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001264 let bufnamenr = bufnr(bufname.'$')
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001265" call Decho("bufname<".bufname."> bufnamenr=".bufnamenr)
Bram Moolenaar57657d82006-04-21 22:12:41 +00001266 mark '
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001267 if bufnamenr != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001268 " buffer already exists, switch to it!
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001269" call Decho("buffer already exists, switching to it")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001270 exe "b ".bufnamenr
1271 if line("$") >= 5
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001272 call s:NetOptionRestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001273" call Dret("NetBrowse")
1274 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001275 endif
1276 else
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001277" call Decho("generate a new buffer")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001278 keepjumps keepalt enew!
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001279 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001280
1281 " rename file to reflect where its from
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001282 setlocal bt=nofile bh=wipe nobl noswf
1283 exe "setlocal ts=".g:netrw_maxfilenamelen
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001284" call Decho("exe file ".escape(bufname,s:netrw_cd_escape))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001285 exe 'file '.escape(bufname,s:netrw_cd_escape)
Bram Moolenaar269ec652004-07-29 08:43:53 +00001286" call Decho("renaming file to bufname<".bufname.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001287 setlocal bt=nofile nobl nonu noswf
1288 if g:netrw_fastbrowse >= 1
1289 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001290 else
1291 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001292 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001293
1294 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001295 call s:NetBookmarkDir(3,expand("%"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001296
1297 " set up buffer-local mappings
1298" call Decho("set up buffer-local mappings")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001299 nnoremap <buffer> <silent> <cr> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001300 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>NetBrowseChgDir(expand("%"),'./'),0)<cr>
Bram Moolenaar843ee412004-06-30 16:16:41 +00001301 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),'../'))<cr>
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001302 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 +00001303 if w:netrw_longlist != 2
1304 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1305 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,expand("%"))<cr>
1306 endif
1307 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
1308 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(0,expand("%"))<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001309 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(0)<cr>
1310 nnoremap <buffer> <silent> i :call <SID>NetLongList(0)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001311 nnoremap <buffer> <silent> o :call <SID>NetSplit(0)<cr>
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001312 nnoremap <buffer> <silent> O :call netrw#NetObtain()<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001313 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(0)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001314 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,expand("%"))<cr>
1315 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>
1316 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>
1317 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001318 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
1319 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00001320 nnoremap <buffer> <silent> v :call <SID>NetSplit(1)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001321 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()),1)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001322 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>NetBrowse(<SID>NetBrowseChgDir(expand("%"),<SID>NetGetWord()))<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001323 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001324 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001325 exe 'nnoremap <buffer> <silent> d :call <SID>NetMakeDir("'.user.machine.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001326 exe 'nnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar843ee412004-06-30 16:16:41 +00001327 exe 'vnoremap <buffer> <silent> D :call <SID>NetBrowseRm("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001328 exe 'nnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00001329 exe 'vnoremap <buffer> <silent> R :call <SID>NetBrowseRename("'.user.machine.'","'.path.'")<cr>'
Bram Moolenaar433f7c82006-03-21 21:29:36 +00001330 nnoremap <buffer> <F1> :he netrw-browse-cmds<cr>
Bram Moolenaar83bab712005-08-01 21:58:57 +00001331 setlocal ma nonu nowrap
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001332
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001333 " Set up the banner
Bram Moolenaar57657d82006-04-21 22:12:41 +00001334" 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 +00001335 keepjumps put ='\" ==========================================================================='
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001336 keepjumps put ='\" Netrw Remote Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001337 keepjumps put ='\" '.bufname
Bram Moolenaar488c6512005-08-11 20:09:58 +00001338 let w:netrw_bannercnt = 7
1339 let sortby = g:netrw_sort_by
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001340 if g:netrw_sort_direction =~ "^r"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001341 let sortby = sortby." reversed"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001342 endif
1343
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001344 if g:netrw_sort_by =~ "^n"
1345 " sorted by name
Bram Moolenaar488c6512005-08-11 20:09:58 +00001346 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001347 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001348 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
1349 else
1350 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001351 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001352 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001353 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001354" call Decho("g:netrw_hide=".g:netrw_hide)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001355 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001356 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001357 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001358 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001359 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00001360 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar843ee412004-06-30 16:16:41 +00001361 endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001362 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 +00001363 keepjumps put ='\" ==========================================================================='
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001364
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001365 " remote read the requested directory listing
1366 " Use ftp if that was the file-transfer method selected, otherwise use ssh
1367 " Note that not all ftp servers honor the options for ls
1368 if method == "ftp"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001369 " use ftp to get remote file listing
1370" call Decho("use ftp to get remote file listing")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001371 call s:NetBrowseFtpCmd(path,listcmd)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001372 keepjumps 1d
1373
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001374 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001375 " shorten the listing
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001376" call Decho("generate short listing")
Bram Moolenaar488c6512005-08-11 20:09:58 +00001377 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001378
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001379 " cleanup
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001380 if g:netrw_ftp_browse_reject != ""
1381 exe "silent! g/".g:netrw_ftp_browse_reject."/keepjumps d"
1382 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001383 silent! keepjumps %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001384
1385 " if there's no ../ listed, then put ./ and ../ in
1386 let line1= line(".")
1387 keepjumps 1
1388 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1389 let line2= line(".")
1390 if line2 == 0
1391 keepjumps put='../'
1392 keepjumps put='./'
1393 endif
1394 exe "keepjumps ".line1
1395 keepjumps norm! 0
1396
1397 " more cleanup
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001398 exe 'silent! keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
1399 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
1400 exe "silent! keepjumps ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001401 endif
1402
1403 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001404 " use ssh to get remote file listing
1405" call Decho("use ssh to get remote file listing")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001406 let shq= &shq? &shq : ( &sxq? &sxq : "'")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001407" call Decho("exe silent r! ".listcmd." '".shq.escape(path,s:netrw_cd_escape).shq."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001408 exe "silent r! ".listcmd." ".shq.escape(path,s:netrw_cd_escape).shq
1409 keepjumps 1d
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001410 " cleanup
1411 if g:netrw_ftp_browse_reject != ""
1412 exe "silent! g/".g:netrw_ssh_browse_reject."/keepjumps d"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001413 endif
1414 endif
1415
1416 " set up syntax highlighting
1417 if has("syntax")
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001418 setlocal ft=netrw
Bram Moolenaar572cb562005-08-05 21:35:02 +00001419 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001420 setlocal ft=
Bram Moolenaar572cb562005-08-05 21:35:02 +00001421 " Ugly workaround -- when syntax highlighting is off and laststatus==2,
1422 " sometimes the laststatus highlight bleeds into the entire display.
1423 " Only seems to happen with remote browsing. Weird.
1424 redraw
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001425 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001426 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001427
1428 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001429 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00001430 if g:netrw_hide && g:netrw_list_hide != ""
1431 call s:NetrwListHide()
Bram Moolenaar843ee412004-06-30 16:16:41 +00001432 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001433
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001434 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00001435 " do a long listing; these substitutions need to be done prior to sorting
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001436" call Decho("manipulate long listing")
1437
1438 if method == "ftp"
1439 " cleanup
Bram Moolenaar488c6512005-08-11 20:09:58 +00001440 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar572cb562005-08-05 21:35:02 +00001441 while getline(".") =~ g:netrw_ftp_browse_reject
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001442 keepjumps d
1443 endwhile
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001444 " if there's no ../ listed, then put ./ and ../ in
1445 let line1= line(".")
1446 keepjumps 1
1447 silent keepjumps call search('^\.\.\/\%(\s\|$\)','W')
1448 let line2= line(".")
1449 if line2 == 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00001450 exe 'keepjumps '.w:netrw_bannercnt."put='./'"
1451 exe 'keepjumps '.w:netrw_bannercnt."put='../'"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001452 endif
1453 exe "keepjumps ".line1
1454 keepjumps norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001455 endif
1456
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001457 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/ -> .*$//e'
1458 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
1459 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar8299df92004-07-10 09:47:34 +00001460 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001461
Bram Moolenaar488c6512005-08-11 20:09:58 +00001462 if line("$") >= w:netrw_bannercnt
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001463 if g:netrw_sort_by =~ "^n"
1464 call s:SetSort()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001465 if g:netrw_sort_direction =~ 'n'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001466 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001467 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001468 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
Bram Moolenaar83bab712005-08-01 21:58:57 +00001469 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001470 " remove priority pattern prefix
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001471 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001472 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001473 if w:netrw_longlist == 1
1474 " shorten the list to keep its width <= winwidth characters
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001475 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\t[-dstrwx]\+/\t/e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001476 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00001477 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001478 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001479
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001480 call s:NetrwWideListing()
1481 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001482 " place cursor on the top-left corner of the file listing
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001483 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001484 norm! 0
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001485 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00001486
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001487 call s:NetOptionRestore()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001488 setlocal nomod noma nonu
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001489
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001490" call Dret("NetBrowse")
1491 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001492endfun
1493
1494" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001495" NetBrowseChgDir: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001496fun! s:NetBrowseChgDir(dirname,newdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001497" call Dfunc("NetBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001498
1499 let dirname= a:dirname
Bram Moolenaar843ee412004-06-30 16:16:41 +00001500 let newdir = a:newdir
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001501
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001502 if newdir !~ '[\/]$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001503 " handling a file
1504 let dirname= dirname.newdir
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001505 let didfile= 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001506 if g:netrw_browse_split == 1
1507 new
1508 wincmd _
1509 elseif g:netrw_browse_split == 2
1510 rightb vert new
1511 wincmd |
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001512 else
1513 " handling a file, didn't split, so possibly remove menu
1514 call s:NetMenu(0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001515 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001516" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001517
1518 elseif newdir == './'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001519 " refresh the directory list
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001520" call Decho("refresh directory listing")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001521 setlocal ma nobl
1522 if g:netrw_fastbrowse >= 1
1523 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001524 else
1525 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001526 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001527 %d
1528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001529 elseif newdir == '../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001530 " go up one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001531 let trailer= substitute(a:dirname,'^\(\w\+://\%(\w\+@\)\=\w\+/\)\(.*\)$','\2','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001533 if trailer =~ '^\%(\.\./\)*$'
1534 " tack on a ../"
1535 let dirname= dirname.'../'
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001536
1537 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001538 " strip off a directory name from dirname
1539 let dirname= substitute(dirname,'^\(.*/\)[^/]\+/','\1','')
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001540 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001541" call Decho("go up one dir: dirname<".dirname."> trailer<".trailer.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001542
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001543 else
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001544 " go down one directory
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001545 let dirname= dirname.newdir
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001546" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001547 endif
1548
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001549" call Dret("NetBrowseChgDir <".dirname.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001550 return dirname
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001551endfun
1552
Bram Moolenaar843ee412004-06-30 16:16:41 +00001553" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001554" NetGetWord: it gets the directory named under the cursor {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001555fun! s:NetGetWord()
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001556" call Dfunc("NetGetWord() line#".line(".")." longlist=".g:netrw_longlist." virtcol=".virtcol("."))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00001557 call s:UseBufWinVars()
1558
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001559 " insure that w:netrw_longlist is set up
1560 if !exists("w:netrw_longlist")
1561 if exists("g:netrw_longlist")
1562 let w:netrw_longlist= g:netrw_longlist
1563 else
1564 let w:netrw_longlist= 0
1565 endif
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001566" call Decho("w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001567 endif
1568
Bram Moolenaar488c6512005-08-11 20:09:58 +00001569 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001570 " Active Banner support
1571" call Decho("active banner handling")
1572 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001573 let dirname= "./"
Bram Moolenaar488c6512005-08-11 20:09:58 +00001574 let curline= getline(".")
1575 if curline =~ '"\s*Sorted by\s'
1576 norm s
1577 let s:netrw_skipbrowse= 1
1578 echo 'Pressing "s" also works'
1579 elseif curline =~ '"\s*Sort sequence:'
1580 let s:netrw_skipbrowse= 1
1581 echo 'Press "S" to edit sorting sequence'
1582 elseif curline =~ '"\s*Quick Help:'
1583 norm ?
1584 let s:netrw_skipbrowse= 1
1585 echo 'Pressing "?" also works'
1586 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
1587 norm a
1588 let s:netrw_skipbrowse= 1
1589 echo 'Pressing "a" also works'
1590 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001591 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00001592 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001593
1594 elseif w:netrw_longlist == 0
1595" call Decho("thin column handling")
1596 norm! 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001597 let dirname= getline(".")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001598
1599 elseif w:netrw_longlist == 1
1600" call Decho("long column handling")
1601 norm! 0
1602 let dirname= substitute(getline("."),'^\(\%(\S\+\s\)*\S\+\).\{-}$','\1','e')
1603
1604 else
1605" call Decho("obtain word from wide listing")
1606 let dirname= getline(".")
1607
1608 if !exists("b:netrw_cpf")
1609 let b:netrw_cpf= 0
1610 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
1611" call Decho("computed cpf")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001612 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001613
1614 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001615" 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 +00001616" call Decho("1: dirname<".dirname.">")
1617 if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif
1618" call Decho("2: dirname<".dirname.">")
1619 let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e')
1620" call Decho("3: dirname<".dirname.">")
1621 let dirname = substitute(dirname,'\s\+$','','e')
1622" call Decho("4: dirname<".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001623 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001624
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001625" call Dret("NetGetWord <".dirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001626 return dirname
1627endfun
1628
1629" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001630" NetBrowseRm: remove/delete a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001631fun! s:NetBrowseRm(usrhost,path) range
Bram Moolenaarc01140a2006-03-24 22:21:52 +00001632" call Dfunc("NetBrowseRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001633" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001634
1635 " preparation for removing multiple files/directories
1636 let ctr= a:firstline
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001637 let all= 0
Bram Moolenaar843ee412004-06-30 16:16:41 +00001638
1639 " remove multiple files and directories
1640 while ctr <= a:lastline
1641 exe ctr
1642
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001643 let rmfile= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001644" call Decho("rmfile<".rmfile.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001645
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001646 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar843ee412004-06-30 16:16:41 +00001647 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001648 if !all
1649 echohl Statement
1650 call inputsave()
1651 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1652 call inputrestore()
1653 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001654 if ok == ""
1655 let ok="no"
1656 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001657 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1658 if ok =~ 'a\%[ll]'
1659 let all= 1
1660 endif
1661 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001662
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001663 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001664 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001665 silent! keepjumps .,$d
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001666 call s:NetBrowseFtpCmd(a:path,"delete ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001667 else
1668 let netrw_rm_cmd= substitute(g:netrw_rm_cmd,'HOSTNAME',a:usrhost,'').' "'.escape(a:path.rmfile,s:netrw_cd_escape).'"'
1669" call Decho("attempt to remove file: system(".netrw_rm_cmd.")")
1670 let ret= system(netrw_rm_cmd)
1671" call Decho("returned=".ret." errcode=".v:shell_error)
1672 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001673 elseif ok =~ 'q\%[uit]'
1674 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001675 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001676
Bram Moolenaar843ee412004-06-30 16:16:41 +00001677 else
1678 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001679 if !all
1680 call inputsave()
1681 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
1682 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001683 if ok == ""
1684 let ok="no"
1685 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001686 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
1687 if ok =~ 'a\%[ll]'
1688 let all= 1
1689 endif
1690 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001691
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001692 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar488c6512005-08-11 20:09:58 +00001693 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001694 call s:NetBrowseFtpCmd(a:path,"rmdir ".rmfile)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001695 else
1696 let rmfile = a:path.rmfile
1697 let netrw_rmdir_cmd= substitute(g:netrw_rmdir_cmd,'HOSTNAME',a:usrhost,'').' '."'".'"'.rmfile.'"'."'"
1698" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
1699 let ret= system(netrw_rmdir_cmd)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001700" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001701
1702 if v:shell_error != 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001703 let netrw_rmf_cmd= substitute(g:netrw_rmf_cmd,'HOSTNAME',a:usrhost,'').' '.substitute(rmfile,'[\/]$','','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001704" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
1705 let ret= system(netrw_rmf_cmd)
1706" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001707
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001708 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00001709 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001710 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001711 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001712 endif
1713 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001714
1715 elseif ok =~ 'q\%[uit]'
1716 break
Bram Moolenaar843ee412004-06-30 16:16:41 +00001717 endif
1718 endif
1719
1720 let ctr= ctr + 1
1721 endwhile
1722
1723 " refresh the directory
1724 let curline= line(".")-1
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001725" call Decho("refresh the directory")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001726 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar843ee412004-06-30 16:16:41 +00001727 exe curline
1728
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001729" call Dret("NetBrowseRm")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001730endfun
1731
1732" ---------------------------------------------------------------------
1733" NetBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001734fun! s:NetBrowseRename(usrhost,path) range
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001735" call Dfunc("NetBrowseRename(usrhost<".a:usrhost."> path<".a:path.">)")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001736
1737 " preparation for removing multiple files/directories
1738 let ctr = a:firstline
1739 let rename_cmd = substitute(g:netrw_rename_cmd,'\<HOSTNAME\>',a:usrhost,'')
1740
1741 " attempt to rename files/directories
1742 while ctr <= a:lastline
Bram Moolenaar8299df92004-07-10 09:47:34 +00001743 exe "keepjumps ".ctr
Bram Moolenaar843ee412004-06-30 16:16:41 +00001744
1745 norm! 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001746 let oldname= s:NetGetWord()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001747" call Decho("oldname<".oldname.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001748
1749 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001750 let newname= input("Moving ".oldname." to : ",oldname)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001751 call inputrestore()
1752
Bram Moolenaar488c6512005-08-11 20:09:58 +00001753 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001754 call s:NetBrowseFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001755 else
1756 let oldname= a:path.oldname
1757 let newname= a:path.newname
1758" call Decho("system(rename_cmd".' "'.escape(oldname," ").'" "'.escape(newname,s:netrw_cd_escape).'"')
1759 let ret= system(rename_cmd.' "'.escape(oldname,s:netrw_cd_escape).'" "'.escape(newname,s:netrw_cd_escape).'"')
1760 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00001761
1762 let ctr= ctr + 1
1763 endwhile
1764
1765 " refresh the directory
1766 let curline= line(".")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001767 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001768 exe "keepjumps ".curline
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001769" call Dret("NetBrowseRename")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001770endfun
1771
1772" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00001773" NetRefresh: {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001774fun! s:NetRefresh(dirname,islocal)
1775" call Dfunc("NetRefresh(dirname<".a:dirname.">,islocal=".a:islocal.")")
1776 call netrw#NetSavePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001777 set ma
1778 %d
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001779 if a:islocal
1780 call s:LocalBrowse(a:dirname)
1781 else
1782 call s:NetBrowse(a:dirname)
1783 endif
1784 call netrw#NetRestorePosn()
Bram Moolenaar572cb562005-08-05 21:35:02 +00001785 redraw!
1786" call Dret("NetRefresh")
1787endfun
1788
1789" ---------------------------------------------------------------------
Bram Moolenaar488c6512005-08-11 20:09:58 +00001790" NetSplit: mode {{{2
1791" =0 : net and o
1792" =1 : net and v
1793" =2 : local and o
1794" =3 : local and v
1795fun! s:NetSplit(mode)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001796" call Dfunc("NetSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
Bram Moolenaar488c6512005-08-11 20:09:58 +00001797
1798 call s:SaveWinVars()
1799 if a:mode == 0
1800 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
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 ==1
1805 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1806 call s:CopyWinVars()
1807 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001808 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001809 elseif a:mode ==2
1810 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
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 else
1815 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
1816 call s:CopyWinVars()
1817 exe "norm! 0"
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001818 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,s:NetGetWord()))
Bram Moolenaar488c6512005-08-11 20:09:58 +00001819 endif
1820
1821" call Dret("NetSplit")
1822endfun
1823
1824" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00001825" NetBrowseX: allows users to write custom functions to operate on {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00001826" files given their extension. Passes 0=local, 1=remote
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001827fun! netrw#NetBrowseX(fname,remote)
1828" call Dfunc("NetBrowseX(fname<".a:fname."> remote=".a:remote.")")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001829
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001830 " set up the filename
1831 " (lower case the extension, make a local copy of a remote file)
Bram Moolenaar843ee412004-06-30 16:16:41 +00001832 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001833 if has("win32") || has("win95") || has("win64") || has("win16")
1834 let exten= substitute(exten,'^.*$','\L&\E','')
1835 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001836 let fname= escape(a:fname,"%#")
1837" call Decho("fname<".fname."> after escape()")
1838
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001839 " seems kde systems often have gnome-open due to dependencies, even though
1840 " gnome-open's subsidiary display tools are largely absent. Kde systems
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001841 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
1842 if !exists("s:haskdeinit")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001843 if has("unix")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001844 silent! let s:haskdeinit= system('ps -e') =~ 'kdeinit'
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001845 if v:shell_error
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001846 let s:haskdeinit = 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001847 endif
1848 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001849 let s:haskdeinit= 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001850 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001851" call Decho("setting s:haskdeinit=".s:haskdeinit)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001852 endif
1853
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001854 if a:remote == 1
1855 " create a local copy
1856 let fname= tempname().".".exten
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001857" call Decho("a:remote==1: create a local copy of <".a:fname."> as <".fname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001858 exe "silent keepjumps bot 1new ".a:fname
Bram Moolenaar572cb562005-08-05 21:35:02 +00001859 set bh=delete
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001860 exe "w! ".fname
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001861 q
1862 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001863" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
Bram Moolenaar8299df92004-07-10 09:47:34 +00001864
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001865 " set up redirection
1866 if &srr =~ "%s"
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00001867 let redir= substitute(&srr,"%s","/dev/null","")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001868 else
1869 let redir= &srr . "/dev/null"
1870 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001871" call Decho("redir{".redir."} srr{".&srr."}")
Bram Moolenaar8299df92004-07-10 09:47:34 +00001872
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001873 if exists("g:netrw_browsex_viewer") && executable(g:netrw_browsex_viewer)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001874" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001875 if g:netrw_browsex_viewer == '-'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001876 let ret= netrwFileHandlers#Invoke(exten,fname)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001877 else
1878" call Decho("exe silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."' ".redir)
1879 exe "silent !".g:netrw_browsex_viewer." '".escape(fname,'%#')."'".redir
1880 let ret= v:shell_error
1881 endif
1882
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001883 " execute the file handler
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001884 elseif has("win32") || has("win64")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001885" call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"')
1886 exe 'silent !start rundll32 url.dll,FileProtocolHandler "'.escape(fname, '%#').'"'
1887 let ret= v:shell_error
1888
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001889 elseif has("unix") && executable("gnome-open") && !s:haskdeinit
Bram Moolenaara5792f52005-11-23 21:25:05 +00001890" call Decho("exe silent !gnome-open '".escape(fname,'%#')."' ".redir)
1891 exe "silent !gnome-open '".escape(fname,'%#')."'".redir
1892 let ret= v:shell_error
1893
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001894 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001895" call Decho("exe silent !kfmclient exec '".escape(fname,'%#')."' ".redir)
1896 exe "silent !kfmclient exec '".escape(fname,'%#')."' ".redir
1897 let ret= v:shell_error
1898
1899 else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001900 " netrwFileHandlers#Invoke() always returns 0
1901 let ret= netrwFileHandlers#Invoke(exten,fname)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001902 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001903
1904 " if unsuccessful, attempt netrwFileHandlers#Invoke()
1905 if ret
1906 let ret= netrwFileHandlers#Invoke(exten,fname)
1907 endif
1908
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001909 redraw!
Bram Moolenaar8299df92004-07-10 09:47:34 +00001910
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001911 " cleanup: remove temporary file,
1912 " delete current buffer if success with handler,
1913 " return to prior buffer (directory listing)
1914 if a:remote == 1 && fname != a:fname
1915" call Decho("deleting temporary file<".fname.">")
1916 call delete(fname)
1917 endif
1918
1919 if a:remote == 1
Bram Moolenaar572cb562005-08-05 21:35:02 +00001920 set bh=delete bt=nofile noswf
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001921 exe "norm! \<c-o>"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001922 redraw!
Bram Moolenaar843ee412004-06-30 16:16:41 +00001923 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00001924
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001925" call Dret("NetBrowseX")
Bram Moolenaar843ee412004-06-30 16:16:41 +00001926endfun
1927
1928" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001929" NetBrowseFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
1930" This function assumes that a long listing will be received. Size, time,
1931" and reverse sorts will be requested of the server but not otherwise
1932" enforced here.
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001933fun! s:NetBrowseFtpCmd(path,listcmd)
1934" call Dfunc("NetBrowseFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001935
1936 " because WinXX ftp uses unix style input
1937 " curline is one more than the bannercnt in order to account
1938 " for the unwanted first blank line (doing a :put to an empty
1939 " buffer yields a blank first line)
1940 let ffkeep= &ff
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001941 setlocal ma ff=unix
Bram Moolenaar488c6512005-08-11 20:09:58 +00001942 let curline= w:netrw_bannercnt+1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001943 exe "silent! keepjumps ".curline.",$d"
1944
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001945 ".........................................
1946 if w:netrw_method == 2 || w:netrw_method == 5
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001947 " ftp + <.netrc>: Method #2
1948 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001949 put ='cd \"'.a:path.'\"'
1950" call Decho('ftp: '.getline("."))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001951 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001952 exe "put ='".a:listcmd."'"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001953" call Decho("ftp: ".getline("."))
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001954" redraw!|call inputsave()|call input("Pausing...")|call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001955 if exists("g:netrw_port") && g:netrw_port != ""
1956" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
1957 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
1958 else
1959" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
1960 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
1961 endif
1962
1963 ".........................................
Bram Moolenaar488c6512005-08-11 20:09:58 +00001964 elseif w:netrw_method == 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001965 " ftp + machine,id,passwd,filename: Method #3
1966 setlocal ff=unix
1967 if exists("g:netrw_port") && g:netrw_port != ""
1968 put ='open '.g:netrw_machine.' '.g:netrw_port
1969 else
1970 put ='open '.g:netrw_machine
1971 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001972
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001973 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1974 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001975 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001976 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001977 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001978 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001979
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001980 if a:path != ""
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001981 put ='cd \"'.a:path.'\"'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001982 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001983 exe "put ='".a:listcmd."'"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001984
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001985 " perform ftp:
1986 " -i : turns off interactive prompting from ftp
1987 " -n unix : DON'T use <.netrc>, even though it exists
1988 " -n win32: quit being obnoxious about password
1989" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
1990 exe g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n"
1991
1992 ".........................................
1993 else
1994 echo "***warning*** unable to comply with your request<" . choice . ">"
1995 endif
1996
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001997 " cleanup for Windows
1998 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001999 silent! keepjumps! %s/\r$//e
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002000 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002001 if a:listcmd == "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002002 " infer directory/link based on the file permission string
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002003 silent! keepjumps g/d\%([-r][-w][-x]\)\{3}/s@$@/@
2004 silent! keepjumps g/l\%([-r][-w][-x]\)\{3}/s/$/@/
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002005 if w:netrw_longlist == 0 || w:netrw_longlist == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002006 exe "silent! keepjumps ".curline.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002007 endif
2008 endif
2009
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002010 " ftp's ls doesn't seem to include ./ or ../
2011 if !search('^\.\/$','wn')
2012 exe 'keepjumps '.curline
2013 if a:path !~ '^$'
2014 put ='../'
2015 endif
2016 put ='./'
2017 exe 'keepjumps '.curline
2018 endif
2019
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002020 " restore settings
2021 let &ff= ffkeep
2022" call Dret("NetBrowseFtpCmd")
2023endfun
2024
2025" ---------------------------------------------------------------------
Bram Moolenaar843ee412004-06-30 16:16:41 +00002026" NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
2027" separated patterns given in g:netrw_list_hide
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002028fun! s:NetrwListHide()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002029" call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">")
Bram Moolenaar843ee412004-06-30 16:16:41 +00002030
Bram Moolenaar5a305422006-04-28 22:38:25 +00002031 " find a character not in the "hide" string to used as a separator
2032 " for :g and :v commands
Bram Moolenaar843ee412004-06-30 16:16:41 +00002033 let listhide= g:netrw_list_hide
Bram Moolenaar5a305422006-04-28 22:38:25 +00002034 let sep = strpart(substitute('~!@#$%^&*{};:,<.>/?|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
2035" call Decho("sep=".sep)
2036
Bram Moolenaar843ee412004-06-30 16:16:41 +00002037 while listhide != ""
2038 if listhide =~ ','
2039 let hide = substitute(listhide,',.*$','','e')
2040 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
2041 else
2042 let hide = listhide
2043 let listhide= ""
2044 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002045
2046 " Prune the list by hiding any files which match
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002047 if g:netrw_hide == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002048" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar5a305422006-04-28 22:38:25 +00002049 exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002050 elseif g:netrw_hide == 2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002051" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar5a305422006-04-28 22:38:25 +00002052 exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002053 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00002054 endwhile
Bram Moolenaar5a305422006-04-28 22:38:25 +00002055 if g:netrw_hide == 2
2056 exe 'silent keepjumps '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
2057 exe 'silent keepjumps '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
2058 endif
Bram Moolenaar843ee412004-06-30 16:16:41 +00002059
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002060" call Dret("NetrwListHide")
2061endfun
2062
2063" ---------------------------------------------------------------------
2064" NetHideEdit: allows user to edit the file/directory hiding list
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002065fun! s:NetHideEdit(islocal)
2066" call Dfunc("NetHideEdit(islocal=".a:islocal.")")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002067
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002068 " get new hiding list from user
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002069 call inputsave()
2070 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
2071 call inputrestore()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002072 let g:netrw_list_hide= newhide
2073" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002074
2075 " refresh the listing
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002076 if a:islocal == 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00002077 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2078 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002079 silent call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,"./"),a:islocal)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002080 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002081
2082" call Dret("NetHideEdit")
Bram Moolenaar843ee412004-06-30 16:16:41 +00002083endfun
2084
Bram Moolenaar8299df92004-07-10 09:47:34 +00002085" ---------------------------------------------------------------------
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002086" NetSortSequence: allows user to edit the sorting sequence
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002087fun! s:NetSortSequence(mode)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002088" call Dfunc("NetSortSequence(mode=".a:mode.")")
2089
2090 call inputsave()
2091 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
2092 call inputrestore()
2093
2094 " refresh the listing
2095 let g:netrw_sort_sequence= newsortseq
2096 if a:mode == 0
2097 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
2098 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002099 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002100 endif
2101
2102" call Dret("NetSortSequence")
2103endfun
2104
2105" ---------------------------------------------------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002106" NetLongList: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002107fun! s:NetLongList(mode)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002108" call Dfunc("NetLongList(mode=".a:mode.") netrw_longlist=".w:netrw_longlist)
2109 let fname = s:NetGetWord()
2110 let w:netrw_longlist = (w:netrw_longlist + 1) % 3
2111" call Decho("fname<".fname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002112
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002113 if w:netrw_longlist == 0
2114 " use one column listing
2115" call Decho("use one column list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002116 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2117
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002118 elseif w:netrw_longlist == 1
2119 " use long list
2120" call Decho("use long list")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002121 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002122
2123 else
2124 " give wide list
2125" call Decho("use wide list")
2126 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00002127 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002128 setlocal ma
Bram Moolenaar572cb562005-08-05 21:35:02 +00002129
2130 " clear buffer - this will cause NetBrowse/LocalBrowse to do a refresh
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002131 %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002132
2133 " refresh the listing
2134 if a:mode == 0
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002135 silent call s:NetBrowse(s:NetBrowseChgDir(expand("%"),"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002136 else
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002137 silent call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,"./"))
Bram Moolenaar8299df92004-07-10 09:47:34 +00002138 endif
2139
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002140 " keep cursor on the filename
2141 silent keepjumps $
2142 if fname =~ '/$'
2143 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2144 else
2145 silent call search('\%(^\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bW')
2146 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002147
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002148" call Dret("NetLongList : w:netrw_longlist=".w:netrw_longlist)
2149endfun
2150
2151" ---------------------------------------------------------------------
2152" NetrwWideListing: {{{2
2153fun! s:NetrwWideListing()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002154
2155 if w:netrw_longlist == 2
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002156" call Dfunc("NetrwWideListing() w:netrw_longlist=".w:netrw_longlist)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002157 " look for longest filename (cpf=characters per filename)
2158 " cpf: characters per file
2159 " fpl: files per line
2160 " fpc: files per column
2161 set ma
2162 let b:netrw_cpf= 0
2163 if line("$") >= w:netrw_bannercnt
2164 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 +00002165 else
2166" call Dret("NetrwWideListing")
2167 return
2168 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002169" call Decho("max file strlen+1=".b:netrw_cpf)
2170 let b:netrw_cpf= b:netrw_cpf + 1
2171
2172 " determine qty files per line (fpl)
2173 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002174 if w:netrw_fpl <= 0
2175 let w:netrw_fpl= 1
2176 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002177" call Decho("fpl= ".winwidth(0)."/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
2178
2179 " make wide display
Bram Moolenaar57657d82006-04-21 22:12:41 +00002180 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^.*$/\=printf("%-'.b:netrw_cpf.'s",escape(submatch(0),"\\"))/'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002181 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
2182 let newcolstart = w:netrw_bannercnt + fpc
2183 let newcolend = newcolstart + fpc - 1
2184" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
2185 while line("$") >= newcolstart
2186 if newcolend > line("$") | let newcolend= line("$") | endif
2187 let newcolqty= newcolend - newcolstart
2188 exe newcolstart
2189 if newcolqty == 0
2190 exe "silent keepjumps norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
2191 else
2192 exe "silent keepjumps norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
2193 endif
2194 exe "silent keepjumps ".newcolstart.','.newcolend.'d'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002195 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002196 endwhile
2197 exe "silent keepjumps ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002198 setlocal noma nomod
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002199" call Dret("NetrwWideListing")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002200 endif
2201
Bram Moolenaar8299df92004-07-10 09:47:34 +00002202endfun
2203
2204" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002205" NetSaveWordPosn: used by the "s" command in both remote and local {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002206" browsing. Along with NetRestoreWordPosn(), it keeps the cursor on
2207" the same word even though the sorting has changed its order of appearance.
2208fun! s:NetSaveWordPosn()
2209" call Dfunc("NetSaveWordPosn()")
2210 let s:netrw_saveword= '^'.escape(getline("."),s:netrw_cd_escape).'$'
2211" call Dret("NetSaveWordPosn : saveword<".s:netrw_saveword.">")
2212endfun
2213
2214" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002215" NetRestoreWordPosn: used by the "s" command; see NetSaveWordPosn() above {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002216fun! s:NetRestoreWordPosn()
2217" call Dfunc("NetRestoreWordPosn()")
2218 silent! call search(s:netrw_saveword,'w')
2219" call Dret("NetRestoreWordPosn")
2220endfun
2221
2222" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002223" NetMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002224fun! s:NetMakeDir(usrhost)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002225" call Dfunc("NetMakeDir(usrhost<".a:usrhost.">)")
2226
2227 " get name of new directory from user. A bare <CR> will skip.
2228 " if its currently a directory, also request will be skipped, but with
2229 " a message.
2230 call inputsave()
2231 let newdirname= input("Please give directory name: ")
2232 call inputrestore()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002233" call Decho("newdirname<".newdirname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002234
2235 if newdirname == ""
2236" call Dret("NetMakeDir : user aborted with bare <cr>")
2237 return
2238 endif
2239
2240 if a:usrhost == ""
2241
2242 " Local mkdir:
2243 " sanity checks
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002244 let fullnewdir= b:netrw_curdir.'/'.newdirname
2245" call Decho("fullnewdir<".fullnewdir.">")
2246 if isdirectory(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002247 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002248 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a directory!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002249 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002250 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002251" call Dret("NetMakeDir : directory<".newdirname."> exists previously")
2252 return
2253 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002254 if filereadable(fullnewdir)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002255 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002256 echohl WarningMsg | echo "***netrw*** <".newdirname."> is already a file!" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002257 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002258 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002259" call Dret("NetMakeDir : file<".newdirname."> exists previously")
2260 return
2261 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002262
2263 " requested new local directory is neither a pre-existing file or
2264 " directory, so make it!
2265 if exists("*mkdir")
2266 call mkdir(fullnewdir,"p")
2267 else
2268 let netrw_origdir= s:NetGetcwd(1)
Bram Moolenaar57657d82006-04-21 22:12:41 +00002269 exe 'keepjumps cd '.b:netrw_curdir
2270" call Decho("netrw_origdir<".netrw_origdir.">: cd b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002271" call Decho("exe silent! !".g:netrw_local_mkdir.' "'.newdirname.'"')
2272 exe "silent! !".g:netrw_local_mkdir.' "'.newdirname.'"'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002273 if !g:netrw_keepdir | exe 'keepjumps cd '.netrw_origdir | endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00002274 if !g:netrw_keepdir
2275 exe 'keepjumps cd '.netrw_origdir
2276" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".netrw_origdir)
2277 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002278 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002279
Bram Moolenaar8299df92004-07-10 09:47:34 +00002280 if v:shell_error == 0
2281 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002282" call Decho("refresh listing")
2283 let linenum= line(".")
2284 norm! H0
2285 let hline = line(".")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002286 set ma|norm! 2D
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002287 call s:LocalBrowse(s:LocalBrowseChgDir(b:netrw_curdir,'./'))
2288 exe "norm! ".hline."G0z\<CR>"
2289 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002290 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002291 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002292 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002293 endif
2294 redraw!
2295
2296 else
2297 " Remote mkdir:
2298 let mkdircmd = substitute(g:netrw_mkdir_cmd,'\<HOSTNAME\>',a:usrhost,'')
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002299 let newdirname= "'".'"'.substitute(expand("%"),'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname.'"'."'"
Bram Moolenaar8299df92004-07-10 09:47:34 +00002300" call Decho("exe silent! !".mkdircmd." ".newdirname)
2301 exe "silent! !".mkdircmd." ".newdirname
2302 if v:shell_error == 0
2303 " refresh listing
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002304 let linenum= line(".")
2305 norm! H0
2306 let hline = line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002307 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),'./'))
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002308 exe "norm! ".hline."G0z\<CR>"
2309 exe linenum
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002310 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002311 echohl Error | echo "***netrw*** unable to make directory<".newdirname.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002312 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00002313 endif
2314 redraw!
2315 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002316
Bram Moolenaar8299df92004-07-10 09:47:34 +00002317" call Dret("NetMakeDir")
2318endfun
2319
2320" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00002321" NetBookmarkDir: {{{2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002322" 0: (user: <b>) bookmark current directory
2323" 1: (user: <B>) change to the bookmarked directory
2324" 2: (user: <q>) list bookmarks
2325" 3: (LocalBrowse) record current directory history
2326" 4: (user: <u>) go up (previous) bookmark
2327" 5: (user: <U>) go down (next) bookmark
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002328fun! s:NetBookmarkDir(chg,curdir)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002329" call Dfunc("NetBookmarkDir(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002330 if exists("w:netrw_bannercnt") && line(".") <= w:netrw_bannercnt
2331 " looks like a "b" was pressed while in the banner region
2332 if line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002333 exe 'silent keepjumps '.w:netrw_bannercnt
Bram Moolenaar488c6512005-08-11 20:09:58 +00002334 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002335 if &ch > 1
2336 " "clear" the message
2337 echo ""
2338 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002339" call Dret("NetBookmarkDir - ignoring")
2340 return
2341 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002342
2343 if a:chg == 0
2344 " bookmark the current directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002345 let g:NETRW_BOOKMARKDIR_{v:count}= a:curdir
2346 if !exists("g:NETRW_BOOKMARKMAX")
2347 let g:NETRW_BOOKMARKMAX= v:count
2348 elseif v:count > g:NETRW_BOOKMARKMAX
2349 let g:NETRW_BOOKMARKMAX= v:count
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002350 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002351 echo "bookmarked the current directory"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002352
2353 elseif a:chg == 1
2354 " change to the bookmarked directory
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00002355 if exists("g:NETRW_BOOKMARKDIR_{v:count}")
2356 exe "e ".g:NETRW_BOOKMARKDIR_{v:count}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002357 else
2358 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2359 endif
2360
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002361 elseif a:chg == 2
Bram Moolenaar572cb562005-08-05 21:35:02 +00002362 " list user's bookmarks
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002363 if exists("g:NETRW_BOOKMARKMAX")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002364" call Decho("list bookmarks [0,".g:NETRW_BOOKMARKMAX."]")
2365 let cnt= 0
2366 while cnt <= g:NETRW_BOOKMARKMAX
2367 if exists("g:NETRW_BOOKMARKDIR_{cnt}")
2368" call Decho("Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt})
2369 echo "Netrw Bookmark#".cnt.": ".g:NETRW_BOOKMARKDIR_{cnt}
2370 endif
2371 let cnt= cnt + 1
2372 endwhile
2373 endif
2374
2375 " list directory history
2376 let cnt = g:NETRW_DIRHIST_CNT
2377 let first = 1
2378 let histcnt = 0
2379 while ( first || cnt != g:NETRW_DIRHIST_CNT )
2380" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:NETRW_DIRHIST_CNT)
2381 let histcnt= histcnt + 1
2382 if exists("g:NETRW_DIRHIST_{cnt}")
2383" call Decho("Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt})
2384 echo "Netrw History#".histcnt.": ".g:NETRW_DIRHIST_{cnt}
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002385 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002386 let first = 0
2387 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2388 if cnt < 0
2389 let cnt= cnt + g:netrw_dirhistmax
2390 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002391 endwhile
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002392
2393 elseif a:chg == 3
Bram Moolenaar572cb562005-08-05 21:35:02 +00002394 " saves most recently visited directories (when they differ)
2395 if !exists("g:NETRW_DIRHIST_0") || g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT} != a:curdir
2396 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2397 let g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}= substitute(a:curdir,'[/\\]$','','e')
2398" call Decho("save dirhist#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2399 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002400
2401 elseif a:chg == 4
2402 " u: change to the previous directory stored on the history list
2403 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2404 if g:NETRW_DIRHIST_CNT < 0
2405 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2406 endif
2407 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2408" call Decho("changedir u#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2409 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2410 else
2411 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2412 echo "Sorry, no predecessor directory exists yet"
2413 endif
2414
2415 elseif a:chg == 5
2416 " U: change to the subsequent directory stored on the history list
2417 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT + 1 ) % g:netrw_dirhistmax
2418 if exists("g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}")
2419" call Decho("changedir U#".g:NETRW_DIRHIST_CNT."<".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}.">")
2420 exe "e ".g:NETRW_DIRHIST_{g:NETRW_DIRHIST_CNT}
2421 else
2422 let g:NETRW_DIRHIST_CNT= ( g:NETRW_DIRHIST_CNT - 1 ) % g:netrw_dirhistmax
2423 if g:NETRW_DIRHIST_CNT < 0
2424 let g:NETRW_DIRHIST_CNT= g:NETRW_DIRHIST_CNT + g:netrw_dirhistmax
2425 endif
2426 echo "Sorry, no successor directory exists yet"
2427 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002428 endif
2429" call Dret("NetBookmarkDir")
2430endfun
2431
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002432" ---------------------------------------------------------------------
2433" NetObtain: obtain file under cursor (for remote browsing support) {{{2
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002434fun! netrw#NetObtain(...)
2435" call Dfunc("NetObtain() a:0=".a:0)
2436
2437 if a:0==0
2438 " no arguments -- use word under cursor
2439 let fname= expand("<cWORD>")
2440" call Decho("no arguments, use <".fname.">")
2441 elseif a:0 > 1
2442 " more than one argument, recurse with each argument separately
2443" call Decho("more than 1 argument, use recursion")
2444 let i=1
2445 while i <= a:0
2446 call netrw#NetObtain(a:{i})
2447 let i=i+1
2448 endwhile
2449 return
2450 else
2451 " one argument provided
2452 let fname = a:1
2453 let keep_netrw_choice = exists("b:netrw_choice")? b:netrw_choice : ""
2454 let keep_netrw_fname = exists("b:netrw_fname")? b:netrw_fname : ""
2455 let keep_netrw_wmethod = exists("w:netrw_method")? w:netrw_method : ""
2456 call s:NetMethod(fname)
2457 let w:netrw_method= b:netrw_method
2458 let fname = b:netrw_fname
2459" call Decho("g:netrw_scp_cmd<".g:netrw_scp_cmd.">")
2460" call Decho("g:netrw_machine<".g:netrw_machine.">")
2461" call Decho("fname<".fname.">")
2462 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002463
2464 " NetrwStatusLine support - for obtaining support
2465 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.fname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002466
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002467" call Decho("method=".w:netrw_method)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002468 if exists("w:netrw_method") && w:netrw_method =~ '[235]'
2469 if executable("ftp")
2470 let curdir = expand("%")
2471 let path = substitute(curdir,'ftp://[^/]\+/','','e')
2472 let curline= line(".")
2473 let endline= line("$")+1
2474 set ma
2475 keepjumps $
2476
2477 ".........................................
2478 if w:netrw_method == 2
2479 " ftp + <.netrc>: Method #2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002480 setlocal ff=unix
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002481 if path != ""
2482 put ='cd '.path
2483" call Decho("ftp: cd ".path)
2484 endif
2485 put ='get '.fname
2486" call Decho("ftp: get ".fname)
2487 if exists("g:netrw_port") && g:netrw_port != ""
2488" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port)
2489 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port
2490 else
2491" call Decho("exe ".g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine)
2492 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i ".g:netrw_machine
2493 endif
2494
2495 ".........................................
2496 elseif w:netrw_method == 3
2497 " ftp + machine,id,passwd,filename: Method #3
2498 setlocal ff=unix
2499 if exists("g:netrw_port") && g:netrw_port != ""
2500 put ='open '.g:netrw_machine.' '.g:netrw_port
2501" call Decho('ftp: open '.g:netrw_machine.' '.g:netrw_port)
2502 else
2503 put ='open '.g:netrw_machine
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504" call Decho('ftp: open '.g:netrw_machine)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002505 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002507 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2508 put =g:netrw_uid
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002509 put ='\"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002510" call Decho('ftp: g:netrw_uid')
2511" call Decho('ftp: g:netrw_passwd')
2512 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002513 put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002514" call Decho('user '.g:netrw_uid.' '.g:netrw_passwd)
2515 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002516
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002517 if a:path != ""
2518 put ='cd '.a:path
2519" call Decho('cd '.a:path)
2520 endif
2521 exe "put ='".a:cmd."'"
2522" call Decho("ftp: ".a:cmd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002523
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002524 " perform ftp:
2525 " -i : turns off interactive prompting from ftp
2526 " -n unix : DON'T use <.netrc>, even though it exists
2527 " -n win32: quit being obnoxious about password
2528" call Decho("exe ".g:netrw_silentxfer.curline.",$!".g:netrw_ftp_cmd." -i -n")
2529 exe g:netrw_silentxfer.endline.",$!".g:netrw_ftp_cmd." -i -n"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002530
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002531 ".........................................
2532 else
2533 echo "***warning*** unable to comply with your request<" . choice . ">"
2534 endif
2535 " restore
2536 exe "silent! ".endline.",$d"
2537 exe "keepjumps ".curline
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002538 setlocal noma nomod
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002539 else
2540 if !exists("g:netrw_quiet")
2541 echohl Error | echo "***netrw*** this system doesn't support ftp" | echohl None
2542 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2543 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002544 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002545 let &stl = s:netrw_users_stl
2546 let &laststatus = s:netrw_users_ls
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002547 " restore NetMethod
2548 if exists("keep_netrw_method")
2549 call s:NetMethod(keep_netrw_choice)
2550 let w:netrw_method = keep_netrw_wmethod
2551 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002552" call Dret("NetObtain")
2553 return
2554 endif
2555
2556 ".........................................
2557 else
2558 " scp: Method#4
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002559 let curdir = expand("%")
2560 let path = substitute(curdir,'scp://[^/]\+/','','e')
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561" call Decho("path<".path.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002562 if exists("g:netrw_port") && g:netrw_port != ""
2563 let useport= " -P ".g:netrw_port
2564 else
2565 let useport= ""
2566 endif
2567 if g:netrw_cygwin == 1
2568 let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2570 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002571 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002572" call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." .")
2573 exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".path.escape(fname,' ?&')." ."
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002574 endif
2575 endif
2576
2577 " restore status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002578 let &stl = s:netrw_users_stl
2579 let &laststatus = s:netrw_users_ls
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002580 redraw!
2581
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002582 " restore NetMethod
2583 if exists("keep_netrw_method")
2584 call s:NetMethod(keep_netrw_choice)
2585 let w:netrw_method = keep_netrw_wmethod
2586 endif
2587
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002588" call Dret("NetObtain")
2589endfun
2590
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002591" ---------------------------------------------------------------------
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002592" NetPrevWinOpen: open file/directory in previous window. {{{2
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002593" If there's only one window, then the window will first be split.
2594fun! s:NetPrevWinOpen(islocal)
2595" call Dfunc("NetPrevWinOpen(islocal=".a:islocal.")")
2596
2597 " get last window number and the word currently under the cursor
2598 let lastwinnr = winnr("$")
2599 let curword = s:NetGetWord()
2600 let curdir = b:netrw_curdir
2601" call Decho("lastwinnr=".lastwinnr." curword<".curword.">")
2602
2603 let didsplit = 0
2604 if lastwinnr == 1
2605 " if only one window, open a new one first
2606" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
2607 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
2608 let didsplit = 1
2609
2610 else
2611 wincmd p
2612 " if the previous window's buffer has been changed (is modified),
2613 " and it doesn't appear in any other extant window, then ask the
2614 " user if s/he wants to abandon modifications therein.
2615 let bnr = winbufnr(0)
2616 let bnrcnt = 0
2617 if &mod
2618 windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif
2619" call Decho("bnr=".bnr." bnrcnt=".bnrcnt)
2620 if bnrcnt == 1
2621 let bufname= bufname(winbufnr(winnr()))
2622 let choice= confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel")
2623
2624 if choice == 1
2625 " Yes -- write file & then browse
2626 let v:errmsg= ""
2627 silent w
2628 if v:errmsg != ""
2629 echohl Error | echo "***netrw*** "unable to write <".bufname.">!" | echohl None
2630 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2631 if didsplit
2632 q
2633 else
2634 wincmd p
2635 endif
2636" call Dret("NetPrevWinOpen : unable to write <".bufname.">")
2637 return
2638 endif
2639
2640 elseif choice == 2
2641 " No -- don't worry about changed file, just browse anyway
2642 set nomod
2643 echohl WarningMsg | echo "***netrw*** ".bufname." changes abandoned" | echohl None
2644
2645 else
2646 " Cancel -- don't do this
2647 if didsplit
2648 q
2649 else
2650 wincmd p
2651 endif
2652" call Dret("NetPrevWinOpen : cancelled")
2653 return
2654 endif
2655 endif
2656 endif
2657 endif
2658
2659 if a:islocal
2660 call s:LocalBrowse(s:LocalBrowseChgDir(curdir,curword))
2661 else
2662 call s:NetBrowse(s:NetBrowseChgDir(expand("%"),curword))
2663 endif
2664" call Dret("NetPrevWinOpen")
2665endfun
2666
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002667" ---------------------------------------------------------------------
2668" NetMenu: generates the menu for gvim and netrw {{{2
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002669fun! s:NetMenu(domenu)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002670
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002671 if !exists("g:NetrwMenuPriority")
2672 let g:NetrwMenuPriority= 80
2673 endif
2674
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002675 if has("menu") && has("gui_running") && &go =~ 'm'
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002676" call Dfunc("NetMenu(domenu=".a:domenu.")")
2677 if !exists("s:netrw_menu_enabled") && a:domenu
2678" call Decho("initialize menu")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002679 let s:netrw_menu_enabled= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002680 if !exists("g:NetrwTopLvlMenu")
2681 let g:NetrwTopLvlMenu= "Netrw."
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002682 endif
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00002683 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
2684 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
2685 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory<tab>b Nb'
2686 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
2687 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory<tab>B NB'
2688 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory<tab>u u'
2689 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory<tab>U U'
2690 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
2691 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List<tab>'."<ctrl-h> \<c-h>"
2692 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory<tab><cr> '."\<cr>"
2693 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window<tab>o o'
2694 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window<tab>v v'
2695 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History<tab>q q'
2696 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)<tab>i i'
2697 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
2698 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Normal-Hide-Show<tab>a a'
2699 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
2700 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Preview\ File/Directory<tab>p p'
2701 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser<tab>P P'
2702 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
2703 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
2704 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order<tab>'."r r"
2705 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style<tab>s s'
2706 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit<tab>S S'
2707 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
2708 exe 'silent! '.g:NetrwMenuPriority.'menu '.g:NetrwTopLvlMenu.'Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002709 elseif !a:domenu
2710 let s:netrwcnt = 0
2711 let curwin = winnr()
2712 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
2713 exe curwin."wincmd w"
2714
2715 if s:netrwcnt <= 1
2716" call Decho("clear menus")
2717 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Help'
2718 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer'
2719 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Bookmark\ Current\ Directory'
2720 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Go\ Up\ Directory'
2721 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Goto\ Bookmarked\ Directory'
2722 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Recently\ Used\ Directory'
2723 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Change\ To\ Subsequently\ Used\ Directory'
2724 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Delete\ File/Directory'
2725 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory'
2726 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Window'
2727 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File/Directory,\ New\ Vertical\ Window'
2728 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File\ Hiding\ List'
2729 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Edit\ File'
2730 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory'
2731 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Enter\ File/Directory\ (vertical\ split)'
2732 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'List\ Bookmarks\ and\ History'
2733 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Listing\ Style\ (thin-long-wide)'
2734 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Make\ Subdirectory'
2735 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Normal-Hide-Show'
2736 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Obtain\ File'
2737 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Preview\ File/Directory'
2738 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Previous\ Window\ Browser'
2739 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Refresh\ Listing'
2740 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Rename\ File/Directory'
2741 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Reverse\ Sorting\ Order'
2742 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Select\ Sorting\ Style'
2743 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Sorting\ Sequence\ Edit'
2744 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Set\ Current\ Directory'
2745 exe 'silent! unmenu '.g:NetrwTopLvlMenu.'Settings/Options'
2746 unlet s:netrw_menu_enabled
2747 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002748 endif
2749" call Dret("NetMenu")
2750 endif
2751
2752endfun
2753
Bram Moolenaar83bab712005-08-01 21:58:57 +00002754" ==========================================
2755" Local Directory Browsing Support: {{{1
2756" ==========================================
Bram Moolenaar8299df92004-07-10 09:47:34 +00002757
2758" ---------------------------------------------------------------------
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002759" LocalBrowse: {{{2
2760fun! s:LocalBrowse(dirname)
2761 " unfortunate interaction -- debugging calls can't be used here;
2762 " the BufEnter event causes triggering when attempts to write to
2763 " the DBG buffer are made.
2764 if isdirectory(a:dirname)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002765 silent! call netrw#DirBrowse(a:dirname)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002766 endif
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002767 " not a directory, ignore it
2768endfun
Bram Moolenaar8299df92004-07-10 09:47:34 +00002769
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002770" ---------------------------------------------------------------------
2771" DirBrowse: supports local file/directory browsing {{{2
2772fun! netrw#DirBrowse(dirname)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002773 if !exists("w:netrw_longlist")|let w:netrw_longlist= g:netrw_longlist|endif
Bram Moolenaar5a305422006-04-28 22:38:25 +00002774" call Dfunc("DirBrowse(dirname<".a:dirname.">) buf#".bufnr("%")." winnr=".winnr()." sortby=".g:netrw_sort_by." hide=".g:netrw_hide)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002775" call Dredir("ls!")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002776
Bram Moolenaar488c6512005-08-11 20:09:58 +00002777 if exists("s:netrw_skipbrowse")
2778 unlet s:netrw_skipbrowse
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002779" call Dret("DirBrowse")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002780 return
2781 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002782 if &fo =~ '[ta]'
2783 set fo-=t
2784 set fo-=a
2785 echohl Warning
2786 echo '***warning*** directory browsing and formatoptions "ta" are incompatible'
2787 echohl None
2788 endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002789
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002790 call s:NetOptionSave()
Bram Moolenaar57657d82006-04-21 22:12:41 +00002791 if w:acdkeep
2792 exe 'cd '.escape(a:dirname,s:netrw_cd_escape)
2793" call Decho("cd ".escape(a:dirname,s:netrw_cd_escape))
2794" call Decho("getcwd<".getcwd().">")
2795 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002796
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002797 if v:version < 603
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002798 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002799 echohl Error | echo "***netrw*** vim version<".v:version."> too old for browsing with netrw" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002800 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002801 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002802 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002803" call Dret("DirBrowse : vim version<".v:version."> too old")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002804 return
2805 endif
2806
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00002807 " use buffer-oriented WinVars if buffer ones exist but window ones don't
2808 call s:UseBufWinVars()
2809
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002810 " set up menus
2811 let b:netrw_browser_active= 1
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002812 call s:NetMenu(1)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002813
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002814 " find buffer number of buffer named precisely the same as a:dirname
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002815 let bufnum= bufnr(escape(a:dirname,'\'))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002816" call Decho("findbuf: bufnum=".bufnum)
2817 if bufnum > 0 && bufname(bufnum) != a:dirname
2818 let ibuf= 1
2819 let buflast= bufnr("$")
2820 while bufname(ibuf) !~ '^'.a:dirname.'\=$' && ibuf <= buflast
2821" call Decho("findbuf: ibuf=".ibuf. " bufname<".bufname(ibuf)."> dirname<".a:dirname.">")
2822 let ibuf= ibuf + 1
2823 endwhile
2824 if ibuf > buflast
2825 let bufnum= -1
2826 else
2827 let bufnum= ibuf
2828 endif
2829" call Decho("findbuf: bufnum=".bufnum." (final)")
2830 endif
2831
2832 " get cleared buffer
Bram Moolenaar57657d82006-04-21 22:12:41 +00002833 mark '
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002834 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002835 keepjumps keepalt enew!
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002836" call Decho("enew buffer")
2837 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002838 exe "keepalt b ".bufnum
Bram Moolenaar572cb562005-08-05 21:35:02 +00002839 if exists("s:last_sort_by") && g:netrw_sort_by == s:last_sort_by
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002840 if getline(2) =~ '^" Netrw Directory Listing '
Bram Moolenaar572cb562005-08-05 21:35:02 +00002841 if !g:netrw_keepdir
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002842 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar57657d82006-04-21 22:12:41 +00002843" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar572cb562005-08-05 21:35:02 +00002844 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002845 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002846" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar572cb562005-08-05 21:35:02 +00002847 return
2848 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002849 endif
2850 endif
Bram Moolenaar572cb562005-08-05 21:35:02 +00002851 let s:last_sort_by= g:netrw_sort_by
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002852
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00002853 " set up ShellCmdPost handling. Append current buffer to browselist
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00002854 call s:LocalFastBrowser()
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00002855
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002856 " get the new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002857 if has("win32") || has("win95") || has("win64") || has("win16")
2858 let b:netrw_curdir= substitute(a:dirname,'\\','/','ge')
2859 else
2860 let b:netrw_curdir= a:dirname
2861 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002862 if b:netrw_curdir =~ '[/\\]$'
2863 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2864 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002865 if b:netrw_curdir == ''
2866 " under unix, when the root directory is encountered, the result
2867 " from the preceding substitute is an empty string.
2868 let b:netrw_curdir= '/'
2869 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00002870" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002871
Bram Moolenaar83bab712005-08-01 21:58:57 +00002872 " make netrw's idea of the current directory vim's if the user wishes
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002873 if !g:netrw_keepdir
Bram Moolenaar57657d82006-04-21 22:12:41 +00002874" call Decho("netrw_keepdir=".g:netrw_keepdir.": cd ".escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar488c6512005-08-11 20:09:58 +00002875 try
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002876 exe 'cd '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar488c6512005-08-11 20:09:58 +00002877 catch /^Vim\%((\a\+)\)\=:E472/
2878 echohl Error | echo "***netrw*** unable to change directory to <".b:netrw_curdir."> (permissions?)" | echohl None
2879 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2880 if exists("w:netrw_prvdir")
2881 let b:netrw_curdir= w:netrw_prvdir
2882 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002883 call s:NetOptionRestore()
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002884" call Dret("DirBrowse : reusing buffer#".bufnum."<".a:dirname.">")
Bram Moolenaar488c6512005-08-11 20:09:58 +00002885 return
2886 endif
2887 endtry
Bram Moolenaar83bab712005-08-01 21:58:57 +00002888 endif
2889
2890 " change the name of the buffer to reflect the b:netrw_curdir
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002891 " Hmm. When another vim is open to the same directory, I get
2892 " a "Press ENTER" ... ok, setting "noswf" avoids it.
2893" call Decho('exe silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape))
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00002894 exe 'silent! file '.escape(b:netrw_curdir,s:netrw_cd_escape)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002895
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00002896 " make this buffer not-a-file, modifiable, not line-numbered, etc
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002897 setlocal bt=nofile nobl ma nonu noswf nowrap
2898 if g:netrw_fastbrowse >= 2
2899 setlocal bh=hide
Bram Moolenaarc01140a2006-03-24 22:21:52 +00002900 else
2901 setlocal bh=delete
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002902 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002903 keepalt silent! %d
Bram Moolenaar8299df92004-07-10 09:47:34 +00002904
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002905 " ---------------------------
Bram Moolenaar8299df92004-07-10 09:47:34 +00002906 " Perform Directory Listing:
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002907 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2908 echo "(netrw) Processing your browsing request..."
2909 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00002910
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002911 " save current directory on directory history list
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002912 call s:NetBookmarkDir(3,b:netrw_curdir)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002913
Bram Moolenaar8299df92004-07-10 09:47:34 +00002914 " set up all the maps
Bram Moolenaar269ec652004-07-29 08:43:53 +00002915" call Decho("Setting up local browser maps")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002916 nnoremap <buffer> <silent> <cr> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002917 nnoremap <buffer> <silent> <c-l> :call <SID>NetRefresh(<SID>LocalBrowseChgDir(b:netrw_curdir,'./'),1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002918 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,'../'))<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002919 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 +00002920 if w:netrw_longlist != 2
2921 nnoremap <buffer> <silent> b :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2922 nnoremap <buffer> <silent> B :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
2923 endif
2924 nnoremap <buffer> <silent> Nb :<c-u>call <SID>NetBookmarkDir(0,b:netrw_curdir)<cr>
2925 nnoremap <buffer> <silent> NB :<c-u>call <SID>NetBookmarkDir(1,b:netrw_curdir)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002926 nnoremap <buffer> <silent> c :exe "cd ".b:netrw_curdir<cr>
2927 nnoremap <buffer> <silent> d :call <SID>NetMakeDir("")<cr>
2928 nnoremap <buffer> <silent> <c-h> :call <SID>NetHideEdit(1)<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002929 nnoremap <buffer> <silent> i :call <SID>NetLongList(1)<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002930 nnoremap <buffer> <silent> o :call <SID>NetSplit(2)<cr>
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002931 nnoremap <buffer> <silent> O :call <SID>LocalObtain()<cr>
2932 nnoremap <buffer> <silent> p :call <SID>LocalPreview(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),1))<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002933 nnoremap <buffer> <silent> P :call <SID>NetPrevWinOpen(1)<cr>
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002934 nnoremap <buffer> <silent> q :<c-u>call <SID>NetBookmarkDir(2,b:netrw_curdir)<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002935 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 +00002936 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>
2937 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002938 nnoremap <buffer> <silent> u :<c-u>call <SID>NetBookmarkDir(4,expand("%"))<cr>
2939 nnoremap <buffer> <silent> U :<c-u>call <SID>NetBookmarkDir(5,expand("%"))<cr>
Bram Moolenaar488c6512005-08-11 20:09:58 +00002940 nnoremap <buffer> <silent> v :call <SID>NetSplit(3)<cr>
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002941 nnoremap <buffer> <silent> x :call netrw#NetBrowseX(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord(),0),0)"<cr>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002942 nnoremap <buffer> <silent> <2-leftmouse> :call <SID>LocalBrowse(<SID>LocalBrowseChgDir(b:netrw_curdir,<SID>NetGetWord()))<cr>
Bram Moolenaar57657d82006-04-21 22:12:41 +00002943 if s:didstarstar || !mapcheck("<s-down>","n")
2944 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
2945 endif
2946 if s:didstarstar || !mapcheck("<s-up>","n")
2947 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
2948 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949 exe 'nnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002950 exe 'vnoremap <buffer> <silent> <del> :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951 exe 'nnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002952 exe 'vnoremap <buffer> <silent> D :call <SID>LocalBrowseRm("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002953 exe 'nnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002954 exe 'vnoremap <buffer> <silent> R :call <SID>LocalBrowseRename("'.b:netrw_curdir.'")<cr>'
Bram Moolenaar269ec652004-07-29 08:43:53 +00002955 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetMakeDir("")<cr>'
Bram Moolenaar433f7c82006-03-21 21:29:36 +00002956 nnoremap <buffer> <F1> :he netrw-dir<cr>
Bram Moolenaar8299df92004-07-10 09:47:34 +00002957
2958 " Set up the banner
Bram Moolenaar269ec652004-07-29 08:43:53 +00002959" call Decho("set up banner")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002960 keepjumps put ='\" ============================================================================'
Bram Moolenaar8299df92004-07-10 09:47:34 +00002961 keepjumps 1d
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002962 keepjumps put ='\" Netrw Directory Listing (netrw '.g:loaded_netrw.')'
Bram Moolenaar83bab712005-08-01 21:58:57 +00002963 keepjumps put ='\" '.b:netrw_curdir
Bram Moolenaar488c6512005-08-11 20:09:58 +00002964 let w:netrw_bannercnt= 3
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002965
2966 let sortby= g:netrw_sort_by
2967 if g:netrw_sort_direction =~ "^r"
2968 let sortby= sortby." reversed"
2969 endif
Bram Moolenaar269ec652004-07-29 08:43:53 +00002970
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002971 " Sorted by...
Bram Moolenaar8299df92004-07-10 09:47:34 +00002972 if g:netrw_sort_by =~ "^n"
Bram Moolenaar269ec652004-07-29 08:43:53 +00002973" call Decho("directories will be sorted by name")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002974 " sorted by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002975 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar8299df92004-07-10 09:47:34 +00002976 keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar488c6512005-08-11 20:09:58 +00002977 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8299df92004-07-10 09:47:34 +00002978 else
Bram Moolenaar269ec652004-07-29 08:43:53 +00002979" call Decho("directories will be sorted by size or date")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002980 " sorted by size or date
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002981 keepjumps put ='\" Sorted by '.sortby
Bram Moolenaar488c6512005-08-11 20:09:58 +00002982 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002983 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002984
2985 " Hiding... -or- Showing...
Bram Moolenaar269ec652004-07-29 08:43:53 +00002986 if g:netrw_list_hide != "" && g:netrw_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002987 if g:netrw_hide == 1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002988 keepjumps put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002989 else
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002990 keepjumps put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002991 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00002992 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00002993 endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +00002994 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 +00002995 keepjumps put ='\" ============================================================================'
Bram Moolenaar488c6512005-08-11 20:09:58 +00002996 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002997
2998 " bannercnt should index the line just after the banner
Bram Moolenaar488c6512005-08-11 20:09:58 +00002999 let w:netrw_bannercnt= w:netrw_bannercnt + 1
3000" call Decho("bannercnt=".w:netrw_bannercnt)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003001
3002 " generate the requested directory listing
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003003 call s:LocalBrowseList()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003004
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003005 " set up syntax highlighting
3006 if has("syntax")
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00003007 setlocal ft=netrw
Bram Moolenaar572cb562005-08-05 21:35:02 +00003008 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003009 setlocal ft=
3010 endif
3011 endif
3012
Bram Moolenaar8299df92004-07-10 09:47:34 +00003013 " manipulate the directory listing (hide, sort)
Bram Moolenaar488c6512005-08-11 20:09:58 +00003014 if line("$") >= w:netrw_bannercnt
Bram Moolenaar269ec652004-07-29 08:43:53 +00003015 if g:netrw_hide && g:netrw_list_hide != ""
3016 call s:NetrwListHide()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003017 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003018 if line("$") >= w:netrw_bannercnt
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003019
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003020 if g:netrw_sort_by =~ "^n"
3021 call s:SetSort()
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003022
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003023 if w:netrw_bannercnt < line("$")
3024 if g:netrw_sort_direction =~ 'n'
3025 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
3026 else
3027 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
3028 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003029 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003030 " remove priority pattern prefix
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003031 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e'
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003032
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003033 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003034 if w:netrw_bannercnt < line("$")
3035 if g:netrw_sort_direction =~ 'n'
3036 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort'
3037 else
3038 exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!'
3039 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003040 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003041 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003042 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003043
Bram Moolenaar8299df92004-07-10 09:47:34 +00003044 endif
3045 endif
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003046
3047 call s:NetrwWideListing()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003048 if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003049 " place cursor on the top-left corner of the file listing
3050 exe 'silent '.w:netrw_bannercnt
3051 norm! 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003052 endif
3053
3054 " record previous current directory
3055 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaar8299df92004-07-10 09:47:34 +00003056
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00003057 " save certain window-oriented variables into buffer-oriented variables
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003058 call s:SetBufWinVars()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003059 call s:NetOptionRestore()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003060 setlocal noma nomod nonu nobl nowrap
3061 if g:netrw_fastbrowse >= 2
3062 setlocal bh=hide
3063 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003064
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003065" call Dret("DirBrowse : file<".expand("%:p")."> bufname<".bufname("%").">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003066endfun
3067
3068" ---------------------------------------------------------------------
3069" LocalBrowseList: does the job of "ls" for local directories {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003070fun! s:LocalBrowseList()
Bram Moolenaar57657d82006-04-21 22:12:41 +00003071" call Dfunc("LocalBrowseList() b:netrw_curdir<".b:netrw_curdir."> sortby<".g:netrw_sort_by.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003072
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003073 " get the list of files contained in the current directory
Bram Moolenaar83bab712005-08-01 21:58:57 +00003074 let dirname = escape(b:netrw_curdir,s:netrw_glob_escape)
3075 let dirnamelen = strlen(b:netrw_curdir)
3076 let filelist = glob(dirname."/*")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003077" call Decho("glob(dirname<".dirname."/.*>)=".filelist)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003078 if filelist != ""
3079 let filelist= filelist."\n"
3080 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003081 let filelist= filelist.glob(dirname."/.*")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003082" call Decho("glob(dirname<".dirname."/.*>)=".glob(dirname.".*"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003083
3084 " if the directory name includes a "$", and possibly other characters,
3085 " the glob() doesn't include "." and ".." entries.
3086 if filelist !~ '[\\/]\.[\\/]\=\(\n\|$\)'
3087" call Decho("forcibly tacking on .")
3088 if filelist == ""
3089 let filelist= dirname."."
3090 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003091 let filelist= filelist."\n".b:netrw_curdir."."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003092 endif
3093" call Decho("filelist<".filelist.">")
3094 endif
3095 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
3096" call Decho("forcibly tacking on ..")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003097 let filelist= filelist."\n".b:netrw_curdir.".."
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003098" call Decho("filelist<".filelist.">")
3099 endif
3100 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
Bram Moolenaar57657d82006-04-21 22:12:41 +00003101 if (has("win32") || has("win95") || has("win64") || has("win16"))
3102 let filelist= substitute(filelist,'\','/','ge')
3103 else
3104 let filelist= substitute(filelist,'\','\\','ge')
3105 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003106
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003107" call Decho("dirname<".dirname.">")
3108" call Decho("dirnamelen<".dirnamelen.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003109" call Decho("filelist<".filelist.">")
3110
3111 while filelist != ""
3112 if filelist =~ '\n'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003113 let filename = substitute(filelist,'\n.*$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003114 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
3115 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00003116 let filename = filelist
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003117 let filelist = ""
Bram Moolenaar8299df92004-07-10 09:47:34 +00003118 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003119 let pfile= filename
3120 if isdirectory(filename)
3121 let pfile= filename."/"
Bram Moolenaar8299df92004-07-10 09:47:34 +00003122 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003123 if pfile =~ '//$'
3124 let pfile= substitute(pfile,'//$','/','e')
3125 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003126 let pfile= strpart(pfile,dirnamelen)
Bram Moolenaar572cb562005-08-05 21:35:02 +00003127 let pfile= substitute(pfile,'^/','','e')
Bram Moolenaar83bab712005-08-01 21:58:57 +00003128" call Decho(" ")
3129" call Decho("filename<".filename.">")
3130" call Decho("pfile <".pfile.">")
3131
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003132 if w:netrw_longlist == 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003133 let sz = getfsize(filename)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003134 let fsz = strpart(" ",1,15-strlen(sz)).sz
3135 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003136" call Decho("sz=".sz." fsz=".fsz)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003137 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003138
Bram Moolenaar8299df92004-07-10 09:47:34 +00003139 if g:netrw_sort_by =~ "^t"
3140 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003141" call Decho("getftime(".filename.")=".getftime(filename))
3142 let t = getftime(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003143 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar83bab712005-08-01 21:58:57 +00003144" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003145 let ftpfile= ft.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003146 keepjumps silent! put=ftpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003147
Bram Moolenaar8299df92004-07-10 09:47:34 +00003148 elseif g:netrw_sort_by =~ "^s"
3149 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003150" call Decho("getfsize(".filename.")=".getfsize(filename))
3151 let sz = getfsize(filename)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003152 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar83bab712005-08-01 21:58:57 +00003153" call Decho("exe keepjumps put ='".fsz.'/'.filename."'")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003154 let fszpfile= fsz.'/'.pfile
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003155 keepjumps silent! put =fszpfile
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003156
Bram Moolenaar8299df92004-07-10 09:47:34 +00003157 else
3158 " sort by name
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003159" call Decho("exe keepjumps put ='".pfile."'")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003160 keepjumps silent! put=pfile
Bram Moolenaar8299df92004-07-10 09:47:34 +00003161 endif
3162 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003163
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00003164 " cleanup any windows mess at end-of-line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003165 silent! keepjumps %s/\r$//e
Bram Moolenaar83bab712005-08-01 21:58:57 +00003166 setlocal ts=32
Bram Moolenaar8299df92004-07-10 09:47:34 +00003167
3168" call Dret("LocalBrowseList")
3169endfun
3170
3171" ---------------------------------------------------------------------
3172" LocalBrowseChgDir: constructs a new directory based on the current {{{2
3173" directory and a new directory name
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003174fun! s:LocalBrowseChgDir(dirname,newdir,...)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003175" call Dfunc("LocalBrowseChgDir(dirname<".a:dirname."> newdir<".a:newdir.">) a:0=".a:0)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003176
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003177 let dirname= substitute(a:dirname,'\\','','ge')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003178 let newdir = a:newdir
3179
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003180 if dirname !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00003181 " apparently vim is "recognizing" that it is in the home directory and
3182 " is removing the "/". Bad idea, so I have to put it back.
3183 let dirname= dirname.'/'
3184" call Decho("adjusting dirname<".dirname.">")
3185 endif
3186
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003187 if newdir !~ '[\/]$'
Bram Moolenaar8299df92004-07-10 09:47:34 +00003188 " handling a file
3189 let dirname= dirname.newdir
3190" call Decho("handling a file: dirname<".dirname.">")
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003191 " this lets NetBrowseX avoid the edit
3192 if a:0 < 1
Bram Moolenaar83bab712005-08-01 21:58:57 +00003193" call Decho("dirname<".dirname."> netrw_cd_escape<".s:netrw_cd_escape.">")
3194" call Decho("about to edit<".escape(dirname,s:netrw_cd_escape).">")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003195 if g:netrw_browse_split == 1
3196 new
3197 wincmd _
3198 elseif g:netrw_browse_split == 2
3199 rightb vert new
3200 wincmd |
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003201 else
3202 " handling a file, didn't split, so possibly remove menu
3203 call s:NetMenu(0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003204 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003205 exe "e! ".escape(dirname,s:netrw_cd_escape)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003206 set ma nomod
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003207 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003208
3209 elseif newdir == './'
3210 " refresh the directory list
3211" call Decho("refresh directory listing")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003212
3213 elseif newdir == '../'
3214 " go up one directory
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003215 let dirname= substitute(dirname,'^\(.*/\)\([^/]\+[\/]$\)','\1','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003216" call Decho("go up one dir: dirname<".dirname.">")
3217
3218 else
3219 " go down one directory
3220 let dirname= dirname.newdir
3221" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
3222 endif
3223
3224" call Dret("LocalBrowseChgDir <".dirname.">")
3225 return dirname
3226endfun
3227
3228" ---------------------------------------------------------------------
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003229" LocalBrowseShellCmdRefresh: this function is called after a user has {{{2
3230" performed any shell command. The idea is to cause all local-browsing
3231" buffers to be refreshed after a user has executed some shell command,
3232" on the chance that s/he removed/created a file/directory with it.
3233fun! s:LocalBrowseShellCmdRefresh()
3234" call Dfunc("LocalBrowseShellCmdRefresh() browselist=".string(s:netrw_browselist))
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00003235 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
3236 " | refresh any netrw window
3237 " | wipe out any non-displaying netrw buffer
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003238 let curwin = winnr()
3239 let ibl = 0
3240 for ibuf in s:netrw_browselist
3241 if bufwinnr(ibuf) == -1
3242" call Decho("wiping buf#".ibuf)
Bram Moolenaarc01140a2006-03-24 22:21:52 +00003243 exe "silent! bw ".ibuf
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003244 call remove(s:netrw_browselist,ibl)
3245" call Decho("browselist=".string(s:netrw_browselist))
3246 continue
3247 else
3248" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
3249 exe bufwinnr(ibuf)."wincmd w"
3250 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
3251 endif
3252 let ibl= ibl + 1
3253 endfor
3254 exe curwin."wincmd w"
3255
3256" call Dret("LocalBrowseShellCmdRefresh")
3257endfun
3258
3259" ---------------------------------------------------------------------
Bram Moolenaar572cb562005-08-05 21:35:02 +00003260" LocalBrowseRm: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003261fun! s:LocalBrowseRm(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003262" call Dfunc("LocalBrowseRm(path<".a:path.">)")
3263" call Decho("firstline=".a:firstline." lastline=".a:lastline)
3264
3265 " preparation for removing multiple files/directories
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003266 let ctr = a:firstline
3267 let ret = 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003268 let all= 0
Bram Moolenaar8299df92004-07-10 09:47:34 +00003269
3270 " remove multiple files and directories
3271 while ctr <= a:lastline
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003272 exe "keepjumps ".ctr
3273
3274 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003275 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003276 let ctr= ctr + 1
3277 continue
3278 endif
3279 let curword= s:NetGetWord()
3280 if curword == "./" || curword == "../"
3281 let ctr= ctr + 1
3282 continue
3283 endif
Bram Moolenaar8299df92004-07-10 09:47:34 +00003284
3285 norm! 0
Bram Moolenaar83bab712005-08-01 21:58:57 +00003286 let rmfile= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003287" call Decho("rmfile<".rmfile.">")
3288
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003289 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003290 " attempt to remove file
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003291 if !all
3292 echohl Statement
3293 call inputsave()
3294 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3295 call inputrestore()
3296 echohl NONE
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003297 if ok == ""
3298 let ok="no"
3299 endif
3300" call Decho("response: ok<".ok.">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003301 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003302" call Decho("response: ok<".ok."> (after sub)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 if ok =~ 'a\%[ll]'
3304 let all= 1
3305 endif
3306 endif
3307
3308 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003309 let ret= delete(rmfile)
3310" call Decho("errcode=".v:shell_error." ret=".ret)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003311 elseif ok =~ 'q\%[uit]'
3312 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003313 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003314
Bram Moolenaar8299df92004-07-10 09:47:34 +00003315 else
3316 " attempt to remove directory
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003317 if !all
3318 echohl Statement
3319 call inputsave()
3320 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
3321 call inputrestore()
3322 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003323 if ok == ""
3324 let ok="no"
3325 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003326 if ok =~ 'a\%[ll]'
3327 let all= 1
3328 endif
3329 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003330 let rmfile= substitute(rmfile,'[\/]$','','e')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003331
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003332 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003333" call Decho("1st attempt: system(".g:netrw_local_rmdir.' "'.rmfile.'")')
3334 call system(g:netrw_local_rmdir.' "'.rmfile.'"')
Bram Moolenaar8299df92004-07-10 09:47:34 +00003335" call Decho("v:shell_error=".v:shell_error)
3336
3337 if v:shell_error != 0
3338" call Decho("2nd attempt to remove directory<".rmfile.">")
3339 let errcode= delete(rmfile)
3340" call Decho("errcode=".errcode)
3341
3342 if errcode != 0
3343 if has("unix")
3344" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003345call system("rm ".rmfile)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003346 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003347 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003348 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003349endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003350 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003351 echohl Error | echo "***netrw*** unable to remove directory<".rmfile."> -- is it empty?" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003352 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar8299df92004-07-10 09:47:34 +00003353 endif
3354 endif
3355 endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003356
3357 elseif ok =~ 'q\%[uit]'
3358 break
Bram Moolenaar8299df92004-07-10 09:47:34 +00003359 endif
3360 endif
3361
3362 let ctr= ctr + 1
3363 endwhile
3364
3365 " refresh the directory
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003366 let curline= line(".")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003367" call Decho("refresh the directory")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003368 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003369 exe curline
3370
3371" call Dret("LocalBrowseRm")
3372endfun
3373
3374" ---------------------------------------------------------------------
3375" LocalBrowseRename: rename a remote file or directory {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003376fun! s:LocalBrowseRename(path) range
Bram Moolenaar8299df92004-07-10 09:47:34 +00003377" call Dfunc("LocalBrowseRename(path<".a:path.">)")
3378
3379 " preparation for removing multiple files/directories
3380 let ctr= a:firstline
3381
3382 " attempt to rename files/directories
3383 while ctr <= a:lastline
3384 exe "keepjumps ".ctr
3385
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003386 " sanity checks
Bram Moolenaar488c6512005-08-11 20:09:58 +00003387 if line(".") < w:netrw_bannercnt
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003388 let ctr= ctr + 1
3389 continue
3390 endif
3391 let curword= s:NetGetWord()
3392 if curword == "./" || curword == "../"
3393 let ctr= ctr + 1
3394 continue
3395 endif
3396
Bram Moolenaar8299df92004-07-10 09:47:34 +00003397 norm! 0
Bram Moolenaar572cb562005-08-05 21:35:02 +00003398 let oldname= a:path."/".curword
Bram Moolenaar8299df92004-07-10 09:47:34 +00003399" call Decho("oldname<".oldname.">")
3400
3401 call inputsave()
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003402 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
Bram Moolenaar8299df92004-07-10 09:47:34 +00003403 call inputrestore()
3404
Bram Moolenaar83bab712005-08-01 21:58:57 +00003405 let ret= rename(oldname,newname)
3406" call Decho("renaming <".oldname."> to <".newname.">")
Bram Moolenaar8299df92004-07-10 09:47:34 +00003407
3408 let ctr= ctr + 1
3409 endwhile
3410
3411 " refresh the directory
3412 let curline= line(".")
Bram Moolenaar269ec652004-07-29 08:43:53 +00003413" call Decho("refresh the directory listing")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003414 call s:NetRefresh(s:LocalBrowseChgDir(b:netrw_curdir,'./'),1)
Bram Moolenaar8299df92004-07-10 09:47:34 +00003415 exe "keepjumps ".curline
3416" call Dret("LocalBrowseRename")
3417endfun
3418
3419" ---------------------------------------------------------------------
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00003420" LocalFastBrowser: handles setting up/taking down fast browsing for the {{{2
3421" local browser
3422fun! s:LocalFastBrowser()
3423" call Dfunc("LocalFastBrowser()")
3424
3425 " initialize browselist, a list of buffer numbers that the local browser has used
3426 if !exists("s:netrw_browselist")
3427 let s:netrw_browselist= []
3428 endif
3429
3430 " append current buffer to fastbrowse list
3431 if g:netrw_fastbrowse <= 1 && (empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1])
3432 call add(s:netrw_browselist,bufnr("%"))
3433" call Decho("browselist=".string(s:netrw_browselist))
3434 endif
3435
3436 " enable autocmd events to handle refreshing/removing local browser buffers
3437 " If local browse buffer is currently showing: refresh it
3438 " If local browse buffer is currently hidden : wipe it
3439 if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1
3440" call Decho("setting up local-browser shell command refresh")
3441 let s:netrw_browser_shellcmd= 1
3442 augroup AuNetrwShellCmd
3443 au!
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00003444 if (has("win32") || has("win95") || has("win64") || has("win16"))
3445 au ShellCmdPost * call s:LocalBrowseShellCmdRefresh()
3446 else
3447 au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()
3448 endif
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00003449 augroup END
Bram Moolenaar8dff8182006-04-06 20:18:50 +00003450 endif
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00003451
3452 " user must have changed fastbrowse to its fast setting, so remove
3453 " the associated autocmd events
3454 if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd")
3455 unlet s:netrw_browser_shellcmd
3456 augroup AuNetrwShellCmd
3457 au!
3458 augroup END
3459 augroup! AuNetrwShellCmd
3460 endif
3461
3462" call Dret("LocalFastBrowser")
3463endfun
3464
3465" ---------------------------------------------------------------------
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003466" LocalObtain: copy selected file to current working directory {{{2
3467fun! s:LocalObtain()
3468" call Dfunc("LocalObtain()")
3469 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
3470 let fname= expand("<cWORD>")
3471 let fcopy= readfile(b:netrw_curdir."/".fname,"b")
3472 call writefile(fcopy,getcwd()."/".fname,"b")
3473 elseif !exists("b:netrw_curdir")
3474 echohl Error | echo "***netrw*** local browsing directory doesn't exist!"
3475 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3476 else
3477 echohl Error | echo "***netrw*** local browsing directory and current directory are identical"
3478 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3479 endif
3480" call Dret("LocalObtain")
3481endfun
3482
3483" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003484" LocalPreview: {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003485fun! s:LocalPreview(path) range
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003486" call Dfunc("LocalPreview(path<".a:path.">)")
3487 if has("quickfix")
3488 if !isdirectory(a:path)
3489 exe "pedit ".a:path
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003490 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003491 echohl WarningMsg | echo "***netrw*** sorry, cannot preview a directory such as <".a:path.">" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003492 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003493 endif
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003494 elseif !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003495 echohl WarningMsg | echo "***netrw*** sorry, to preview your vim needs the quickfix feature compiled in" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003496 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003497 endif
3498" call Dret("LocalPreview")
3499endfun
3500
3501" ---------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00003502" Explore: launch the local browser in the directory of the current file {{{2
3503" dosplit==0: the window will be split iff the current file has
3504" been modified
3505" dosplit==1: the window will be split before running the local
3506" browser
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003507fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003508" call Dfunc("Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.")")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003509
3510 " if dosplit or file has been modified
3511 if a:dosplit || &modified
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003512 call s:SaveWinVars()
Bram Moolenaar488c6512005-08-11 20:09:58 +00003513
Bram Moolenaar83bab712005-08-01 21:58:57 +00003514 if a:style == 0 " Explore, Sexplore
3515 exe g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003516" call Decho("style=0: Explore or Sexplore")
3517
Bram Moolenaar83bab712005-08-01 21:58:57 +00003518 elseif a:style == 1 "Explore!, Sexplore!
3519 exe g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003520" call Decho("style=1: Explore! or Sexplore!")
3521
Bram Moolenaar83bab712005-08-01 21:58:57 +00003522 elseif a:style == 2 " Hexplore
3523 exe "bel ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003524" call Decho("style=2: Hexplore")
3525
Bram Moolenaar83bab712005-08-01 21:58:57 +00003526 elseif a:style == 3 " Hexplore!
3527 exe "abo ".g:netrw_winsize."wincmd s"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003528" call Decho("style=3: Hexplore!")
3529
Bram Moolenaar83bab712005-08-01 21:58:57 +00003530 elseif a:style == 4 " Vexplore
3531 exe "lefta ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003532" call Decho("style=4: Vexplore")
3533
Bram Moolenaar83bab712005-08-01 21:58:57 +00003534 elseif a:style == 5 " Vexplore!
3535 exe "rightb ".g:netrw_winsize."wincmd v"
Bram Moolenaar488c6512005-08-11 20:09:58 +00003536" call Decho("style=5: Vexplore!")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003537 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003538 call s:CopyWinVars()
Bram Moolenaar83bab712005-08-01 21:58:57 +00003539 endif
3540 norm! 0
3541
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003542 if a:1 =~ '^\*/'
Bram Moolenaar57657d82006-04-21 22:12:41 +00003543 " Explore */pattern
3544 let pattern= substitute(a:1,'^\*/\(.*\)$','\1','')
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003545" call Decho("Explore */pat: a:1<".a:1."> -> pattern<".pattern.">")
3546 elseif a:1 =~ '^\*\*//'
3547 " Explore **//pattern
3548 let pattern = substitute(a:1,'^\*\*//','','')
3549 let starstarpat = 1
3550" call Decho("Explore **//pat: a:1<".a:1."> -> pattern<".pattern.">")
Bram Moolenaar57657d82006-04-21 22:12:41 +00003551 endif
3552
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003553 if a:1 == "" && a:indx >= 0
Bram Moolenaar488c6512005-08-11 20:09:58 +00003554 " Explore Hexplore Vexplore Sexplore
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003555" call Decho("Explore Hexplore Vexplore Sexplore")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003556 let newdir= substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
3557 if newdir =~ '^scp:' || newdir =~ '^ftp:'
3558" call Decho("calling NetBrowse(newdir<".newdir.">)")
3559 call s:NetBrowse(newdir)
3560 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003561 if newdir == ""|let newdir= getcwd()|endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003562" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3563 call s:LocalBrowse(newdir)
3564 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003565
Bram Moolenaar57657d82006-04-21 22:12:41 +00003566 elseif a:1 =~ '^\*\*/' || a:indx < 0 || a:1 =~ '^\*/'
3567 " Nexplore, Pexplore, Explore **/... , or Explore */pattern
3568" call Decho("Nexplore, Pexplore, <s-down>, <s-up>, Explore ".a:1)
3569 let s:didstarstar= 1
3570 if exists("b:netrw_curdir")
3571 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
3572 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
3573 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003574
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003575 if has("path_extra")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003576 if !exists("w:netrw_explore_indx")
3577 let w:netrw_explore_indx= 0
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003578 endif
3579 let indx = a:indx
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003580" call Decho("set indx=".indx)
Bram Moolenaar57657d82006-04-21 22:12:41 +00003581"
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003582 if indx == -1
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003583 "Nexplore
Bram Moolenaar57657d82006-04-21 22:12:41 +00003584 if !exists("w:netrw_explore_list") " sanity check
3585 echohl WarningMsg | echo "***netrw*** using Nexplore or <s-down> improperly; see help for netrw-starstar" | echohl None
3586 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3587" call Dret("Explore")
3588 return
3589 endif
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003590 let indx = w:netrw_explore_indx
3591 let curfile= w:netrw_explore_list[indx]
3592 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
3593 let indx= indx + 1
3594" call Decho("indx=".indx)
3595 endwhile
3596" call Decho("Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaar57657d82006-04-21 22:12:41 +00003597
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003598 elseif indx == -2
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003599 "Pexplore
Bram Moolenaar57657d82006-04-21 22:12:41 +00003600 if !exists("w:netrw_explore_list") " sanity check
3601 echohl WarningMsg | echo "***netrw*** using Pexplore or <s-up> improperly; see help for netrw-starstar" | echohl None
3602 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3603" call Dret("Explore")
3604 return
3605 endif
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003606 let indx = w:netrw_explore_indx
3607 let curfile= w:netrw_explore_list[indx]
3608 while indx > 0 && curfile == w:netrw_explore_list[indx]
3609 let indx= indx - 1
3610 endwhile
3611" call Decho("Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaar57657d82006-04-21 22:12:41 +00003612
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003613 else
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003614 " Explore -- initialize
Bram Moolenaar57657d82006-04-21 22:12:41 +00003615 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003616" call Decho("Explore -- initialize")
3617 let w:netrw_explore_indx= 0
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003618 if !exists("b:netrw_curdir")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003619 let b:netrw_curdir= getcwd()
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003620 endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003621" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
3622 if exists("pattern")
3623" call Decho("building list based on pattern<".pattern."> cwd<".getcwd().">")
Bram Moolenaar4a85b412006-04-23 22:40:29 +00003624 if exists("starstarpat")
3625 exe "vimgrep /".pattern."/gj "."**/*"
3626 let s:netrw_curdir= b:netrw_curdir
3627 let w:netrw_explore_list = map(getqflist(),'s:netrw_curdir."/".bufname(v:val.bufnr)')
3628 else
3629 exe "vimgrep /".pattern."/gj ".b:netrw_curdir."/*"
3630 if (has("win32") || has("win95") || has("win64") || has("win16"))
3631 let w:netrw_explore_list = map(getqflist(),'bufname(v:val.bufnr)')
3632 else
3633 let w:netrw_explore_list = map(getqflist(),'b:netrw_curdir.bufname(v:val.bufnr)')
3634 endif
3635 endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003636 else
3637" call Decho("building list based on ".b:netrw_curdir."/".a:1)
3638 let w:netrw_explore_list= split(expand(b:netrw_curdir."/".a:1),'\n')
3639 endif
3640
Bram Moolenaar488c6512005-08-11 20:09:58 +00003641 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaar57657d82006-04-21 22:12:41 +00003642" call Decho("w:netrw_explore_list<".string(w:netrw_explore_list)."> listlen=".w:netrw_explore_listlen)
3643
Bram Moolenaar488c6512005-08-11 20:09:58 +00003644 if w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/'
Bram Moolenaar572cb562005-08-05 21:35:02 +00003645 echohl WarningMsg | echo "***netrw*** no files matched" | echohl None
3646 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3647" call Dret("Explore")
3648 return
3649 endif
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003650 endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003651
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003652 " NetrwStatusLine support - for exploring support
Bram Moolenaar488c6512005-08-11 20:09:58 +00003653 let w:netrw_explore_indx= indx
Bram Moolenaar488c6512005-08-11 20:09:58 +00003654" call Decho("explorelist<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003655
3656 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00003657 if indx >= w:netrw_explore_listlen || indx < 0
3658 let indx= (indx < 0)? 0 : ( w:netrw_explore_listlen - 1 )
Bram Moolenaar572cb562005-08-05 21:35:02 +00003659 echohl WarningMsg | echo "***netrw*** no more files match Explore pattern" | echohl None
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003660 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3661" call Dret("Explore")
3662 return
3663 endif
3664
Bram Moolenaar488c6512005-08-11 20:09:58 +00003665 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003666" call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003667 let newdir= substitute(dirfile,'/[^/]*$','','e')
3668" call Decho("newdir<".newdir.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003669
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003670" call Decho("calling LocalBrowse(newdir<".newdir.">)")
3671 call s:LocalBrowse(newdir)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003672 if w:netrw_longlist == 0 || w:netrw_longlist == 1
3673 call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
3674 else
3675 call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
3676 endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00003677 let w:netrw_explore_mtchcnt = indx + 1
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003678 let w:netrw_explore_bufnr = bufnr("%")
Bram Moolenaar488c6512005-08-11 20:09:58 +00003679 let w:netrw_explore_line = line(".")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003680 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaar488c6512005-08-11 20:09:58 +00003681" 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 +00003682
3683 else
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003684 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003685 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 +00003686 endif
3687 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3688 endif
3689
Bram Moolenaar83bab712005-08-01 21:58:57 +00003690 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003691" call Decho("Explore newdir<".a:1.">")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003692 let newdir= a:1
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00003693 call s:LocalBrowse(newdir)
Bram Moolenaar83bab712005-08-01 21:58:57 +00003694 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00003695
3696" call Dret("Explore")
3697endfun
3698
3699" ---------------------------------------------------------------------
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003700" SetupNetrwStatusLine: {{{2
3701fun! s:SetupNetrwStatusLine(statline)
3702" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
3703
3704 if !exists("s:netrw_setup_statline")
3705 let s:netrw_setup_statline= 1
3706" call Decho("do first-time status line setup")
3707
3708 if !exists("s:netrw_users_stl")
3709 let s:netrw_users_stl= &stl
3710 endif
3711 if !exists("s:netrw_users_ls")
3712 let s:netrw_users_ls= &laststatus
3713 endif
3714
3715 " set up User9 highlighting as needed
3716 let keepa= @a
3717 redir @a
3718 try
3719 hi User9
3720 catch /^Vim\%((\a\+)\)\=:E411/
3721 if &bg == "dark"
3722 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
3723 else
3724 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
3725 endif
3726 endtry
3727 redir END
3728 let @a= keepa
3729 endif
3730
3731 " set up status line (may use User9 highlighting)
3732 " insure that windows have a statusline
3733 " make sure statusline is displayed
3734 let &stl=a:statline
3735 set laststatus=2
3736" call Decho("stl=".&stl)
3737 redraw!
3738
3739" call Dret("SetupNetrwStatusLine : stl=".&stl)
3740endfun
3741
3742" ---------------------------------------------------------------------
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003743" NetrwStatusLine: {{{2
3744fun! NetrwStatusLine()
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003745
3746 " vvv NetrwStatusLine() debugging vvv
3747" let g:stlmsg=""
3748" if !exists("w:netrw_explore_bufnr")
3749" let g:stlmsg="!X<explore_bufnr>"
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003750" elseif w:netrw_explore_bufnr != bufnr("%")
3751" let g:stlmsg="explore_bufnr!=".bufnr("%")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003752" endif
3753" if !exists("w:netrw_explore_line")
3754" let g:stlmsg=" !X<explore_line>"
3755" elseif w:netrw_explore_line != line(".")
3756" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
3757" endif
3758" if !exists("w:netrw_explore_list")
3759" let g:stlmsg=" !X<explore_list>"
3760" endif
3761 " ^^^ NetrwStatusLine() debugging ^^^
3762
Bram Moolenaar1f4d4de2006-03-14 23:00:46 +00003763 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 +00003764 " restore user's status line
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003765 let &stl = s:netrw_users_stl
3766 let &laststatus = s:netrw_users_ls
Bram Moolenaar488c6512005-08-11 20:09:58 +00003767 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
3768 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003769 return ""
3770 else
Bram Moolenaar488c6512005-08-11 20:09:58 +00003771 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
Bram Moolenaarf6cf9872005-08-08 22:00:59 +00003772 endif
3773endfun
3774
3775" ---------------------------------------------------------------------
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003776" NetGetcwd: get the current directory. {{{2
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003777" Change backslashes to forward slashes, if any.
3778" If doesc is true, escape certain troublesome characters
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00003779fun! s:NetGetcwd(doesc)
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003780" call Dfunc("NetGetcwd(doesc=".a:doesc.")")
3781 let curdir= substitute(getcwd(),'\\','/','ge')
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003782 if curdir !~ '[\/]$'
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003783 let curdir= curdir.'/'
3784 endif
3785 if a:doesc
3786 let curdir= escape(curdir,s:netrw_cd_escape)
3787 endif
3788" call Dret("NetGetcwd <".curdir.">")
3789 return curdir
3790endfun
3791
3792" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003793" NetMethod: determine method of transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794" method == 1: rcp
3795" 2: ftp + <.netrc>
3796" 3: ftp + machine, id, password, and [path]filename
3797" 4: scp
3798" 5: http (wget)
3799" 6: cadaver
3800" 7: rsync
3801" 8: fetch
3802" 9: sftp
3803fun! s:NetMethod(choice) " globals: method machine id passwd fname
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003804" call Dfunc("NetMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003805
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003806 " initialization
3807 let b:netrw_method = 0
3808 let g:netrw_machine = ""
3809 let b:netrw_fname = ""
3810 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003811 let g:netrw_choice = a:choice
3812
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003813 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003814 " mipf : a:machine a:id password filename Use ftp
3815 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003816 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003817 " rcpurm : rcp://[user@]host/filename Use rcp
3818 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003819 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003820 " httpurm : http://[user@]host/filename Use wget
3821 " davurm : [s]dav://host[:port]/path Use cadaver
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003822 " rsyncurm : rsync://host[:port]/path Use rsync
3823 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3824 " sftpurm : sftp://[user@]host/filename Use scp
3825 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3826 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
3827 let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
Bram Moolenaar83bab712005-08-01 21:58:57 +00003828 let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003829 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003830 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003831 let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003832 let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003833 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
3834 let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
3835 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003836
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003837" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003838 " Determine Method
3839 " rcp://user@hostname/...path-to-file
3840 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003841" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00003842 let b:netrw_method = 1
3843 let userid = substitute(a:choice,rcpurm,'\1',"")
3844 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3845 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003846 if userid != ""
3847 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003849
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003850 " scp://user@hostname/...path-to-file
3851 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003852" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003853 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003854 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3855 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3856 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003857
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003858 " http://user@hostname/...path-to-file
3859 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003860" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003861 let b:netrw_method = 5
3862 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3863 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003864
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003865 " dav://hostname[:port]/..path-to-file..
3866 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003867" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003868 let b:netrw_method= 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003869 if a:choice =~ '^s'
3870 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3871 else
3872 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3873 endif
3874 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003875
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003876 " rsync://user@hostname/...path-to-file
3877 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003878" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003879 let b:netrw_method = 7
3880 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3881 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003882
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003883 " ftp://[user@]hostname[[:#]port]/...path-to-file
3884 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003885" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003886 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003887 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3888 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3889 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003890 if userid != ""
3891 let g:netrw_uid= userid
3892 endif
3893 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3894 let b:netrw_method = 3
3895 else
3896 if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc")
3897 let b:netrw_method= 2
3898 else
3899 if !exists("g:netrw_uid") || g:netrw_uid == ""
3900 call NetUserPass()
3901 elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
3902 call NetUserPass(g:netrw_uid)
3903 " else just use current g:netrw_uid and g:netrw_passwd
3904 endif
3905 let b:netrw_method= 3
3906 endif
3907 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003908
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003909 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003910" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003911 let b:netrw_method = 8
3912 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3913 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3914 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3915 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003916
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003917 " Issue an ftp : "machine id password [path/]filename"
3918 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003919" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003921 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3922 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
3923 let g:netrw_passwd = substitute(a:choice,mipf,'\3',"")
3924 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003925
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003926 " Issue an ftp: "hostname [path/]filename"
3927 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003928" call Decho("(ftp) host file")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003929 if exists("g:netrw_uid") && exists("g:netrw_passwd")
3930 let b:netrw_method = 3
3931 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3932 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003933
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003934 elseif filereadable(expand("$HOME/.netrc"))
3935 let b:netrw_method = 2
3936 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3937 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3938 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003939
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003940 " sftp://user@hostname/...path-to-file
3941 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003942" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003943 let b:netrw_method = 9
3944 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3945 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003946
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003947 " Issue an rcp: hostname:filename" (this one should be last)
3948 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003949" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003950 let b:netrw_method = 1
3951 let userid = substitute(a:choice,rcphf,'\2',"")
3952 let g:netrw_machine= substitute(a:choice,rcphf,'\3',"")
3953 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003954" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
3955" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
3956" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
3957" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003958 if userid != ""
3959 let g:netrw_uid= userid
3960 endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +00003961 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003962 " don't let PCs try <.netrc>
3963 let b:netrw_method = 3
3964 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003965
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003966 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003967 if !exists("g:netrw_quiet")
Bram Moolenaar572cb562005-08-05 21:35:02 +00003968 echohl Error | echo "***netrw*** cannot determine method" | echohl None
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003969 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003970 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003971 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 endif
Bram Moolenaar81695252004-12-29 20:58:21 +00003973
3974 " remove any leading [:#] from port number
3975 if g:netrw_port != ""
3976 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3977 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003978
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003979" call Decho("a:choice <".a:choice.">")
3980" call Decho("b:netrw_method <".b:netrw_method.">")
3981" call Decho("g:netrw_machine<".g:netrw_machine.">")
3982" call Decho("g:netrw_port <".g:netrw_port.">")
3983" if exists("g:netrw_uid") "Decho
3984" call Decho("g:netrw_uid <".g:netrw_uid.">")
3985" endif "Decho
3986" if exists("g:netrw_passwd") "Decho
3987" call Decho("g:netrw_passwd <".g:netrw_passwd.">")
3988" endif "Decho
3989" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003990" call Dret("NetMethod : b:netrw_method=".b:netrw_method)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992
3993" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003994" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995" Usage: :call NetUserPass() -- will prompt for userid and password
3996" :call NetUserPass("uid") -- will prompt for password
3997" :call NetUserPass("uid","password") -- sets global userid and password
3998fun! NetUserPass(...)
3999
4000 " get/set userid
4001 if a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004002" call Dfunc("NetUserPass(a:0<".a:0.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 if !exists("g:netrw_uid") || g:netrw_uid == ""
4004 " via prompt
4005 let g:netrw_uid= input('Enter username: ')
4006 endif
4007 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004008" call Dfunc("NetUserPass(a:1<".a:1.">) {")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 let g:netrw_uid= a:1
4010 endif
4011
4012 " get password
4013 if a:0 <= 1 " via prompt
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004014" call Decho("a:0=".a:0." case <=1:")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 let g:netrw_passwd= inputsecret("Enter Password: ")
4016 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004017" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 let g:netrw_passwd=a:2
4019 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004020
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004021" call Dret("NetUserPass")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023
4024" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004025" NetOptionSave: save options and set to "standard" form {{{2
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004026fun! s:NetOptionSave()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004027" call Dfunc("NetOptionSave()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004028 if !exists("w:netoptionsave")
4029 let w:netoptionsave= 1
4030 else
4031" call Dret("NetOptionSave : netoptionsave=".w:netoptionsave)
4032 return
4033 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004035 " Get Temporary Filename
Bram Moolenaar57657d82006-04-21 22:12:41 +00004036 let w:acdkeep = &acd
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004037 let w:aikeep = &ai
Bram Moolenaar57657d82006-04-21 22:12:41 +00004038 let w:fokeep = &fo
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004039 let w:cikeep = &ci
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004040 let w:cinkeep = &cin
4041 let w:cinokeep = &cino
4042 let w:comkeep = &com
4043 let w:cpokeep = &cpo
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00004044 let w:hidkeep = &hidden
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004045 let w:magickeep = &magic
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004046 let w:gdkeep = &gd
4047 let w:repkeep = &report
4048 let w:spellkeep = &spell
4049 let w:twkeep = &tw
Bram Moolenaar8299df92004-07-10 09:47:34 +00004050 setlocal cino =
4051 setlocal com =
4052 setlocal cpo -=aA
Bram Moolenaar57657d82006-04-21 22:12:41 +00004053 setlocal noacd nocin noai noci magic nospell fo=nroql2 nohid
Bram Moolenaar8299df92004-07-10 09:47:34 +00004054 setlocal tw =0
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004055 setlocal report=10000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004056 if has("win32") && !has("win95")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004057 let w:swfkeep= &swf
Bram Moolenaar8299df92004-07-10 09:47:34 +00004058 setlocal noswf
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004059" call Decho("setting w:swfkeep to <".&swf.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004060 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004062" call Dret("NetOptionSave")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063endfun
4064
4065" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004066" NetOptionRestore: restore options {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067fun! s:NetOptionRestore()
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004068" call Dfunc("NetOptionRestore()")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004069 if !exists("w:netoptionsave")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004070" call Dret("NetOptionRestore : w:netoptionsave doesn't exist")
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004071 return
4072 endif
4073 unlet w:netoptionsave
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004074
Bram Moolenaar57657d82006-04-21 22:12:41 +00004075 if exists("w:acdkeep") |let &acd = w:acdkeep |unlet w:acdkeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004076 if exists("w:aikeep") |let &ai = w:aikeep |unlet w:aikeep |endif
4077 if exists("w:cikeep") |let &ci = w:cikeep |unlet w:cikeep |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004078 if exists("w:cinkeep") |let &cin = w:cinkeep |unlet w:cinkeep |endif
4079 if exists("w:cinokeep") |let &cino = w:cinokeep |unlet w:cinokeep |endif
4080 if exists("w:comkeep") |let &com = w:comkeep |unlet w:comkeep |endif
4081 if exists("w:cpokeep") |let &cpo = w:cpokeep |unlet w:cpokeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004082 if exists("w:fokeep") |let &fo = w:fokeep |unlet w:fokeep |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004083 if exists("w:gdkeep") |let &gd = w:gdkeep |unlet w:gdkeep |endif
Bram Moolenaar7d47b6e2006-03-15 22:59:18 +00004084 if exists("w:hidkeep") |let &hidden = w:hidkeep |unlet w:hidkeep |endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004085 if exists("w:magic") |let &magic = w:magic |unlet w:magic |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004086 if exists("w:repkeep") |let &report = w:repkeep |unlet w:repkeep |endif
4087 if exists("w:spellkeep")|let &spell = w:spellkeep |unlet w:spellkeep|endif
4088 if exists("w:twkeep") |let &tw = w:twkeep |unlet w:twkeep |endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004089 if exists("w:swfkeep")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004090 if &directory == "" && exists("w:swfkeep")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004091 " user hasn't specified a swapfile directory;
4092 " netrw will temporarily make the swapfile
4093 " directory the current local one.
4094 let &directory = getcwd()
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004095 silent! let &swf = w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004096 set directory=
4097 else
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004098 let &swf= w:swfkeep
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004099 endif
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00004100 unlet w:swfkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004101 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004102
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004103" call Dret("NetOptionRestore")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104endfun
4105
4106" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004107" NetReadFixup: this sort of function is typically written by the user {{{2
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004108" to handle extra junk that their system's ftp dumps
4109" into the transfer. This function is provided as an
4110" example and as a fix for a Windows 95 problem: in my
4111" experience, win95's ftp always dumped four blank lines
4112" at the end of the transfer.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004113if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 fun! NetReadFixup(method, line1, line2)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004115" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 if method == 3 " ftp (no <.netrc>)
4117 let fourblanklines= line2 - 3
4118 silent fourblanklines.",".line2."g/^\s*/d"
4119 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004120" call Dret("NetReadFixup")
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 endfun
4122endif
4123
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004124" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004125" NetSort: Piet Delport's BISort2() function, modified to take a range {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00004126if v:version < 700
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004127 fun! s:NetSort() range
Bram Moolenaar83bab712005-08-01 21:58:57 +00004128" " call Dfunc("NetSort()")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004129
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004130 let i = a:firstline + 1
4131 while i <= a:lastline
4132 " find insertion point via binary search
4133 let i_val = getline(i)
4134 let lo = a:firstline
4135 let hi = i
4136 while lo < hi
Bram Moolenaar83bab712005-08-01 21:58:57 +00004137 let mid = (lo + hi) / 2
4138 let mid_val = getline(mid)
4139 if g:netrw_sort_direction =~ '^n'
4140 " normal sorting order
4141 if i_val < mid_val
4142 let hi = mid
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004143 else
Bram Moolenaar83bab712005-08-01 21:58:57 +00004144 let lo = mid + 1
4145 if i_val == mid_val | break | endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004146 endif
Bram Moolenaar83bab712005-08-01 21:58:57 +00004147 else
4148 " reverse sorting order
4149 if i_val > mid_val
4150 let hi = mid
4151 else
4152 let lo = mid + 1
4153 if i_val == mid_val | break | endif
4154 endif
4155 endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004156 endwhile
4157 " do insert
4158 if lo < i
Bram Moolenaar83bab712005-08-01 21:58:57 +00004159 exe 'keepjumps '.i.'d_'
4160 keepjumps call append(lo - 1, i_val)
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004161 endif
4162 let i = i + 1
4163 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00004164
Bram Moolenaar83bab712005-08-01 21:58:57 +00004165" " call Dret("NetSort")
4166 endfun
4167endif
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004168
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004169" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004170" SetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
Bram Moolenaar8299df92004-07-10 09:47:34 +00004171" What this function does is to compute a priority for the patterns
4172" in the g:netrw_sort_sequence. It applies a substitute to any
4173" "files" that satisfy each pattern, putting the priority / in
4174" front. An "*" pattern handles the default priority.
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004175fun! s:SetSort()
Bram Moolenaar488c6512005-08-11 20:09:58 +00004176" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004177 if w:netrw_longlist == 1
Bram Moolenaar8299df92004-07-10 09:47:34 +00004178 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
4179 else
4180 let seqlist = g:netrw_sort_sequence
4181 endif
4182 " sanity check -- insure that * appears somewhere
4183 if seqlist == ""
4184 let seqlist= '*'
4185 elseif seqlist !~ '\*'
4186 let seqlist= seqlist.',*'
4187 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004188 let priority = 1
4189 while seqlist != ""
4190 if seqlist =~ ','
4191 let seq = substitute(seqlist,',.*$','','e')
4192 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
4193 else
4194 let seq = seqlist
4195 let seqlist = ""
4196 endif
4197 let eseq= escape(seq,'/')
4198 if priority < 10
4199 let spriority= "00".priority.'\/'
4200 elseif priority < 100
4201 let spriority= "0".priority.'\/'
4202 else
4203 let spriority= priority.'\/'
4204 endif
4205" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
4206
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004207 " sanity check
Bram Moolenaar488c6512005-08-11 20:09:58 +00004208 if w:netrw_bannercnt > line("$")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004209 " apparently no files were left after a Hiding pattern was used
4210" call Dret("SetSort : no files left after hiding")
4211 return
4212 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004213 if seq == '*'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004214 exe 'silent keepjumps '.w:netrw_bannercnt.',$v/^\d\{3}\//s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004215 else
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004216 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/'.eseq.'/s/^/'.spriority.'/'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004217 endif
4218 let priority = priority + 1
4219 endwhile
4220
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00004221 " Following line associated with priority -- items that satisfy a priority
4222 " pattern get prefixed by ###/ which permits easy sorting by priority.
4223 " Sometimes files can satisfy multiple priority patterns -- only the latest
4224 " priority pattern needs to be retained. So, at this point, these excess
4225 " priority prefixes need to be removed, but not directories that happen to
4226 " be just digits themselves.
Bram Moolenaar8dff8182006-04-06 20:18:50 +00004227 exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\(\d\{3}\/\)\%(\d\{3}\/\)\+\ze./\1/e'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00004228
4229" call Dret("SetSort")
4230endfun
4231
Bram Moolenaar488c6512005-08-11 20:09:58 +00004232" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004233" SaveWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00004234fun! s:SaveWinVars()
4235" call Dfunc("SaveWinVars()")
4236 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
4237 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
4238 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
4239 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
4240 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
4241 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
4242 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
4243 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004244 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00004245" call Dret("SaveWinVars")
4246endfun
4247
4248" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004249" CopyWinVars: (used by Explore()) {{{2
Bram Moolenaar488c6512005-08-11 20:09:58 +00004250fun! s:CopyWinVars()
4251" call Dfunc("CopyWinVars()")
4252 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
4253 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
4254 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
4255 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
4256 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
4257 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
4258 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
4259 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 +00004260 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 +00004261" call Dret("CopyWinVars")
4262endfun
4263
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004264" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004265" SetBufWinVars: (used by NetBrowse() and LocalBrowse()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004266" To allow separate windows to have their own activities, such as
4267" Explore **/pattern, several variables have been made window-oriented.
4268" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004269" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004270" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004271fun! s:SetBufWinVars()
4272" call Dfunc("SetBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004273 if exists("w:netrw_longlist") |let b:netrw_longlist = w:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004274 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
4275 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
4276 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
4277 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
4278 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen = w:netrw_explore_listlen|endif
4279 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = w:netrw_explore_mtchcnt|endif
4280 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
4281 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
4282 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004283" call Dret("SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004284endfun
4285
4286" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004287" UseBufWinVars: (used by NetBrowse() and LocalBrowse() {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004288" Matching function to BufferWinVars()
4289fun! s:UseBufWinVars()
4290" call Dfunc("UseBufWinVars()")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00004291 if exists("b:netrw_longlist") && !exists("w:netrw_longlist") |let w:netrw_longlist = b:netrw_longlist |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00004292 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
4293 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
4294 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
4295 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
4296 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
4297 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
4298 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
4299 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
4300 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
4301" call Dret("UseBufWinVars")
4302endfun
4303
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004304" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004305" RFC2396: converts %xx into characters {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +00004306fun! netrw#RFC2396(fname)
4307" call Dfunc("RFC2396(fname<".a:fname.">)")
4308 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
4309" call Dret("RFC2396 ".fname)
4310 return fname
4311endfun
4312
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004313" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00004314" Settings Restoration: {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00004315let &cpo= s:keepcpo
4316unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00004317
Bram Moolenaar071d4272004-06-13 20:20:40 +00004318" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00004319" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320" vim:ts=8 fdm=marker