blob: b05f81db8bf1b164f8f0252b37314ca26147afd2 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003" Date: Jul 27, 2010
4" Version: 139
Bram Moolenaar9964e462007-05-05 17:54:07 +00005" Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007" Copyright: Copyright (C) 1999-2010 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
Bram Moolenaar446cb832008-06-24 21:56:24 +000012" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000013" 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 Moolenaar446cb832008-06-24 21:56:24 +000016"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
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 Moolenaar9964e462007-05-05 17:54:07 +000021" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022if &cp || exists("g:loaded_netrw")
23 finish
24endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020025let g:loaded_netrw = "v139"
Bram Moolenaar5c736222010-01-06 20:54:52 +010026if v:version < 702
27 echohl WarningMsg
28 echo "***warning*** this version of netrw needs vim 7.2"
29 echohl Normal
30 finish
31endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000032if !exists("s:NOTE")
33 let s:NOTE = 0
34 let s:WARNING = 1
35 let s:ERROR = 2
36endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000037
38" sanity checks
Bram Moolenaar578b49e2005-09-10 19:22:57 +000039if v:version < 700
Bram Moolenaar9964e462007-05-05 17:54:07 +000040 call netrw#ErrorMsg(s:WARNING,"you need vim version 7.0 or later for version ".g:loaded_netrw." of netrw",1)
Bram Moolenaar578b49e2005-09-10 19:22:57 +000041 finish
42endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000043
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044let s:keepcpo= &cpo
Bram Moolenaar9964e462007-05-05 17:54:07 +000045setlocal cpo&vim
46"DechoTabOn
47"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw)
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000049" ======================
50" Netrw Variables: {{{1
51" ======================
52
Bram Moolenaar071d4272004-06-13 20:20:40 +000053" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +010054" NetrwInit: initializes variables if they haven't been defined {{{2
55" Loosely, varname = value.
56fun s:NetrwInit(varname,value)
57 if !exists(a:varname)
58 if type(a:value) == 0
59 exe "let ".a:varname."=".a:value
60 elseif type(a:value) == 1
61 exe "let ".a:varname."="."'".a:value."'"
62 else
63 exe "let ".a:varname."=".a:value
64 endif
65 endif
66endfun
67
68" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000069" Netrw Constants: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010070call s:NetrwInit("g:netrw_dirhist_cnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +000071if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +010072 call s:NetrwInit("s:THINLIST",0)
73 call s:NetrwInit("s:LONGLIST",1)
74 call s:NetrwInit("s:WIDELIST",2)
75 call s:NetrwInit("s:TREELIST",3)
76 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +000077endif
78
79" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000080" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1afcace2005-11-25 19:54:28 +000081if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +010082 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +000083 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +010084 elseif executable("curl")
85 let g:netrw_dav_cmd = "curl"
86 else
87 let g:netrw_dav_cmd = ""
88 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000089endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +000090if !exists("g:netrw_fetch_cmd")
91 if executable("fetch")
92 let g:netrw_fetch_cmd = "fetch -o"
93 else
94 let g:netrw_fetch_cmd = ""
95 endif
96endif
97if !exists("g:netrw_ftp_cmd")
98 let g:netrw_ftp_cmd = "ftp"
99endif
100if !exists("g:netrw_http_cmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000101 if executable("elinks")
102 let g:netrw_http_cmd = "elinks"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100103 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000104 elseif executable("links")
105 let g:netrw_http_cmd = "links"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100106 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000107 elseif executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100108 let g:netrw_http_cmd = "curl"
109 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000110 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100111 let g:netrw_http_cmd = "wget"
112 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000113 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100114 let g:netrw_http_cmd = "fetch"
115 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000116 else
117 let g:netrw_http_cmd = ""
118 endif
119endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100120call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
121call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
122call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
123call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
124call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000125
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000126if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000127 \ && exists("g:netrw_use_nt_rcp")
128 \ && g:netrw_use_nt_rcp
129 \ && executable( $SystemRoot .'/system32/rcp.exe')
130 let s:netrw_has_nt_rcp = 1
131 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000132else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000133 let s:netrw_has_nt_rcp = 0
134 let s:netrw_rcpmode = ''
135endif
136
137" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000138" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000139" Cygwin Detection ------- {{{3
140if !exists("g:netrw_cygwin")
141 if has("win32") || has("win95") || has("win64") || has("win16")
142 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
143 let g:netrw_cygwin= 1
144 else
145 let g:netrw_cygwin= 0
146 endif
147 else
148 let g:netrw_cygwin= 0
149 endif
150endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000151" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100152call s:NetrwInit("g:netrw_alto" , &sb)
153call s:NetrwInit("g:netrw_altv" , &spr)
154call s:NetrwInit("g:netrw_banner" , 1)
155call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200156call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100157call s:NetrwInit("g:netrw_chgwin" , -1)
158call s:NetrwInit("g:netrw_compress" , "gzip")
159call s:NetrwInit("g:netrw_ctags" , "ctags")
160if !exists("g:netrw_cursorline")
161 let g:netrw_cursorline= 1
162 let s:netrw_usercul = &cursorline
163 let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar446cb832008-06-24 21:56:24 +0000164endif
165" Default values - d-g ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100166call s:NetrwInit("g:netrw_dirhist_cnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200167call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100168call s:NetrwInit("g:netrw_dirhistmax" , 10)
169call s:NetrwInit("g:netrw_fastbrowse" , 1)
170call s:NetrwInit("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 Moolenaarc0197e22004-09-13 20:26:32 +0000171if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000172 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
173 let g:netrw_ftp_list_cmd = "ls -lF"
174 let g:netrw_ftp_timelist_cmd = "ls -tlF"
175 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000176 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000177 let g:netrw_ftp_list_cmd = "dir"
178 let g:netrw_ftp_timelist_cmd = "dir"
179 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000180 endif
181endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100182call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000183" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100184call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000185if !exists("g:netrw_ignorenetrc")
186 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
187 let g:netrw_ignorenetrc= 1
188 else
189 let g:netrw_ignorenetrc= 0
190 endif
191endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000193if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000194 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
195 " provide a 'pscp' listing command
196 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
197 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
198 endif
199 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
200 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000201 " provide a default listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000202 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000203 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000204" call Decho(g:netrw_ssh_cmd." is not executable")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000205 let g:netrw_list_cmd= ""
206 endif
207endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100208call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000209" Default values - lh-lz ---------- {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +0000210if !exists("g:netrw_localcopycmd")
211 if has("win32") || has("win95") || has("win64") || has("win16")
212 if g:netrw_cygwin
213 let g:netrw_localcopycmd= "cp"
214 else
215 let g:netrw_localcopycmd= "copy"
216 endif
217 elseif has("unix") || has("macunix")
218 let g:netrw_localcopycmd= "cp"
219 else
220 let g:netrw_localcopycmd= ""
221 endif
222endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100223call s:NetrwInit("g:netrw_local_mkdir","mkdir")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000224if !exists("g:netrw_localmovecmd")
225 if has("win32") || has("win95") || has("win64") || has("win16")
226 if g:netrw_cygwin
227 let g:netrw_localmovecmd= "mv"
228 else
229 let g:netrw_localmovecmd= "move"
230 endif
231 elseif has("unix") || has("macunix")
232 let g:netrw_localmovecmd= "mv"
233 else
234 let g:netrw_localmovecmd= ""
235 endif
236endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100237call s:NetrwInit("g:netrw_local_rmdir", "rmdir")
238call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
239" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000240if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000241 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000242endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000243if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000244 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
245endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000246" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100247call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
248call s:NetrwInit("g:netrw_maxfilenamelen", 32)
249call s:NetrwInit("g:netrw_menu" , 1)
250call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
251call s:NetrwInit("g:netrw_mousemaps" , (exists("&mouse") && &mouse =~ '[anh]'))
252call s:NetrwInit("g:netrw_retmap" , 0)
253if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
254 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
255elseif has("win32") || has("win95") || has("win64") || has("win16")
256 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
257else
258 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000259endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260call s:NetrwInit("g:netrw_preview" , 0)
261call s:NetrwInit("g:netrw_scpport" , "-P")
262call s:NetrwInit("g:netrw_sshport" , "-p")
263call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
264call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
265call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
266call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000267" Default values - s ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100268" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
269call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200270call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "silent keepj " : "keepj ")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
272call s:NetrwInit("g:netrw_sort_options" , "")
273call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100275 if has("unix")
276 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
277 else
278 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000279 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000280endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281call s:NetrwInit("g:netrw_special_syntax" , 0)
282call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
283call s:NetrwInit("g:netrw_use_noswf" , 0)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000284" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100285call s:NetrwInit("g:netrw_timefmt","%c")
286call s:NetrwInit("g:netrw_xstrlen",0)
287call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
288call s:NetrwInit("g:netrw_use_errorwindow",1)
289call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200290call s:NetrwInit("g:netrw_winsize",25)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000291" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000292" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100293call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200294if has("win32") || has("win95") || has("win64") || has("win16")
295 call s:NetrwInit("g:netrw_glob_escape",'[]*?`{$')
296else
297 call s:NetrwInit("g:netrw_glob_escape",'[]*?`{~$\')
298endif
299call s:NetrwInit("g:netrw_menu_escape",'./&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100300call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
301call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000302
303" BufEnter event ignored by decho when following variable is true
304" Has a side effect that doau BufReadPost doesn't work, so
305" files read by network transfer aren't appropriately highlighted.
306"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000308" ==============================
309" Netrw Utility Functions: {{{1
310" ==============================
311
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000313" s:NetrwOptionSave: save options and set to "standard" form {{{2
314" 06/08/07 : removed call to NetrwSafeOptions(), either placed
315" immediately after NetrwOptionSave() calls in NetRead
316" and NetWrite, or after the s:NetrwEnew() call in
317" NetrwBrowse.
318" vt: normally its "w:" or "s:" (a variable type)
319fun! s:NetrwOptionSave(vt)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321
Bram Moolenaar446cb832008-06-24 21:56:24 +0000322" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"))
323 if !exists("{a:vt}netrw_optionsave")
324 let {a:vt}netrw_optionsave= 1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000325 else
Bram Moolenaar446cb832008-06-24 21:56:24 +0000326" call Dret("s:NetrwOptionSave : options already saved")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000327 return
328 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200329" call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000330
331 " Save current settings and current directory
332 let s:yykeep = @@
333 if exists("&l:acd")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000334 let {a:vt}netrw_acdkeep = &l:acd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000335 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336 let {a:vt}netrw_aikeep = &l:ai
337 let {a:vt}netrw_awkeep = &l:aw
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200338 let {a:vt}netrw_bombkeep = &l:bomb
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339 let {a:vt}netrw_cikeep = &l:ci
340 let {a:vt}netrw_cinkeep = &l:cin
341 let {a:vt}netrw_cinokeep = &l:cino
342 let {a:vt}netrw_comkeep = &l:com
343 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200344 let {a:vt}netrw_diffkeep = &l:diff
Bram Moolenaar9964e462007-05-05 17:54:07 +0000345 if g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +0000346 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar9964e462007-05-05 17:54:07 +0000347 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000348 let {a:vt}netrw_fokeep = &l:fo " formatoptions
349 let {a:vt}netrw_gdkeep = &l:gd " gdefault
350 let {a:vt}netrw_hidkeep = &l:hidden
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200351 let {a:vt}netrw_imkeep = &l:im
Bram Moolenaar446cb832008-06-24 21:56:24 +0000352 let {a:vt}netrw_magickeep = &l:magic
353 let {a:vt}netrw_repkeep = &l:report
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200354 let {a:vt}netrw_selkeep = &l:sel
Bram Moolenaar446cb832008-06-24 21:56:24 +0000355 let {a:vt}netrw_spellkeep = &l:spell
356 let {a:vt}netrw_twkeep = &l:tw " textwidth
357 let {a:vt}netrw_wigkeep = &l:wig " wildignore
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358 if has("win32") && !has("win95")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000359 let {a:vt}netrw_swfkeep = &l:swf " swapfile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000361 if &go =~ 'a' | silent! let {a:vt}netrw_regstar = @* | endif
362 silent! let {a:vt}netrw_regslash= @/
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363
Bram Moolenaar446cb832008-06-24 21:56:24 +0000364" call Dret("s:NetrwOptionSave : win#".winnr()." buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365endfun
366
367" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000368" s:NetrwOptionRestore: restore options {{{2
369fun! s:NetrwOptionRestore(vt)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")." winnr($)=".winnr("$"))
Bram Moolenaar446cb832008-06-24 21:56:24 +0000371 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000372" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000373" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 return
375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000376 unlet {a:vt}netrw_optionsave
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377
378 if exists("&acd")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000379 if exists("{a:vt}netrw_acdkeep")
380" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
381 let curdir = getcwd()
382 let &l:acd = {a:vt}netrw_acdkeep
383 unlet {a:vt}netrw_acdkeep
384 if &l:acd
385" call Decho("exe keepjumps lcd ".fnameescape(curdir)) " NOTE: was g:netrw_fname_escape for some reason
386 try
387 if !exists("&l:acd") && !&l:acd
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200388 exe 'keepj lcd '.fnameescape(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000389 endif
390 catch /^Vim\%((\a\+)\)\=:E472/
391 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".curdir."> (permissions?)",61)
392 endtry
393 endif
394 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000395 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000396 if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif
397 if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200398 if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399 if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif
400 if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif
401 if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif
402 if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif
403 if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200404 if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405 if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
406 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
407 if exists("{a:vt}netrw_dirkeep") |exe "keepjumps lcd ".fnameescape(dirkeep)|unlet {a:vt}netrw_dirkeep |endif
408 endif
409 if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif
410 if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif
411 if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200412 if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000413 if exists("{a:vt}netrw_magic") |let &l:magic = {a:vt}netrw_magic |unlet {a:vt}netrw_magic |endif
414 if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200415 if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000416 if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif
417 if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif
418 if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif
419 if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif
420 if exists("{a:vt}netrw_swfkeep")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000421 if &directory == ""
422 " user hasn't specified a swapfile directory;
423 " netrw will temporarily set the swapfile directory
424 " to the current directory as returned by getcwd().
425 let &l:directory = getcwd()
Bram Moolenaar446cb832008-06-24 21:56:24 +0000426 silent! let &l:swf = {a:vt}netrw_swfkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +0000427 setlocal directory=
Bram Moolenaar446cb832008-06-24 21:56:24 +0000428 unlet {a:vt}netrw_swfkeep
429 elseif &l:swf != {a:vt}netrw_swfkeep
430 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
431 silent! let &l:swf= {a:vt}netrw_swfkeep
432 unlet {a:vt}netrw_swfkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +0000433 endif
434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000435 if exists("{a:vt}netrw_regstar") |silent! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif
436 if exists("{a:vt}netrw_regslash")|silent! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000437
Bram Moolenaar446cb832008-06-24 21:56:24 +0000438" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
439" call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist"))
Bram Moolenaarc236c162008-07-13 17:41:49 +0000440" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200441" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"))
Bram Moolenaar446cb832008-06-24 21:56:24 +0000442" call Dret("s:NetrwOptionRestore : win#".winnr()." buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000443endfun
444
445" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000446" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000447fun! s:NetrwSafeOptions()
Bram Moolenaar5c736222010-01-06 20:54:52 +0100448" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
449" call Decho("win#".winnr()."'s ft=".&ft)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000450 setlocal cino=
451 setlocal com=
452 setlocal cpo-=aA
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453 if exists("&acd") | setlocal noacd | endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200454 setlocal nocin noai nobomb noci magic nospell nohid wig= noaw noim
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455 setlocal fo=nroql2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000456 setlocal tw=0
457 setlocal report=10000
Bram Moolenaar5c736222010-01-06 20:54:52 +0100458 setlocal isk+=@ isk+=* isk+=/
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200459 setlocal sel=inclusive
Bram Moolenaar9964e462007-05-05 17:54:07 +0000460 if g:netrw_use_noswf && has("win32") && !has("win95")
461 setlocal noswf
462 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200463 call s:NetrwCursorline()
Bram Moolenaar5c736222010-01-06 20:54:52 +0100464
465 " allow the user to override safe options
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200466" call Decho("ft<".&ft."> ei=".&ei)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100467 if &ft == "netrw"
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200468" call Decho("do any netrw FileType autocmds")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100469 silent keepalt keepjumps doau FileType netrw
470 endif
471
Bram Moolenaar446cb832008-06-24 21:56:24 +0000472" call Decho("fo=".&fo.(exists("&acd")? " acd=".&acd : " acd doesn't exist"))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473" call Dret("s:NetrwSafeOptions")
474endfun
475
Bram Moolenaar446cb832008-06-24 21:56:24 +0000476" ---------------------------------------------------------------------
477" netrw#NetrwClean: remove netrw {{{2
478" supports :NetrwClean -- remove netrw from first directory on runtimepath
479" :NetrwClean! -- remove netrw from all directories on runtimepath
480fun! netrw#NetrwClean(sys)
481" call Dfunc("netrw#NetrwClean(sys=".a:sys.")")
482
483 if a:sys
484 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
485 else
486 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
487 endif
488" call Decho("choice=".choice)
489 let diddel= 0
490 let diddir= ""
491
492 if choice == 1
493 for dir in split(&rtp,',')
494 if filereadable(dir."/plugin/netrwPlugin.vim")
495" call Decho("removing netrw-related files from ".dir)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000496 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
497 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
498 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
499 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
500 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
501 if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000502 let diddir= dir
503 let diddel= diddel + 1
504 if !a:sys|break|endif
505 endif
506 endfor
507 endif
508
509 echohl WarningMsg
510 if diddel == 0
511 echomsg "netrw is either not installed or not removable"
512 elseif diddel == 1
513 echomsg "removed one copy of netrw from <".diddir.">"
514 else
515 echomsg "removed ".diddel." copies of netrw"
516 endif
517 echohl None
518
519" call Dret("netrw#NetrwClean")
520endfun
521
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522" ---------------------------------------------------------------------
523" netrw#Nread: {{{2
524fun! netrw#Nread(mode,fname)
525" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
526 call netrw#NetrwSavePosn()
527 call netrw#NetRead(a:mode,a:fname)
528 call netrw#NetrwRestorePosn()
529" call Dret("netrw#Nread")
530endfun
531
Bram Moolenaar9964e462007-05-05 17:54:07 +0000532" ------------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000533" Netrw Transfer Functions: {{{1
534" ===============================
535
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000537" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000538" mode: =0 read remote file and insert before current line
539" =1 read remote file and insert after current line
540" =2 replace with remote file
541" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000542fun! netrw#NetRead(mode,...)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000543" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000544
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +0000546 call s:NetrwOptionSave("w:")
547 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200548 call s:RestoreCursorline()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000549
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000551 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000552 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000553 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000554 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000555 elseif a:mode == 2 " replace with remote file
556 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000557 elseif a:mode == 3 " skip read of file (leave as temporary)
558 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000559 else
560 exe a:mode
561 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000562 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000563 let ichoice = (a:0 == 0)? 0 : 1
564" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
565
Bram Moolenaar5c736222010-01-06 20:54:52 +0100566 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +0000567 let tmpfile= s:GetTempfile("")
568 if tmpfile == ""
569" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000570 return
571 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000572
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000573 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000574
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000575 " attempt to repeat with previous host-file-etc
576 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000577" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000578 let choice = b:netrw_lastfile
579 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000580
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000581 else
582 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000583" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000584
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000585 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000586 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000587 echomsg 'NetRead Usage:'
588 echomsg ':Nread machine:path uses rcp'
589 echomsg ':Nread "machine path" uses ftp with <.netrc>'
590 echomsg ':Nread "machine id password path" uses ftp'
591 echomsg ':Nread dav://machine[:port]/path uses cadaver'
592 echomsg ':Nread fetch://machine/path uses fetch'
593 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
594 echomsg ':Nread http://[user@]machine/path uses http wget'
595 echomsg ':Nread rcp://[user@]machine/path uses rcp'
596 echomsg ':Nread rsync://machine[:port]/path uses rsync'
597 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
598 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000599 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000600 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000601
Bram Moolenaar9964e462007-05-05 17:54:07 +0000602 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000603 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000604" call Decho("reconstructing choice")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000605 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000606 " case "..."
607 let choice=strpart(choice,1,strlen(choice)-2)
608 else
609 " case "... ... ..."
610 let choice = strpart(choice,1,strlen(choice)-1)
611 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000612
Bram Moolenaar9964e462007-05-05 17:54:07 +0000613 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000614 let wholechoice = wholechoice . " " . choice
615 let ichoice = ichoice + 1
616 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000617 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000618 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000619 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000620" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000621 return
622 endif
623 let choice= a:{ichoice}
624 endwhile
625 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
626 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 endif
628 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000630" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000631 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000632
Bram Moolenaar5c736222010-01-06 20:54:52 +0100633 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +0000634 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100635 if !exists("b:netrw_method") || b:netrw_method < 0
636" call Dfunc("netrw#NetRead : unsupported method")
637 return
638 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000639 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000640
Bram Moolenaar446cb832008-06-24 21:56:24 +0000641 " Check if NetrwBrowse() should be handling this request
642" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000643 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^http://'
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000644" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200645 keepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000646" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000647 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000650 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +0100651 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000652 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000653 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
654 echo "(netrw) Processing your read request..."
655 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000656
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000657 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100658 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000659 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000660" call Decho("read via rcp (method #1)")
Bram Moolenaard68071d2006-05-02 22:08:30 +0000661 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000662 " ER: on Win2K" rcp machine[.user]:file tmpfile
663 " ER: if machine contains '.' adding .user is required (use $USERNAME)
664 " ER: the tmpfile is full path: rcp sees C:\... as host C
665 if s:netrw_has_nt_rcp == 1
666 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
667 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
668 else
669 " Any way needed it machine contains a '.'
670 let uid_machine = g:netrw_machine .'.'. $USERNAME
671 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000673 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
674 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
675 else
676 let uid_machine = g:netrw_machine
677 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +0000679" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100680 exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000681 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000682 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000683
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000684 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100685 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000686 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000687" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000688 let netrw_fname= b:netrw_fname
Bram Moolenaar446cb832008-06-24 21:56:24 +0000689 call s:SaveBufVars()|new|call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000690 let filtbuf= bufnr("%")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000691 setlocal ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200692 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000693" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000694 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200695 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000696" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000697 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000698 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
699" call Decho("filter input: ".getline(line("$")))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000700 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +0000701" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine." ".g:netrw_port,1))
702 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine." ".g:netrw_port,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000703 else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000704" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
705 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000706 endif
707 " 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 +0000708 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +0000709 let debugkeep = &debug
Bram Moolenaar9964e462007-05-05 17:54:07 +0000710 setlocal debug=msg
711 call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000712 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000713 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000714 call s:SaveBufVars()
715 bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +0100716 if bufname("%") == "" && getline("$") == "" && line('$') == 1
717 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000718 q!
719 endif
720 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +0000721 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000722 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000723
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000724 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100725 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000726 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
727 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000728" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000729 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000730 call s:SaveBufVars()|new|call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000731 let filtbuf= bufnr("%")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000732 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000733 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200734 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +0000735" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000736 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200737 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +0000738" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000739 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000741 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200742 keepj put =g:netrw_uid
Bram Moolenaar446cb832008-06-24 21:56:24 +0000743" call Decho("filter input: ".getline('.'))
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200744 keepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000745" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000746 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200747 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000748" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000749 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000750
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000751 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200752 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +0000753" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000754 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000755 if exists("g:netrw_ftpextracmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000756 put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +0000757" call Decho("filter input: ".getline('.'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000758 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200759 keepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +0000760" call Decho("filter input: ".getline('.'))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000762 " perform ftp:
763 " -i : turns off interactive prompting from ftp
764 " -n unix : DON'T use <.netrc>, even though it exists
765 " -n win32: quit being obnoxious about password
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000766 norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000767" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000768 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000769 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
770 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000771" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000772 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000773 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000774 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000775 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000776 call s:SaveBufVars()|bd!|call s:RestoreBufVars()
777 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000778 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000779
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000780 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100781 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000782 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000783" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000784 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +0000785 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000786 else
787 let useport= ""
788 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100789" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
Bram Moolenaarc236c162008-07-13 17:41:49 +0000790 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000791 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000792 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000793
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000794 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100795 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000796 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000797" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000798 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000799 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000800 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000801 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000802" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000803 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000804 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000805
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000806 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
807 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000808" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000809 if exists("g:netrw_http_xcmd")
810" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
811 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
812 else
813" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1))
814 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)
815 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000816 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000817
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000818 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000819 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000820" call Decho(("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000821 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
822 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000823" call Decho("netrw_html<".netrw_html.">")
824" call Decho("netrw_tag <".netrw_tag.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000825" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1))
826 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000827 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000828" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000829 exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
830 endif
831 let b:netrw_lastfile = choice
Bram Moolenaar9964e462007-05-05 17:54:07 +0000832 setlocal ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000833
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000834 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100835 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000836 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000837" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000838
Bram Moolenaar5c736222010-01-06 20:54:52 +0100839 if !executable(g:netrw_dav_cmd)
840 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
841" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
842 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000843 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100844 if g:netrw_dav_cmd =~ "curl"
845" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
846 exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
847 else
848 " Construct execution string (four lines) which will be passed through filter
849 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
850 new
851 setlocal ff=unix
852 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200853 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +0100854 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200855 keepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +0100856 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200857 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
858 keepj put ='get '.netrw_fname.' '.tmpfile
859 keepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000860
Bram Moolenaar5c736222010-01-06 20:54:52 +0100861 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200862 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000863" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100864 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
865 bd!
866 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000867 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000868 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000869
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000870 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100871 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000872 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000873" call Decho("read via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000874" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
875 exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000876 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000877 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000878
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000879 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100880 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000881 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000882 elseif b:netrw_method == 8
Bram Moolenaar9964e462007-05-05 17:54:07 +0000883" call Decho("read via fetch (method #8)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000884 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000885 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000886 call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000887 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000888" call Dret("NetRead")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000889 endif
890 if exists("g:netrw_option") && g:netrw_option == ":http"
891 let netrw_option= "http"
892 else
893 let netrw_option= "ftp"
894 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000895" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000896
Bram Moolenaar446cb832008-06-24 21:56:24 +0000897 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +0000898" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
899 exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000900 else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000901" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
902 exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000903 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000904
Bram Moolenaar446cb832008-06-24 21:56:24 +0000905 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000906 let b:netrw_lastfile = choice
Bram Moolenaar9964e462007-05-05 17:54:07 +0000907 setlocal ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000908
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000909 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100910 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000911 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +0000912" call Decho("read via sftp (method #9)")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000913" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
914 exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +0000915 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000916 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000917
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000918 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +0100919 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000920 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000921 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000922 endif
923 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000924
Bram Moolenaar5c736222010-01-06 20:54:52 +0100925 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000926 if exists("b:netrw_method")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000927" call Decho("cleanup b:netrw_method and b:netrw_fname")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000928 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000929 unlet b:netrw_fname
930 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200931 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000932" call Decho("cleanup by deleting tmpfile<".tmpfile.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100933 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000935 call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +0000936
Bram Moolenaar9964e462007-05-05 17:54:07 +0000937" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000938endfun
939
940" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +0000941" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000942fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +0000943" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000944
Bram Moolenaar5c736222010-01-06 20:54:52 +0100945 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000946 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +0000947 call s:NetrwOptionSave("w:")
948 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000949
Bram Moolenaar5c736222010-01-06 20:54:52 +0100950 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +0000951 let tmpfile= s:GetTempfile("")
952 if tmpfile == ""
953" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000954 return
955 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000956
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000957 if a:0 == 0
958 let ichoice = 0
959 else
960 let ichoice = 1
961 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000962
Bram Moolenaar9964e462007-05-05 17:54:07 +0000963 let curbufname= expand("%")
964" call Decho("curbufname<".curbufname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000965 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +0000966 " For binary writes, always write entire file.
967 " (line numbers don't really make sense for that).
968 " Also supports the writing of tar and zip files.
Bram Moolenaarc236c162008-07-13 17:41:49 +0000969" call Decho("(write entire file) silent exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200970 exe "silent keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000971 elseif g:netrw_cygwin
972 " write (selected portion of) file to temporary
973 let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','')
Bram Moolenaarc236c162008-07-13 17:41:49 +0000974" call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200975 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000976 else
977 " write (selected portion of) file to temporary
Bram Moolenaarc236c162008-07-13 17:41:49 +0000978" call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200979 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000980 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000981
Bram Moolenaar9964e462007-05-05 17:54:07 +0000982 if curbufname == ""
983 " if the file is [No Name], and one attempts to Nwrite it, the buffer takes
984 " on the temporary file's name. Deletion of the temporary file during
985 " cleanup then causes an error message.
986 0file!
987 endif
988
Bram Moolenaar5c736222010-01-06 20:54:52 +0100989 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000990 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000991
Bram Moolenaar9964e462007-05-05 17:54:07 +0000992 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000993 " attempt to repeat with previous host-file-etc
994 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000995" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000996 let choice = b:netrw_lastfile
997 let ichoice= ichoice + 1
998 else
999 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001001 " Reconstruct Choice if choice starts with '"'
1002 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001003 echomsg 'NetWrite Usage:"'
1004 echomsg ':Nwrite machine:path uses rcp'
1005 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
1006 echomsg ':Nwrite "machine id password path" uses ftp'
1007 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
1008 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
1009 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
1010 echomsg ':Nwrite rcp://machine/path uses rcp'
1011 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
1012 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
1013 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001014 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001015 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001016
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001017 elseif match(choice,"^\"") != -1
1018 if match(choice,"\"$") != -1
1019 " case "..."
1020 let choice=strpart(choice,1,strlen(choice)-2)
1021 else
1022 " case "... ... ..."
1023 let choice = strpart(choice,1,strlen(choice)-1)
1024 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001025
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001026 while match(choice,"\"$") == -1
1027 let wholechoice= wholechoice . " " . choice
1028 let ichoice = ichoice + 1
1029 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001030 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001031 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001032 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001033" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001034 return
1035 endif
1036 let choice= a:{ichoice}
1037 endwhile
1038 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1039 endif
1040 endif
1041 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001042 let ichoice= ichoice + 1
Bram Moolenaar9964e462007-05-05 17:54:07 +00001043" call Decho("choice<" . choice . "> ichoice=".ichoice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001044
Bram Moolenaar9964e462007-05-05 17:54:07 +00001045 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar446cb832008-06-24 21:56:24 +00001046 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001047 if !exists("b:netrw_method") || b:netrw_method < 0
1048" call Dfunc("netrw#NetWrite : unsupported method")
1049 return
1050 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001051
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001052 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01001053 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001054 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001055 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
1056 echo "(netrw) Processing your write request..."
Bram Moolenaar446cb832008-06-24 21:56:24 +00001057" call Decho("(netrw) Processing your write request...")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001058 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001059
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001060 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001061 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001062 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001063" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001064 if s:netrw_has_nt_rcp == 1
1065 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1066 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
1067 else
1068 let uid_machine = g:netrw_machine .'.'. $USERNAME
1069 endif
1070 else
1071 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1072 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1073 else
1074 let uid_machine = g:netrw_machine
1075 endif
1076 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001077" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
1078 exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001079 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001081 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001082 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001083 elseif b:netrw_method == 2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001084" call Decho("write via ftp+.netrc (method #2)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001085 let netrw_fname = b:netrw_fname
1086
1087 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1088 let bhkeep = &l:bh
1089 let curbuf = bufnr("%")
1090 setlocal bh=hide
1091 enew
1092
Bram Moolenaar446cb832008-06-24 21:56:24 +00001093" call Decho("filter input window#".winnr())
Bram Moolenaar8299df92004-07-10 09:47:34 +00001094 setlocal ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001095 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001096" call Decho("filter input: ".getline('$'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001097 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001098 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001099" call Decho("filter input: ".getline("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001100 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001101 call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
1102" call Decho("filter input: ".getline("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00001104" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1105 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00001107" call Decho("filter input window#".winnr())
Bram Moolenaarc236c162008-07-13 17:41:49 +00001108" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1109 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 endif
1111 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1112 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001113 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001114 call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001115 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001116 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001118
1119 " remove enew buffer (quietly)
1120 let filtbuf= bufnr("%")
1121 exe curbuf."b!"
1122 let &l:bh = bhkeep
1123 exe filtbuf."bw!"
1124
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001126
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001127 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001128 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001129 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01001130 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaar9964e462007-05-05 17:54:07 +00001131" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001132 let netrw_fname = b:netrw_fname
1133 let bhkeep = &l:bh
1134
1135 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1136 let curbuf = bufnr("%")
1137 setlocal bh=hide
1138 enew
Bram Moolenaar8299df92004-07-10 09:47:34 +00001139 setlocal ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01001140
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001141 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001142 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00001143" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001144 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001145 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00001146" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001147 endif
1148 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001149 keepj put =g:netrw_uid
Bram Moolenaar446cb832008-06-24 21:56:24 +00001150" call Decho("filter input: ".getline('.'))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001151 keepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001152" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001153 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001154 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001155" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001156 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001157 keepj put =g:netrw_ftpmode
Bram Moolenaar5c736222010-01-06 20:54:52 +01001158" call Decho("filter input: ".getline('$'))
1159 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001160 keepj put =g:netrw_ftpextracmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01001161" call Decho("filter input: ".getline("$"))
1162 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001163 keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001164" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001165 " save choice/id/password for future use
1166 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001167
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001168 " perform ftp:
1169 " -i : turns off interactive prompting from ftp
1170 " -n unix : DON'T use <.netrc>, even though it exists
1171 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001172 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001173" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001174 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001175 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1176 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001177 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001178 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001179 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001180 let mod=1
1181 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001182
1183 " remove enew buffer (quietly)
1184 let filtbuf= bufnr("%")
1185 exe curbuf."b!"
1186 let &l:bh= bhkeep
1187 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001188
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001189 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001190 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001191 elseif b:netrw_method == 4
Bram Moolenaar9964e462007-05-05 17:54:07 +00001192" call Decho("write via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001193 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00001194 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001195 else
1196 let useport= ""
1197 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001198" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
1199 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001200 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001201
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001202 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001203 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001204 elseif b:netrw_method == 5
Bram Moolenaar9964e462007-05-05 17:54:07 +00001205" call Decho("write via http (method #5)")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001206 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001207 call netrw#ErrorMsg(s:ERROR,"currently <netrw.vim> does not support writing using http:",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001208 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001209
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001210 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001211 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001212 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001213" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001214
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001215 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01001216 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
1217 let bhkeep = &l:bh
1218
1219 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1220 let curbuf = bufnr("%")
1221 setlocal bh=hide
1222 enew
1223
Bram Moolenaar8299df92004-07-10 09:47:34 +00001224 setlocal ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001225 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001226 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001227 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001228 keepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001229 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001230 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001231 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00001232 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001233 keepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001234
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001235 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001236 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001237" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001238 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01001239
1240 " remove enew buffer (quietly)
1241 let filtbuf= bufnr("%")
1242 exe curbuf."b!"
1243 let &l:bh = bhkeep
1244 exe filtbuf."bw!"
1245
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001246 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001247
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001248 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001249 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001250 elseif b:netrw_method == 7
Bram Moolenaar9964e462007-05-05 17:54:07 +00001251" call Decho("write via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001252" call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
1253 exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001254 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001255
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001256 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001257 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001258 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +00001259" call Decho("read via sftp (method #9)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001260 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1262 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1263 else
1264 let uid_machine = g:netrw_machine
1265 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001266
1267 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
1268 let bhkeep = &l:bh
1269 let curbuf = bufnr("%")
1270 setlocal bh=hide
1271 enew
1272
Bram Moolenaar8299df92004-07-10 09:47:34 +00001273 setlocal ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01001274 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001275" call Decho("filter input: ".getline('.'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001276" call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
1277 exe s:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001278 let filtbuf= bufnr("%")
1279 exe curbuf."b!"
1280 let &l:bh = bhkeep
1281 exe filtbuf."bw!"
1282 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001283
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001284 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001285 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001286 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001287 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001289 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001290
Bram Moolenaar5c736222010-01-06 20:54:52 +01001291 " NetWrite: Cleanup: {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001292" call Decho("cleanup")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001293 if s:FileReadable(tmpfile)
1294" call Decho("tmpfile<".tmpfile."> readable, will now delete it")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001295 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001296 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001297 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001298
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001299 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001300 " restore modifiability; usually equivalent to set nomod
1301 let &mod= mod
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001303
Bram Moolenaar5c736222010-01-06 20:54:52 +01001304 " restore equalalways
Bram Moolenaar9964e462007-05-05 17:54:07 +00001305" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001306endfun
1307
1308" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001310" uses NetRead to get a copy of the file into a temporarily file,
1311" then sources that file,
1312" then removes that file.
1313fun! netrw#NetSource(...)
1314" call Dfunc("netrw#NetSource() a:0=".a:0)
1315 if a:0 > 0 && a:1 == '?'
1316 " give help
1317 echomsg 'NetSource Usage:'
1318 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
1319 echomsg ':Nsource fetch://machine/path uses fetch'
1320 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1321 echomsg ':Nsource http://[user@]machine/path uses http wget'
1322 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
1323 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
1324 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
1325 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
1326 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001327 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001328 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001329 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00001330 call netrw#NetRead(3,a:{i})
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001331" call Decho("(netrw#NetSource) s:netread_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001332 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001333" call Decho("(netrw#NetSource) exe so ".fnameescape(s:netrw_tmpfile))
1334 exe "so ".fnameescape(s:netrw_tmpfile)
1335" call Decho("(netrw#NetSource) delete(".s:netrw_tmpfile.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001336 call delete(s:netrw_tmpfile)
1337 unlet s:netrw_tmpfile
1338 else
1339 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
1340 endif
1341 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001342 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00001343 endif
1344" call Dret("netrw#NetSource")
1345endfun
1346
1347" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00001348" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001349" readcmd == %r : replace buffer with newly read file
1350" == 0r : read file at top of buffer
1351" == r : read file after current line
1352" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001353fun! s:NetrwGetFile(readcmd, tfile, method)
1354" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001355
1356 " readcmd=='t': simply do nothing
1357 if a:readcmd == 't'
Bram Moolenaarc236c162008-07-13 17:41:49 +00001358" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001359" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001360 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001361 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001362
Bram Moolenaar9964e462007-05-05 17:54:07 +00001363 " get name of remote filename (ie. url and all)
1364 let rfile= bufname("%")
1365" call Decho("rfile<".rfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001366
Bram Moolenaar9964e462007-05-05 17:54:07 +00001367 if exists("*NetReadFixup")
1368 " for the use of NetReadFixup (not otherwise used internally)
1369 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001370 endif
1371
Bram Moolenaar9964e462007-05-05 17:54:07 +00001372 if a:readcmd[0] == '%'
1373 " get file into buffer
1374" call Decho("get file into buffer")
1375
1376 " rename the current buffer to the temp file (ie. tfile)
1377 if g:netrw_cygwin
1378 let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','')
1379 else
1380 let tfile= a:tfile
1381 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001382" call Decho("exe sil! keepalt file ".fnameescape(tfile))
1383 exe "sil! keepalt file ".fnameescape(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001384
1385 " edit temporary file (ie. read the temporary file in)
1386 if rfile =~ '\.zip$'
1387" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
1388 call zip#Browse(tfile)
1389 elseif rfile =~ '\.tar$'
1390" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
1391 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001392 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001393" call Decho("handling remote gzip-compressed tar file")
1394 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001395 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001396" call Decho("handling remote bz2-compressed tar file")
1397 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001398 elseif rfile =~ '\.tar\.xz$'
1399" call Decho("handling remote xz-compressed tar file")
1400 call tar#Browse(tfile)
1401 elseif rfile =~ '\.txz$'
1402" call Decho("handling remote xz-compressed tar file (.txz)")
1403 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001404 else
1405" call Decho("edit temporary file")
1406 e!
1407 endif
1408
1409 " rename buffer back to remote filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02001410" call Decho("exe sil! keepalt file ".fnameescape(rfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001411 exe "sil! keepalt file ".fnameescape(rfile)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001412 filetype detect
Bram Moolenaar9964e462007-05-05 17:54:07 +00001413" call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
1414 let line1 = 1
1415 let line2 = line("$")
1416
1417 elseif s:FileReadable(a:tfile)
1418 " read file after current line
1419" call Decho("read file<".a:tfile."> after current line")
1420 let curline = line(".")
1421 let lastline= line("$")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001422" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline)
1423 exe a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001424 let line1= curline + 1
1425 let line2= line("$") - lastline + 1
1426
1427 else
1428 " not readable
Bram Moolenaarc236c162008-07-13 17:41:49 +00001429" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001430" call Decho("tfile<".a:tfile."> not readable")
1431 call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001432" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001433 return
1434 endif
1435
1436 " User-provided (ie. optional) fix-it-up command
1437 if exists("*NetReadFixup")
1438" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
1439 call NetReadFixup(a:method, line1, line2)
1440" else " Decho
1441" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
1442 endif
1443
Bram Moolenaar5c736222010-01-06 20:54:52 +01001444 if has("gui") && has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00001445 " update the Buffers menu
1446 call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00001447 endif
1448
1449" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
1450
1451 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00001452" redraw!
1453
Bram Moolenaarc236c162008-07-13 17:41:49 +00001454" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001455" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001456endfun
1457
Bram Moolenaar9964e462007-05-05 17:54:07 +00001458" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001459" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01001460" Input:
1461" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
1462" Output:
1463" b:netrw_method= 1: rcp
1464" 2: ftp + <.netrc>
1465" 3: ftp + machine, id, password, and [path]filename
1466" 4: scp
1467" 5: http (wget)
1468" 6: dav
1469" 7: rsync
1470" 8: fetch
1471" 9: sftp
1472" g:netrw_machine= hostname
1473" b:netrw_fname = filename
1474" g:netrw_port = optional port number (for ftp)
1475" g:netrw_choice = copy of input url (choice)
1476fun! s:NetrwMethod(choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001477" call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001478
Bram Moolenaar5c736222010-01-06 20:54:52 +01001479 " record current g:netrw_machine, if any
1480 " curmachine used if protocol == ftp and no .netrc
1481 if exists("g:netrw_machine")
1482 let curmachine= g:netrw_machine
1483" call Decho("curmachine<".curmachine.">")
1484 else
1485 let curmachine= "N O T A HOST"
1486 endif
1487
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001488 " initialization
1489 let b:netrw_method = 0
1490 let g:netrw_machine = ""
1491 let b:netrw_fname = ""
1492 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001493 let g:netrw_choice = a:choice
1494
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001495 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001496 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00001497 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
1498 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001499 " rcpurm : rcp://[user@]host/filename Use rcp
1500 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001501 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001502 " httpurm : http://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01001503 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001504 " rsyncurm : rsync://host[:port]/path Use rsync
1505 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
1506 " sftpurm : sftp://[user@]host/filename Use scp
1507 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
1508 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
1509 let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
Bram Moolenaar83bab712005-08-01 21:58:57 +00001510 let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001511 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001512 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001513 let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001514 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001515 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
1516 let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
1517 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001518
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001519" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001520 " Determine Method
1521 " rcp://user@hostname/...path-to-file
1522 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001523" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00001524 let b:netrw_method = 1
1525 let userid = substitute(a:choice,rcpurm,'\1',"")
1526 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
1527 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001528 if userid != ""
1529 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001531
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001532 " scp://user@hostname/...path-to-file
1533 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001534" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001535 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00001536 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
1537 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
1538 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001540 " http://user@hostname/...path-to-file
1541 elseif match(a:choice,httpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001542" call Decho("http://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001543 let b:netrw_method = 5
1544 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
1545 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001546
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001547 " dav://hostname[:port]/..path-to-file..
1548 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001549" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001550 let b:netrw_method= 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001551 if a:choice =~ '^s'
1552 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
1553 else
1554 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
1555 endif
1556 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001557
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001558 " rsync://user@hostname/...path-to-file
1559 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001560" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001561 let b:netrw_method = 7
1562 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
1563 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001564
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001565 " ftp://[user@]hostname[[:#]port]/...path-to-file
1566 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001567" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001568 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001569 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
1570 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
1571 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001572" call Decho("g:netrw_machine<".g:netrw_machine.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001573 if userid != ""
1574 let g:netrw_uid= userid
1575 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001576 if exists("s:netrw_passwd") && curmachine != g:netrw_machine
1577 " if there's a change in hostname, require password re-entry
1578 unlet s:netrw_passwd
1579 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001580 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001581 let b:netrw_method = 3
1582 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00001583 if s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001584 let b:netrw_method= 2
1585 else
1586 if !exists("g:netrw_uid") || g:netrw_uid == ""
1587 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00001588 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001589 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001590 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001591 endif
1592 let b:netrw_method= 3
1593 endif
1594 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001595
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001596 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001597" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001598 let b:netrw_method = 8
1599 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
1600 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
1601 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
1602 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001603
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001604 " Issue an ftp : "machine id password [path/]filename"
1605 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001606" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001608 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
1609 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001610 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001611 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001612
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001613 " Issue an ftp: "hostname [path/]filename"
1614 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001615" call Decho("(ftp) host file")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001616 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001617 let b:netrw_method = 3
1618 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1619 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001620
Bram Moolenaar9964e462007-05-05 17:54:07 +00001621 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001622 let b:netrw_method = 2
1623 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
1624 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
1625 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001626
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001627 " sftp://user@hostname/...path-to-file
1628 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001629" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001630 let b:netrw_method = 9
1631 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
1632 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001633
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001634 " Issue an rcp: hostname:filename" (this one should be last)
1635 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001636" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001637 let b:netrw_method = 1
1638 let userid = substitute(a:choice,rcphf,'\2',"")
1639 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
1640 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001641" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
1642" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
1643" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
1644" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001645 if userid != ""
1646 let g:netrw_uid= userid
1647 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001649 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001650 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001651 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001652 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001653 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 endif
Bram Moolenaar81695252004-12-29 20:58:21 +00001655
1656 " remove any leading [:#] from port number
1657 if g:netrw_port != ""
1658 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
1659 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001660
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001661" call Decho("a:choice <".a:choice.">")
1662" call Decho("b:netrw_method <".b:netrw_method.">")
1663" call Decho("g:netrw_machine<".g:netrw_machine.">")
1664" call Decho("g:netrw_port <".g:netrw_port.">")
1665" if exists("g:netrw_uid") "Decho
1666" call Decho("g:netrw_uid <".g:netrw_uid.">")
1667" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00001668" if exists("s:netrw_passwd") "Decho
1669" call Decho("s:netrw_passwd <".s:netrw_passwd.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001670" endif "Decho
1671" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001672" call Dret("NetrwMethod : b:netrw_method=".b:netrw_method)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674
1675" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00001676" NetReadFixup: this sort of function is typically written by the user {{{2
1677" to handle extra junk that their system's ftp dumps
1678" into the transfer. This function is provided as an
1679" example and as a fix for a Windows 95 problem: in my
1680" experience, win95's ftp always dumped four blank lines
1681" at the end of the transfer.
1682if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
1683 fun! NetReadFixup(method, line1, line2)
1684" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001685
1686 " sanity checks -- attempt to convert inputs to integers
1687 let method = a:method + 0
1688 let line1 = a:line1 + 0
1689 let line2 = a:line2 + 0
1690 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
1691" call Dret("NetReadFixup")
1692 return
1693 endif
1694
Bram Moolenaar9964e462007-05-05 17:54:07 +00001695 if method == 3 " ftp (no <.netrc>)
1696 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01001697 if fourblanklines >= line1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001698 exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01001699 call histdel("/",-1)
1700 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001701 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001702
Bram Moolenaar9964e462007-05-05 17:54:07 +00001703" call Dret("NetReadFixup")
1704 endfun
1705endif
1706
1707" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001708" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709" Usage: :call NetUserPass() -- will prompt for userid and password
1710" :call NetUserPass("uid") -- will prompt for password
1711" :call NetUserPass("uid","password") -- sets global userid and password
1712fun! NetUserPass(...)
1713
1714 " get/set userid
1715 if a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001716" call Dfunc("NetUserPass(a:0<".a:0.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717 if !exists("g:netrw_uid") || g:netrw_uid == ""
1718 " via prompt
1719 let g:netrw_uid= input('Enter username: ')
1720 endif
1721 else " from command line
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001722" call Dfunc("NetUserPass(a:1<".a:1.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 let g:netrw_uid= a:1
1724 endif
1725
1726 " get password
1727 if a:0 <= 1 " via prompt
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001728" call Decho("a:0=".a:0." case <=1:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001729 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 else " from command line
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001731" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001732 let s:netrw_passwd=a:2
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001734
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001735" call Dret("NetUserPass")
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737
Bram Moolenaar9964e462007-05-05 17:54:07 +00001738" ===========================================
1739" Shared Browsing Support: {{{1
1740" ===========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001742" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00001743" s:BrowserMaps: {{{2
1744fun! s:BrowserMaps(islocal)
1745" call Dfunc("s:BrowserMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
1746 if a:islocal
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001747" call Decho("make local maps")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001748 nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
1749 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr>
1750 nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001751 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001752 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
1753 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
1754 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
1755 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
1756 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
1757 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
1758 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
1759 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
1760 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
1761 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
1762 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
1763 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
1764 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
1765 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1)<cr>
1766 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001767 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001768 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001769 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001770 nnoremap <buffer> <silent> c :exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001771 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001772 nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>
1773 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001774 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001775 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr>
1776 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr>
1777 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
1778 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001779 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
1780 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001781 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
1782 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
1783 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001784 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001785 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001786 nnoremap <buffer> <silent> T :call <SID>NetrwSplit(4)<bar>norm! gT<cr>
1787 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
1788 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001789 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr>
1790 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
Bram Moolenaarc236c162008-07-13 17:41:49 +00001791 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001792 inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
1793 inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,'../'))<cr>
1794 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr>
1795 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
1796 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
1797 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
1798 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
1799 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
1800 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
1801 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
1802 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr>
1803 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
1804 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
1805 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr>
1806 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr>
1807 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
1808 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr>
1809 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1)<cr>
1810 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
1811 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
1812 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr>
1813 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
1814 inoremap <buffer> <silent> c <c-o>:exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
1815 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
1816 inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>
1817 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr>
1818 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
1819 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr>
1820 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr>
1821 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
1822 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
1823 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
1824 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
1825 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
1826 inoremap <buffer> <silent> r <c-o>:let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
1827 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr>
1828 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr>
1829 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr>
1830 inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(4)<bar>norm! gT<cr>
1831 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
1832 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
1833 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr>
1834 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
1835 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001836 if !hasmapto('<Plug>NetrwHideEdit')
1837 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001838 imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar446cb832008-06-24 21:56:24 +00001839 endif
1840 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
1841 if !hasmapto('<Plug>NetrwRefresh')
1842 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001843 imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaar446cb832008-06-24 21:56:24 +00001844 endif
1845 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001846 if s:didstarstar || !mapcheck("<s-down>","n")
1847 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001848 inoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001849 endif
1850 if s:didstarstar || !mapcheck("<s-up>","n")
1851 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001852 inoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001853 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001854 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001855 if g:netrw_mousemaps == 1
1856 nnoremap <buffer> <silent> <leftmouse> <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
1857 nnoremap <buffer> <silent> <middlemouse> <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
1858 nnoremap <buffer> <silent> <s-leftmouse> <leftmouse>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001859 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
1860 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001861 inoremap <buffer> <silent> <leftmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr>
1862 inoremap <buffer> <silent> <middlemouse> <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
1863 inoremap <buffer> <silent> <s-leftmouse> <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
1864 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001865 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001866 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001867 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001868 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001869 exe 'nnoremap <buffer> <silent> <Leader>m :call <SID>NetrwMakeDir("")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001870 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
1871 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
1872 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
1873 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
1874 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
1875 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
1876 exe 'inoremap <buffer> <silent> <Leader>m <c-o>:call <SID>NetrwMakeDir("")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001877 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001878
Bram Moolenaar9964e462007-05-05 17:54:07 +00001879 else " remote
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001880" call Decho("make remote maps")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001881 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00001882 nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
1883 nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
1884 nnoremap <buffer> <silent> - :exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr>
1885 nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001886 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001887 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
1888 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
1889 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
1890 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
1891 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
1892 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
1893 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
1894 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
1895 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
1896 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
1897 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
1898 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
1899 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
1900 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0)<cr>
1901 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001902 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_cur)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001903 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001904 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001905 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001906 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001907 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001908 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr>
1909 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr>
1910 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
1911 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001912 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
1913 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001914 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
1915 nnoremap <buffer> <silent> r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
1916 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00001917 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001918 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +01001919 nnoremap <buffer> <silent> T :call <SID>NetrwSplit(1)<bar>norm! gT<cr>
1920 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
1921 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001922 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr>
1923 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaarc236c162008-07-13 17:41:49 +00001924 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001925 inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
1926 inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
1927 inoremap <buffer> <silent> - <c-o>:exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'../'))<cr>
1928 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr>
1929 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
1930 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
1931 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
1932 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
1933 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
1934 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
1935 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
1936 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr>
1937 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
1938 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
1939 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr>
1940 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr>
1941 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
1942 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr>
1943 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0)<cr>
1944 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
1945 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_cur)<cr>
1946 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr>
1947 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
1948 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
1949 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr>
1950 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
1951 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr>
1952 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr>
1953 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
1954 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
1955 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
1956 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
1957 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
1958 inoremap <buffer> <silent> r <c-o>:let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
1959 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr>
1960 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr>
1961 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr>
1962 inoremap <buffer> <silent> T <c-o>:call <SID>NetrwSplit(1)<bar>norm! gT<cr>
1963 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
1964 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
1965 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr>
1966 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
1967 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr>
Bram Moolenaar446cb832008-06-24 21:56:24 +00001968 if !hasmapto('<Plug>NetrwHideEdit')
1969 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001970 imap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaar446cb832008-06-24 21:56:24 +00001971 endif
1972 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
1973 if !hasmapto('<Plug>NetrwRefresh')
1974 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001975 imap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaar446cb832008-06-24 21:56:24 +00001976 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001977
1978 let mapsafepath = escape(s:path, s:netrw_map_escape)
1979 let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape)
1980
Bram Moolenaar446cb832008-06-24 21:56:24 +00001981 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
1982 if g:netrw_mousemaps == 1
1983 nnoremap <buffer> <silent> <leftmouse> <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
1984 nnoremap <buffer> <silent> <middlemouse> <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
1985 nnoremap <buffer> <silent> <s-leftmouse> <leftmouse>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001986 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
1987 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001988 inoremap <buffer> <silent> <leftmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr>
1989 inoremap <buffer> <silent> <middlemouse> <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
1990 inoremap <buffer> <silent> <s-leftmouse> <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
1991 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001992 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001993 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001994 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
1995 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
1996 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001997 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001998 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
1999 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2000 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2001 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
2002 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
2003 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaarc236c162008-07-13 17:41:49 +00002004 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002005 inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr>
Bram Moolenaar9964e462007-05-05 17:54:07 +00002006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002007 call s:SetRexDir(a:islocal,b:netrw_curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002008" call Dret("s:BrowserMaps")
2009endfun
2010
2011" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002012" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
2013fun! s:ExplorePatHls(pattern)
2014" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
2015 let repat= substitute(a:pattern,'^**/\{1,2}','','')
2016" call Decho("repat<".repat.">")
2017 let repat= escape(repat,'][.\')
2018" call Decho("repat<".repat.">")
2019 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
2020" call Dret("s:ExplorePatHls repat<".repat.">")
2021 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00002022endfun
2023
2024" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01002025" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00002026" 0: (user: <mb>) bookmark current directory
2027" 1: (user: <gb>) change to the bookmarked directory
2028" 2: (user: <qb>) list bookmarks
2029" 3: (browsing) record current directory history
2030" 4: (user: <u>) go up (previous) bookmark
2031" 5: (user: <U>) go down (next) bookmark
2032" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01002033fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002034" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002035
2036 if a:chg == 0
2037 " bookmark the current directory
2038" call Decho("(user: <b>) bookmark the current directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002039 if !exists("g:netrw_bookmarklist")
2040 let g:netrw_bookmarklist= []
2041 endif
2042 if index(g:netrw_bookmarklist,a:curdir) == -1
2043 " curdir not currently in g:netrw_bookmarklist, so include it
2044 call add(g:netrw_bookmarklist,a:curdir)
2045 call sort(g:netrw_bookmarklist)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002046 endif
2047 echo "bookmarked the current directory"
2048
2049 elseif a:chg == 1
2050 " change to the bookmarked directory
Bram Moolenaar5c736222010-01-06 20:54:52 +01002051" call Decho("(user: <".v:count."mb>) change to the bookmarked directory")
2052 if exists("g:netrw_bookmarklist[v:count-1]")
2053 exe "e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00002054 else
2055 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
2056 endif
2057
2058 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00002059" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002060 let didwork= 0
2061 " list user's bookmarks
2062" call Decho("(user: <q>) list user's bookmarks")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002063 if exists("g:netrw_bookmarklist")
2064" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
2065 let cnt= 1
2066 for bmd in g:netrw_bookmarklist
2067" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
2068 echo "Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1]
2069 let didwork = 1
2070 let cnt = cnt + 1
2071 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00002072 endif
2073
2074 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01002075 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00002076 let first = 1
2077 let histcnt = 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01002078 while ( first || cnt != g:netrw_dirhist_cnt )
2079" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002080 let histcnt= histcnt + 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01002081 if exists("g:netrw_dirhist_{cnt}")
2082" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt})
2083 echo "Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt}
Bram Moolenaar9964e462007-05-05 17:54:07 +00002084 let didwork= 1
2085 endif
2086 let first = 0
2087 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2088 if cnt < 0
2089 let cnt= cnt + g:netrw_dirhistmax
2090 endif
2091 endwhile
2092 if didwork
2093 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
2094 endif
2095
2096 elseif a:chg == 3
2097 " saves most recently visited directories (when they differ)
2098" call Decho("(browsing) record curdir history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002099 if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
2100 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
2101 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
2102" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 endif
2104
2105 elseif a:chg == 4
2106 " u: change to the previous directory stored on the history list
2107" call Decho("(user: <u>) chg to prev dir from history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002108 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
2109 if g:netrw_dirhist_cnt < 0
2110 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002112 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
2113" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
2115 setlocal ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00002116" call Decho("setlocal ma noro")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002117 keepj %d
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118 setlocal nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00002119" call Decho("setlocal nomod")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002121" " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002122 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00002123 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01002124 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
Bram Moolenaar9964e462007-05-05 17:54:07 +00002125 echo "Sorry, no predecessor directory exists yet"
2126 endif
2127
2128 elseif a:chg == 5
2129 " U: change to the subsequent directory stored on the history list
2130" call Decho("(user: <U>) chg to next dir from history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
2132 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
2133" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
2135 setlocal ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00002136" call Decho("setlocal ma noro")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002137 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00002138" call Decho("removed all lines from buffer (%d)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002139 setlocal nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00002140" call Decho("setlocal nomod")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002141 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002143 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01002145 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
2146 if g:netrw_dirhist_cnt < 0
2147 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 endif
2149 echo "Sorry, no successor directory exists yet"
2150 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002151
2152 elseif a:chg == 6
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " delete the v:count'th bookmark
2154" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
2155 let savefile= s:NetrwHome()."/.netrwbook"
2156 if filereadable(savefile)
2157 call s:NetrwBookHistSave() " done here to merge bookmarks first
2158 call delete(savefile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002159 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 call remove(g:netrw_bookmarklist,v:count-1)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002161 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002162 call s:NetrwBookmarkMenu()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002163" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164endfun
2165
2166" ---------------------------------------------------------------------
2167" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
2168" Sister function: s:NetrwBookHistSave()
2169fun! s:NetrwBookHistRead()
2170" call Dfunc("s:NetrwBookHistRead()")
2171 if !exists("s:netrw_initbookhist")
2172 let home = s:NetrwHome()
2173 let savefile= home."/.netrwbook"
2174 if filereadable(savefile)
2175" call Decho("sourcing .netrwbook")
2176 exe "so ".savefile
2177 endif
2178 let savefile= home."/.netrwhist"
2179 if filereadable(savefile)
2180" call Decho("sourcing .netrwhist")
2181 exe "so ".savefile
2182 endif
2183 let s:netrw_initbookhist= 1
2184 au VimLeave * call s:NetrwBookHistSave()
2185 endif
2186" call Dret("s:NetrwBookHistRead")
2187endfun
2188
2189" ---------------------------------------------------------------------
2190" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
2191" Sister function: s:NetrwBookHistRead()
2192" I used to do this via viminfo but that appears to
2193" be unreliable for long-term storage
2194" COMBAK: does $HOME work under windows???
2195fun! s:NetrwBookHistSave()
2196" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
2197 let savefile= s:NetrwHome()."/.netrwhist"
2198 1split
2199 call s:NetrwEnew()
2200 setlocal cino= com= cpo-=aA fo=nroql2 tw=0 report=10000 noswf
2201 setlocal nocin noai noci magic nospell nohid wig= noaw
2202 setlocal ma noro write
2203 if exists("&acd") | setlocal noacd | endif
2204 silent %d
2205
2206 " save .netrwhist -- no attempt to merge
2207 silent! file .netrwhist
2208 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
2209 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
2210 let lastline = line("$")
2211 let cnt = 1
2212 while cnt <= g:netrw_dirhist_cnt
2213 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
2214 let cnt= cnt + 1
2215 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002216 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002217
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002218 sil keepj %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01002219 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
2220 " merge and write .netrwbook
2221 let savefile= s:NetrwHome()."/.netrwbook"
2222
2223 if filereadable(savefile)
2224 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002225 exe "sil keepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 for bdm in booklist
2227 if index(g:netrw_bookmarklist,bdm) == -1
2228 call add(g:netrw_bookmarklist,bdm)
2229 endif
2230 endfor
2231 call sort(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002232 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002233 endif
2234
2235 " construct and save .netrwbook
2236 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002237 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002238 endif
2239 let bgone= bufnr("%")
2240 q!
2241 exe bgone."bwipe!"
2242
2243" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002244endfun
2245
2246" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002247" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
2248" list of the contents of a local or remote directory. It is assumed that the
2249" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
2250" with the requested remote hostname first.
2251fun! s:NetrwBrowse(islocal,dirname)
2252 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002253" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00002254" call Decho("tab#".tabpagenr()." win#".winnr())
2255" call Dredir("ls!")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002256 if !exists("s:netrw_initbookhist")
2257 call s:NetrwBookHistRead()
2258 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002259
2260 " simplify the dirname (especially for ".."s in dirnames)
2261 if a:dirname !~ '^\a\+://'
2262 let dirname= simplify(a:dirname)
2263 else
2264 let dirname= a:dirname
2265 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002266
2267 if exists("s:netrw_skipbrowse")
2268 unlet s:netrw_skipbrowse
Bram Moolenaarc236c162008-07-13 17:41:49 +00002269" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002270" call Dret("s:NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse)
2271 return
2272 endif
2273 if !exists("*shellescape")
2274 call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
2275" call Dret("s:NetrwBrowse : missing shellescape()")
2276 return
2277 endif
2278 if !exists("*fnameescape")
2279 call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
2280" call Dret("s:NetrwBrowse : missing fnameescape()")
2281 return
2282 endif
2283
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002284 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002285
2286 " re-instate any marked files
2287 if exists("s:netrwmarkfilelist_{bufnr('%')}")
2288" call Decho("clearing marked files")
2289 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
2290 endif
2291
2292 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
2293" call Decho("handle w:netrw_acdkeep:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294" call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002295 exe 'keepj lcd '.fnameescape(dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002296 call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002297" call Decho("getcwd<".getcwd().">")
2298
Bram Moolenaar5c736222010-01-06 20:54:52 +01002299 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002300 " looks like a regular file, attempt transfer
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002302
2303 " remove any filetype indicator from end of dirname, except for the {{{3
2304 " "this is a directory" indicator (/).
2305 " There shouldn't be one of those here, anyway.
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar446cb832008-06-24 21:56:24 +00002307" call Decho("new path<".path.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002308 call s:RemotePathAnalysis(dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002309
2310 " remote-read the requested file into current buffer {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002311 keepj mark '
Bram Moolenaar5c736222010-01-06 20:54:52 +01002312 call s:NetrwEnew(dirname)
2313 call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002314 setlocal ma noro
2315" call Decho("setlocal ma noro")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 let b:netrw_curdir= dirname
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002317" call Decho("exe sil! keepalt file ".fnameescape(s:method."://".s:user.s:machine."/".s:path)." (bt=".&bt.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002318 exe "sil! keepalt file ".fnameescape(s:method."://".s:user.s:machine."/".s:path)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002319 exe "sil! keepalt doau BufReadPre ".fnameescape(s:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002320 silent call netrw#NetRead(2,s:method."://".s:user.s:machine."/".s:path)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002321 if s:path !~ '.tar.bz2$' && s:path !~ '.tar.gz' && s:path !~ '.tar.xz' && s:path !~ '.txz'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002322 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002323 exe "sil keepalt doau BufReadPost ".fnameescape(s:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002324 endif
2325
2326 " save certain window-oriented variables into buffer-oriented variables {{{3
2327 call s:SetBufWinVars()
2328 call s:NetrwOptionRestore("w:")
2329 setlocal ma nomod
2330
Bram Moolenaarc236c162008-07-13 17:41:49 +00002331" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002332" call Dret("s:NetrwBrowse : file<".s:fname.">")
2333 return
2334 endif
2335
2336 " use buffer-oriented WinVars if buffer ones exist but window ones don't {{{3
2337 call s:UseBufWinVars()
2338
2339 " set up some variables {{{3
2340 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002342 let s:last_sort_by = g:netrw_sort_by
2343
2344 " set up menu {{{3
2345 call s:NetrwMenu(1)
2346
2347 " set up buffer {{{3
2348 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
2349 " maintain markfile highlighting
2350 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
2351" call Decho("bufnr(%)=".bufnr('%'))
2352" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
2353 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
2354 else
2355" call Decho("2match none")
2356 2match none
2357 endif
2358 if reusing
2359 call s:NetrwOptionRestore("w:")
2360 setlocal noma nomod nowrap
Bram Moolenaarc236c162008-07-13 17:41:49 +00002361" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002362" call Dret("s:NetrwBrowse : re-using buffer")
2363 return
2364 endif
2365
2366 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002367" call Decho("set b:netrw_curdir to the new directory name: (buf#".bufnr("%").")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002368 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002369 if b:netrw_curdir =~ '[/\\]$'
2370 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
2371 endif
2372 if b:netrw_curdir == ''
2373 if has("amiga")
2374 " On the Amiga, the empty string connotes the current directory
2375 let b:netrw_curdir= getcwd()
2376 else
2377 " under unix, when the root directory is encountered, the result
2378 " from the preceding substitute is an empty string.
2379 let b:netrw_curdir= '/'
2380 endif
2381 endif
2382 if !a:islocal && b:netrw_curdir !~ '/$'
2383 let b:netrw_curdir= b:netrw_curdir.'/'
2384 endif
2385" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
2386
2387 " ------------
2388 " (local only) {{{3
2389 " ------------
2390 if a:islocal
2391" call Decho("local only:")
2392
2393 " Set up ShellCmdPost handling. Append current buffer to browselist
2394 call s:LocalFastBrowser()
2395
2396 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
2397 if !g:netrw_keepdir
2398" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
2399" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
2400 if !exists("&l:acd") || !&l:acd
2401" call Decho('exe keepjumps lcd '.fnameescape(b:netrw_curdir))
2402 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002403 exe 'keepj lcd '.fnameescape(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002404 catch /^Vim\%((\a\+)\)\=:E472/
2405 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".b:netrw_curdir."> (permissions?)",61)
2406 if exists("w:netrw_prvdir")
2407 let b:netrw_curdir= w:netrw_prvdir
2408 else
2409 call s:NetrwOptionRestore("w:")
2410 setlocal noma nomod nowrap
2411 let b:netrw_curdir= dirname
Bram Moolenaarc236c162008-07-13 17:41:49 +00002412" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002413" call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
2414 return
2415 endif
2416 endtry
2417 endif
2418 endif
2419
2420 " --------------------------------
2421 " remote handling: {{{3
2422 " --------------------------------
2423 else
2424" call Decho("remote only:")
2425
Bram Moolenaar5c736222010-01-06 20:54:52 +01002426 " analyze dirname and g:netrw_list_cmd {{{4
2427" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
2428 if dirname =~ "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00002429 let dirname= b:netrw_curdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01002430" call Decho("(dirname was ".dirname.") dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002431 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
2432 let dirname= substitute(b:netrw_curdir,'\\','/','g')
2433 if dirname !~ '/$'
2434 let dirname= dirname.'/'
2435 endif
2436 let b:netrw_curdir = dirname
2437" call Decho("(liststyle is TREELIST) dirname<".dirname.">")
2438 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01002439 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00002440" call Decho("(normal) dirname<".dirname.">")
2441 endif
2442
2443 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
2444 if dirname !~ dirpat
2445 if !exists("g:netrw_quiet")
2446 call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
2447 endif
2448 call s:NetrwOptionRestore("w:")
2449 setlocal noma nomod nowrap
Bram Moolenaarc236c162008-07-13 17:41:49 +00002450" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002451" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
2452 return
2453 endif
2454 let b:netrw_curdir= dirname
2455" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
2456 endif " (additional remote handling)
2457
2458 " -----------------------
2459 " Directory Listing: {{{3
2460 " -----------------------
2461 call s:BrowserMaps(a:islocal)
2462 call s:PerformListing(a:islocal)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002463
2464 " The s:LocalBrowseShellCmdRefresh() function is called by an autocmd
2465 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
2466 " However, s:NetrwBrowse() causes the ShellCmdPost event itself to fire once; setting
2467 " the variable below avoids that second refresh of the screen. The s:LocalBrowseShellCmdRefresh()
2468 " function gets called due to that autocmd; it notices that the following variable is set
2469 " and skips the refresh and sets s:locbrowseshellcmd to zero. Oct 13, 2008
2470 let s:locbrowseshellcmd= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00002471
Bram Moolenaarc236c162008-07-13 17:41:49 +00002472" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002473" call Dret("s:NetrwBrowse : did PerformListing")
2474 return
2475endfun
2476
2477" ---------------------------------------------------------------------
2478" s:NetrwFileInfo: supports qf (query for file information) {{{2
2479fun! s:NetrwFileInfo(islocal,fname)
2480" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">)")
2481 if a:islocal
2482 if (has("unix") || has("macunix")) && executable("/bin/ls")
2483 if exists("b:netrw_curdir")
2484" call Decho('using ls with b:netrw_curdir<'.b:netrw_curdir.'>')
2485 if b:netrw_curdir =~ '/$'
2486 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
2487 else
2488 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
2489 endif
2490 else
2491" call Decho('using ls '.a:fname." using cwd<".getcwd().">")
2492 echo system("/bin/ls -lsad ".shellescape(a:fname))
2493 endif
2494 else
2495 " use vim functions to return information about file below cursor
2496" call Decho("using vim functions to query for file info")
2497 if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
2498 let fname= substitute(a:fname,".$","","")
2499 else
2500 let fname= a:fname
2501 endif
2502 let t = getftime(fname)
2503 let sz = getfsize(fname)
2504 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))
2505" call Decho(fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)))
2506 endif
2507 else
2508 echo "sorry, \"qf\" not supported yet for remote files"
2509 endif
2510" call Dret("s:NetrwFileInfo")
2511endfun
2512
2513" ---------------------------------------------------------------------
2514" s:NetrwGetBuffer: {{{2
2515" returns 0=cleared buffer
2516" 1=re-used buffer
2517fun! s:NetrwGetBuffer(islocal,dirname)
2518" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
2519 let dirname= a:dirname
2520
2521 " re-use buffer if possible {{{3
2522" call Decho("--re-use a buffer if possible--")
2523 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
2524 " find NetrwTreeList buffer if there is one
Bram Moolenaar5c736222010-01-06 20:54:52 +01002525" call Decho("find NetrwTreeList buffer if there is one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002526 if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
2527" call Decho(" re-use w:netrw_treebufnr=".w:netrw_treebufnr)
2528 let eikeep= &ei
2529 set ei=all
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002530 exe "sil! b ".w:netrw_treebufnr
Bram Moolenaar446cb832008-06-24 21:56:24 +00002531 let &ei= eikeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01002532" call Dret("s:NetrwGetBuffer : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002533 return
2534 endif
2535 let bufnum= -1
2536" call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist")
2537
2538 else
2539 " find buffer number of buffer named precisely the same as dirname {{{3
2540" call Decho("--find buffer numnber of buffer named precisely the same as dirname--")
2541" call Dredir("ls!")
2542
2543 " get dirname and associated buffer number
2544 let bufnum = bufnr(escape(dirname,'\'))
2545" call Decho(" find buffer<".dirname.">'s number ")
2546" call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
2547
2548 if bufnum < 0 && dirname !~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01002549 " try appending a trailing /
Bram Moolenaar446cb832008-06-24 21:56:24 +00002550" call Decho(" try appending a trailing / to dirname<".dirname.">")
2551 let bufnum= bufnr(escape(dirname.'/','\'))
2552 if bufnum > 0
2553 let dirname= dirname.'/'
2554 endif
2555 endif
2556
2557 if bufnum < 0 && dirname =~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01002558 " try removing a trailing /
Bram Moolenaar446cb832008-06-24 21:56:24 +00002559" call Decho(" try removing a trailing / from dirname<".dirname.">")
2560 let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
2561 if bufnum > 0
2562 let dirname= substitute(dirname,'/$','','')
2563 endif
2564 endif
2565
2566" call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
2567 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches)
2568 if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
2569 " handle approximate matches
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570" call Decho(" handling approx match: bufnum#".bufnum."<".bufname(bufnum)."> approx-dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002571 let ibuf = 1
2572 let buflast = bufnr("$")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002573" call Decho(" findbuf2: buflast=bufnr($)=".buflast)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002574 while ibuf <= buflast
2575 let bname= substitute(bufname(ibuf),'\\','/','g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00002576 let bname= substitute(bname,'.\zs/$','','')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002577" call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
2578 if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
2579 " bname is not empty
2580 " dirname ends with bname,
2581 " dirname doesn't start with /, so its not a absolute path
2582" call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
Bram Moolenaar5c736222010-01-06 20:54:52 +01002583 break
2584 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002585 if bname =~ '^'.dirname.'/\=$'
2586 " bname begins with dirname
2587" call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01002588 break
2589 endif
2590 if dirname =~ '^'.bname.'/$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002591" call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
2592 break
2593 endif
2594 if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
2595" call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596 break
2597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002598 let ibuf= ibuf + 1
2599 endwhile
2600 if ibuf > buflast
2601 let bufnum= -1
2602 else
2603 let bufnum= ibuf
2604 endif
2605" call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
2606 endif
2607 endif
2608
2609 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002610 sil! keepj mark '
Bram Moolenaar446cb832008-06-24 21:56:24 +00002611 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002612" call Decho("--get enew buffer and name it (bufexists([bufnum=".bufnum."])=".bufexists(bufnum).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002613 call s:NetrwEnew(dirname)
2614" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
2615 " name the buffer
2616 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
2617 " Got enew buffer; transform into a NetrwTreeListing
2618" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
2619 if !exists("s:netrw_treelistnum")
2620 let s:netrw_treelistnum= 1
2621 else
2622 let s:netrw_treelistnum= s:netrw_treelistnum + 1
2623 endif
2624 let w:netrw_treebufnr= bufnr("%")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002625" call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002626 exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
2627 set bt=nofile noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00002628 nnoremap <silent> <buffer> [ :silent call <SID>TreeListMove('[')<cr>
2629 nnoremap <silent> <buffer> ] :silent call <SID>TreeListMove(']')<cr>
2630 nnoremap <silent> <buffer> [[ :silent call <SID>TreeListMove('[')<cr>
2631 nnoremap <silent> <buffer> ]] :silent call <SID>TreeListMove(']')<cr>
2632" call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
2633 else
2634" let v:errmsg= "" " Decho
2635 let escdirname= fnameescape(dirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002636" call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002637" call Decho(' exe sil! keepalt file '.escdirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002638" let v:errmsg= "" " Decho
2639 exe 'sil! keepalt file '.escdirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00002640" call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
2641 endif
2642" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">")
2643
2644 else " Re-use the buffer
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002645" call Decho("--re-use buffer#".bufnum." (bufexists([bufnum=".bufnum."])=".bufexists(bufnum).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002646 let eikeep= &ei
2647 set ei=all
2648 if getline(2) =~ '^" Netrw Directory Listing'
2649" call Decho(" re-use buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: keepalt b ".bufnum)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002650 exe "sil! keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00002651 else
2652" call Decho(" reusing buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: b ".bufnum)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002653 exe "sil! b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00002654 endif
2655 if bufname("%") == '.'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002656" call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002657 exe "sil! keepalt file ".fnameescape(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00002658 endif
2659 let &ei= eikeep
2660 if line("$") <= 1
2661 call s:NetrwListSettings(a:islocal)
2662" call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but its empty, so refresh it")
2663 return 0
2664 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
2665" call Decho("--re-use tree listing--")
2666" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002667 sil keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00002668 call s:NetrwListSettings(a:islocal)
2669" call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
2670 return 0
2671 else
2672" call Dret("s:NetrwGetBuffer 1 : buf#".bufnr("%"))
2673 return 1
2674 endif
2675 endif
2676
2677 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
2678 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
2679 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
2680 " med 1 D H
2681 " fast 2 H H
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002682" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002683 let fname= expand("%")
2684 call s:NetrwListSettings(a:islocal)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002685" call Decho("exe sil! keepalt file ".fnameescape(fname))
2686 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002687
2688 " delete all lines from buffer {{{3
2689" call Decho("--delete all lines from buffer--")
2690" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002691 sil! keepalt keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00002692
2693" call Dret("s:NetrwGetBuffer 0 : buf#".bufnr("%"))
2694 return 0
2695endfun
2696
2697" ---------------------------------------------------------------------
2698" s:NetrwGetcwd: get the current directory. {{{2
2699" Change backslashes to forward slashes, if any.
2700" If doesc is true, escape certain troublesome characters
2701fun! s:NetrwGetcwd(doesc)
2702" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
2703 let curdir= substitute(getcwd(),'\\','/','ge')
2704 if curdir !~ '[\/]$'
2705 let curdir= curdir.'/'
2706 endif
2707 if a:doesc
2708 let curdir= fnameescape(curdir)
2709 endif
2710" call Dret("NetrwGetcwd <".curdir.">")
2711 return curdir
2712endfun
2713
2714" ---------------------------------------------------------------------
2715" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
2716fun! s:NetrwGetWord()
2717" call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol("."))
2718 call s:UseBufWinVars()
2719
2720 " insure that w:netrw_liststyle is set up
2721 if !exists("w:netrw_liststyle")
2722 if exists("g:netrw_liststyle")
2723 let w:netrw_liststyle= g:netrw_liststyle
2724 else
2725 let w:netrw_liststyle= s:THINLIST
2726 endif
2727" call Decho("w:netrw_liststyle=".w:netrw_liststyle)
2728 endif
2729
2730 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
2731 " Active Banner support
2732" call Decho("active banner handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002733 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002734 let dirname= "./"
2735 let curline= getline('.')
2736
2737 if curline =~ '"\s*Sorted by\s'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002738 keepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00002739 let s:netrw_skipbrowse= 1
2740 echo 'Pressing "s" also works'
2741
2742 elseif curline =~ '"\s*Sort sequence:'
2743 let s:netrw_skipbrowse= 1
2744 echo 'Press "S" to edit sorting sequence'
2745
2746 elseif curline =~ '"\s*Quick Help:'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002747 keepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00002748 let s:netrw_skipbrowse= 1
2749 echo 'Pressing "?" also works'
2750
2751 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002752 keepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00002753 let s:netrw_skipbrowse= 1
2754 echo 'Pressing "a" also works'
2755
2756 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002757 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00002758 endif
2759
2760 elseif w:netrw_liststyle == s:THINLIST
2761" call Decho("thin column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002762 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002763 let dirname= getline('.')
2764
2765 elseif w:netrw_liststyle == s:LONGLIST
2766" call Decho("long column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002767 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002768 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
2769
2770 elseif w:netrw_liststyle == s:TREELIST
2771" call Decho("treelist handling")
2772 let dirname= substitute(getline('.'),'^\(| \)*','','e')
2773
2774 else
2775" call Decho("obtain word from wide listing")
2776 let dirname= getline('.')
2777
2778 if !exists("b:netrw_cpf")
2779 let b:netrw_cpf= 0
2780 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002782" call Decho("computed cpf=".b:netrw_cpf)
2783 endif
2784
2785" call Decho("buf#".bufnr("%")."<".bufname("%").">")
2786 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
2787" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
2788" call Decho("1: dirname<".dirname.">")
2789 if filestart == 0
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002790 keepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00002791 else
2792 call cursor(line("."),filestart+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002793 keepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00002794 endif
2795 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00002796 let eofname= filestart + b:netrw_cpf + 1
2797 if eofname <= col("$")
2798 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002799 keepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00002800 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002801 keepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00002802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002803 let dirname = @a
2804 let @a = rega
2805" call Decho("2: dirname<".dirname.">")
2806 let dirname= substitute(dirname,'\s\+$','','e')
2807" call Decho("3: dirname<".dirname.">")
2808 endif
2809
2810 " symlinks are indicated by a trailing "@". Remove it before further processing.
2811 let dirname= substitute(dirname,"@$","","")
2812
2813 " executables are indicated by a trailing "*". Remove it before further processing.
2814 let dirname= substitute(dirname,"\*$","","")
2815
2816" call Dret("s:NetrwGetWord <".dirname.">")
2817 return dirname
2818endfun
2819
2820" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002821" s:NetrwListSettings: make standard settings for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00002822fun! s:NetrwListSettings(islocal)
2823" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
2824 let fname= bufname("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002825" call Decho("setlocal bt=nofile nobl ma nonu nowrap noro")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002826 setlocal bt=nofile nobl ma nonu nowrap noro
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002827" call Decho("exe sil! keepalt file ".fnameescape(fname))
2828 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002829 if g:netrw_use_noswf
2830 setlocal noswf
2831 endif
2832" call Dredir("ls!")
2833" call Decho("exe setlocal ts=".g:netrw_maxfilenamelen)
2834 exe "setlocal ts=".g:netrw_maxfilenamelen
2835 setlocal isk+=.,~,-
2836 if g:netrw_fastbrowse > a:islocal
2837 setlocal bh=hide
2838 else
2839 setlocal bh=delete
2840 endif
2841" call Dret("s:NetrwListSettings")
2842endfun
2843
2844" ---------------------------------------------------------------------
2845" s:NetrwListStyle: {{{2
2846" islocal=0: remote browsing
2847" =1: local browsing
2848fun! s:NetrwListStyle(islocal)
2849" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
2850 let fname = s:NetrwGetWord()
2851 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
2852 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
2853" call Decho("fname<".fname.">")
2854" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
2855" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
2856
2857 if w:netrw_liststyle == s:THINLIST
2858 " use one column listing
2859" call Decho("use one column list")
2860 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2861
2862 elseif w:netrw_liststyle == s:LONGLIST
2863 " use long list
2864" call Decho("use long list")
2865 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
2866
2867 elseif w:netrw_liststyle == s:WIDELIST
2868 " give wide list
2869" call Decho("use wide list")
2870 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2871
2872 elseif w:netrw_liststyle == s:TREELIST
2873" call Decho("use tree list")
2874 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2875
2876 else
2877 call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
2878 let g:netrw_liststyle = s:THINLIST
2879 let w:netrw_liststyle = g:netrw_liststyle
2880 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
2881 endif
2882 setlocal ma noro
2883" call Decho("setlocal ma noro")
2884
2885 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
2886" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002887 sil! keepj %d
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002888 " following prevents tree listing buffer from being marked "modified"
2889 setlocal nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00002890
2891 " refresh the listing
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002892" call Decho("refresh the listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002893 let svpos= netrw#NetrwSavePosn()
2894 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
2895 call netrw#NetrwRestorePosn(svpos)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002896 call s:NetrwCursorline()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002897
2898 " keep cursor on the filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002899 sil! keepj $
Bram Moolenaar446cb832008-06-24 21:56:24 +00002900 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
2901" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
2902 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002903 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00002904 endif
2905
2906" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
2907endfun
2908
2909" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01002910" s:NetrwBannerCtrl: toggles the display of the banner {{{2
2911fun! s:NetrwBannerCtrl(islocal)
2912" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
2913
2914 " toggle the banner (enable/suppress)
2915 let g:netrw_banner= !g:netrw_banner
2916
2917 " refresh the listing
2918 let svpos= netrw#NetrwSavePosn()
2919 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
2920
2921 " keep cursor on the filename
2922 let fname= s:NetrwGetWord()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002923 sil keepj $
Bram Moolenaar5c736222010-01-06 20:54:52 +01002924 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
2925" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
2926 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002927 exe "keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01002928 endif
2929" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
2930endfun
2931
2932" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwBookmarkMenu: Uses menu priorities {{{2
2934" .2.[cnt] for bookmarks, and
2935" .3.[cnt] for history
2936" (see s:NetrwMenu())
2937fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938 if !exists("s:netrw_menucnt")
2939 return
2940 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002941" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002942
2943 " the following test assures that gvim is running, has menus available, and has menus enabled.
2944 if has("gui") && has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00002945 if exists("g:NetrwTopLvlMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002946" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002947 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
2948 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01002949 endif
2950 if !exists("s:netrw_initbookhist")
2951 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 endif
2953
2954 " show bookmarked places
Bram Moolenaar5c736222010-01-06 20:54:52 +01002955 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
2956 let cnt= 1
2957 for bmd in g:netrw_bookmarklist
2958" call Decho('silent! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002959 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002960
2961 " show bookmarks for goto menu
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002962 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01002963
2964 " show bookmarks for deletion menu
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002965 exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.' '.cnt."mB"
Bram Moolenaar5c736222010-01-06 20:54:52 +01002966 let cnt= cnt + 1
2967 endfor
2968
2969 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970
2971 " show directory browsing history
Bram Moolenaar5c736222010-01-06 20:54:52 +01002972 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 let first = 1
2974 let histcnt = 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01002975 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 let histcnt = histcnt + 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01002977 let priority = g:netrw_dirhist_cnt + histcnt
2978 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002979 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002980" call Decho('silent! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002981 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 endif
2983 let first = 0
2984 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
2985 if cnt < 0
2986 let cnt= cnt + g:netrw_dirhistmax
2987 endif
2988 endwhile
Bram Moolenaar5c736222010-01-06 20:54:52 +01002989
Bram Moolenaar9964e462007-05-05 17:54:07 +00002990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002991" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002992endfun
2993
2994" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002995" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
2996" directory and a new directory name. Also, if the
2997" "new directory name" is actually a file,
2998" NetrwBrowseChgDir() edits the file.
2999fun! s:NetrwBrowseChgDir(islocal,newdir,...)
3000" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003001
Bram Moolenaar446cb832008-06-24 21:56:24 +00003002 if !exists("b:netrw_curdir")
3003 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
3004 " and the current window is the NetrwMessage window.
3005" call Decho("(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!")
3006" call Decho("getcwd<".getcwd().">")
3007" call Dredir("ls!")
3008" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010 endif
3011
Bram Moolenaar446cb832008-06-24 21:56:24 +00003012 call s:NetrwOptionSave("s:")
3013 call s:NetrwSafeOptions()
3014 let nbcd_curpos = netrw#NetrwSavePosn()
3015 let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003016 if (has("win32") || has("win95") || has("win64") || has("win16"))
3017 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
3018 else
3019 let dirname= b:netrw_curdir
3020 endif
3021 let newdir = a:newdir
3022 let dolockout = 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023
Bram Moolenaar446cb832008-06-24 21:56:24 +00003024 " set up o/s-dependent directory recognition pattern
3025 if has("amiga")
3026 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00003027 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003028 let dirpat= '[\/]$'
3029 endif
3030" call Decho("dirname<".dirname."> dirpat<".dirpat.">")
3031
3032 if dirname !~ dirpat
3033 " apparently vim is "recognizing" that it is in a directory and
3034 " is removing the trailing "/". Bad idea, so I put it back.
3035 let dirname= dirname.'/'
3036" call Decho("adjusting dirname<".dirname.">")
3037 endif
3038
3039 if newdir !~ dirpat
3040 " ------------
3041 " edit a file:
3042 " ------------
3043" call Decho('case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
3044 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
3045 let dirname= s:NetrwTreeDir()
3046 if dirname =~ '/$'
3047 let dirname= dirname.newdir
3048 else
3049 let dirname= s:NetrwTreeDir()."/".newdir
3050 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003051" call Decho("dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003052" call Decho("tree listing")
3053 elseif newdir =~ '^\(/\|\a:\)'
3054 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00003055 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003056 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003057 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003058" call Decho("handling a file: dirname<".dirname."> (a:0=".a:0.")")
3059 " this lets NetrwBrowseX avoid the edit
3060 if a:0 < 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061" call Decho("set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"))
3062 call s:NetrwOptionRestore("s:")
3063 if !exists("s:didsplit")
3064 if g:netrw_browse_split == 1
3065 new
Bram Moolenaar5c736222010-01-06 20:54:52 +01003066 if !&ea
3067 wincmd _
3068 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003069 elseif g:netrw_browse_split == 2
3070 rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071 if !&ea
3072 wincmd |
3073 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003074 elseif g:netrw_browse_split == 3
3075 tabnew
3076 elseif g:netrw_browse_split == 4
3077 if s:NetrwPrevWinOpen(2) == 3
3078" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003079 return
3080 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003081 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003082 " handling a file, didn't split, so remove menu
3083" call Decho("handling a file+didn't split, so remove menu")
3084 call s:NetrwMenu(0)
3085 " optional change to window
3086 if g:netrw_chgwin >= 1
3087 exe "keepjumps ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003088 endif
3089 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003090 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003091
Bram Moolenaar446cb832008-06-24 21:56:24 +00003092 " the point where netrw actually edits the (local) file
3093 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
3094 if a:islocal
3095" call Decho("edit local file: exe e! ".fnameescape(dirname))
3096 exe "e! ".fnameescape(dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003097 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003098" call Decho("remote file: NetrwBrowse will edit it")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003099 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003100 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003101
3102 " handle g:Netrw_funcref -- call external-to-netrw functions
3103 " This code will handle g:Netrw_funcref as an individual function reference
3104 " or as a list of function references. It will ignore anything that's not
3105 " a function reference. See :help Funcref for information about function references.
3106 if exists("g:Netrw_funcref")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003107" call Decho("handle optional Funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003108 if type(g:Netrw_funcref) == 2
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003109" call Decho("handling a g:Netrw_funcref")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003110 call g:Netrw_funcref()
3111 elseif type(g:Netrw_funcref) == 3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003112" call Decho("handling a list of g:Netrw_funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003113 for Fncref in g:Netrw_funcref
3114 if type(FncRef) == 2
3115 call FncRef()
3116 endif
3117 endfor
3118 endif
3119 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003120 endif
3121
3122 elseif newdir =~ '^/'
3123 " ---------------------------------
3124 " just go to the new directory spec
3125 " ---------------------------------
3126" call Decho('case "just go to new directory spec": newdir<'.newdir.'>')
3127 let dirname= newdir
3128 call s:SetRexDir(a:islocal,dirname)
3129 call s:NetrwOptionRestore("s:")
3130
3131 elseif newdir == './'
3132 " --------------------------
3133 " refresh the directory list
3134 " --------------------------
3135" call Decho('case "refresh directory listing": newdir == "./"')
3136 call s:SetRexDir(a:islocal,dirname)
3137
3138 elseif newdir == '../'
3139 " -------------------
3140 " go up one directory
3141 " -------------------
3142" call Decho('case "go up one directory": newdir == "../"')
3143
3144 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
3145 " force a refresh
3146" call Decho("clear buffer<".expand("%")."> with :%d")
3147 setlocal noro ma
3148" call Decho("setlocal noro ma")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003149 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003150 endif
3151
3152 if has("amiga")
3153 " amiga
3154" call Decho('case "go up one directory": newdir == "../" and amiga')
3155 if a:islocal
3156 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
3157 let dirname= substitute(dirname,'/$','','')
3158 else
3159 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
3160 endif
3161" call Decho("amiga: dirname<".dirname."> (go up one dir)")
3162
3163 else
3164 " unix or cygwin
3165" call Decho('case "go up one directory": newdir == "../" and unix or cygwin')
3166 if a:islocal
3167 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
3168 if dirname == ""
3169 let dirname= '/'
3170 endif
3171 else
3172 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
3173 endif
3174" call Decho("unix: dirname<".dirname."> (go up one dir)")
3175 endif
3176 call s:SetRexDir(a:islocal,dirname)
3177
3178 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
3179" call Decho('case liststyle is TREELIST and w:netrw_treedict exists')
3180 " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh)
3181 setlocal noro ma
3182" call Decho("setlocal noro ma")
3183 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
3184" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003185 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003186 endif
3187 let treedir = s:NetrwTreeDir()
3188 let s:treecurpos = nbcd_curpos
3189 let haskey= 0
3190" call Decho("w:netrw_treedict<".string(w:netrw_treedict).">")
3191
3192 " search treedict for tree dir as-is
3193 if has_key(w:netrw_treedict,treedir)
3194" call Decho('....searched for treedir<'.treedir.'> : found it!')
3195 let haskey= 1
3196 else
3197" call Decho('....searched for treedir<'.treedir.'> : not found')
3198 endif
3199
3200 " search treedict for treedir with a / appended
3201 if !haskey && treedir !~ '/$'
3202 if has_key(w:netrw_treedict,treedir."/")
3203 let treedir= treedir."/"
3204" call Decho('....searched.for treedir<'.treedir.'> found it!')
3205 let haskey = 1
3206 else
3207" call Decho('....searched for treedir<'.treedir.'/> : not found')
3208 endif
3209 endif
3210
3211 " search treedict for treedir with any trailing / elided
3212 if !haskey && treedir =~ '/$'
3213 let treedir= substitute(treedir,'/$','','')
3214 if has_key(w:netrw_treedict,treedir)
3215" call Decho('....searched.for treedir<'.treedir.'> found it!')
3216 let haskey = 1
3217 else
3218" call Decho('....searched for treedir<'.treedir.'> : not found')
3219 endif
3220 endif
3221
3222 if haskey
3223 " close tree listing for selected subdirectory
3224" call Decho("closing selected subdirectory<".dirname.">")
3225 call remove(w:netrw_treedict,treedir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003226" call Decho("removed entry<".treedir."> from treedict")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003227" call Decho("yielding treedict<".string(w:netrw_treedict).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003228 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 else
3230 " go down one directory
3231 let dirname= substitute(treedir,'/*$','/','')
3232" call Decho("go down one dir: treedir<".treedir.">")
3233 endif
3234 call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003235 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003236
3237 else
3238 " go down one directory
3239 let dirname= s:ComposePath(dirname,newdir)
3240" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
3241 call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003242 endif
3243
Bram Moolenaar446cb832008-06-24 21:56:24 +00003244 call s:NetrwOptionRestore("s:")
3245 if dolockout
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003246" call Decho("filewritable(dirname<".dirname.">)=".filewritable(dirname))
3247 if filewritable(dirname)
3248" call Decho("doing modification lockout settings: ma nomod noro")
3249 setlocal ma nomod noro
3250 else
3251" call Decho("doing modification lockout settings: ma nomod ro")
3252 setlocal ma nomod ro
3253 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254" call Decho("setlocal ma nomod noro")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003255 endif
3256
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
3258 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00003259endfun
3260
3261" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003262" s:NetrwBrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
3263" given filename; typically this means given their extension.
3264" 0=local, 1=remote
Bram Moolenaar446cb832008-06-24 21:56:24 +00003265fun! netrw#NetrwBrowseX(fname,remote)
3266" call Dfunc("NetrwBrowseX(fname<".a:fname."> remote=".a:remote.")")
3267
Bram Moolenaar5c736222010-01-06 20:54:52 +01003268 " special core dump handler
3269 if a:fname =~ '/core\(\.\d\+\)\=$'
3270 if exists("g:Netrw_corehandler")
3271 if type(g:Netrw_corehandler) == 2
3272 " g:Netrw_corehandler is a function reference (see :help Funcref)
3273" call Decho("g:Netrw_corehandler is a funcref")
3274 call g:Netrw_corehandler(a:fname)
3275 elseif type(g:netrw_corehandler) == 3)
3276 " g:Netrw_corehandler is a List of function references (see :help Funcref)
3277" call Decho("g:Netrw_corehandler is a List")
3278 for Fncref in g:Netrw_corehandler
3279 if type(FncRef) == 2
3280 call FncRef(a:fname)
3281 endif
3282 endfor
3283 endif
3284" call Dret("NetrwBrowseX : coredump handler invoked")
3285 return
3286 endif
3287 endif
3288
Bram Moolenaar446cb832008-06-24 21:56:24 +00003289 " set up the filename
3290 " (lower case the extension, make a local copy of a remote file)
3291 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
3292 if has("win32") || has("win95") || has("win64") || has("win16")
3293 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00003294 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003295" call Decho("exten<".exten.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003296
3297 " seems kde systems often have gnome-open due to dependencies, even though
3298 " gnome-open's subsidiary display tools are largely absent. Kde systems
3299 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
3300 if !exists("s:haskdeinit")
3301 if has("unix")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003302 let s:haskdeinit= system("ps -e") =~ 'kdeinit'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003303 if v:shell_error
3304 let s:haskdeinit = 0
3305 endif
3306 else
3307 let s:haskdeinit= 0
3308 endif
3309" call Decho("setting s:haskdeinit=".s:haskdeinit)
3310 endif
3311
3312 if a:remote == 1
3313 " create a local copy
Bram Moolenaar5c736222010-01-06 20:54:52 +01003314" call Decho("a:remote=".a:remote.": create a local copy of <".a:fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003315 setlocal bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01003316 call netrw#NetRead(3,a:fname)
3317 " attempt to rename tempfile
3318 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
3319 let newname= substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
3320" call Decho("basename<".basename.">")
3321" call Decho("newname <".newname.">")
3322 if rename(s:netrw_tmpfile,newname) == 0
3323 " renaming succeeded
3324 let fname= newname
3325 else
3326 " renaming failed
3327 let fname= s:netrw_tmpfile
3328 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00003329 else
3330 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003331 " special ~ handler for local
3332 if fname =~ '^\~' && expand("$HOME") != ""
3333" call Decho('invoking special ~ handler')
3334 let fname= substitute(fname,'^\~',expand("$HOME"),'')
3335 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003336 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003337" call Decho("fname<".fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003338" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
3339
3340 " set up redirection
3341 if &srr =~ "%s"
3342 if (has("win32") || has("win95") || has("win64") || has("win16"))
3343 let redir= substitute(&srr,"%s","nul","")
3344 else
3345 let redir= substitute(&srr,"%s","/dev/null","")
3346 endif
3347 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
3348 let redir= &srr . "nul"
3349 else
3350 let redir= &srr . "/dev/null"
3351 endif
3352" call Decho("redir{".redir."} srr{".&srr."}")
3353
3354 " extract any viewing options. Assumes that they're set apart by quotes.
3355 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003356" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003357 if g:netrw_browsex_viewer =~ '\s'
3358 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
3359 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
3360 let oviewer = ''
3361 let cnt = 1
3362 while !executable(viewer) && viewer != oviewer
3363 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
3364 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
3365 let cnt = cnt + 1
3366 let oviewer = viewer
3367" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">")
3368 endwhile
3369 else
3370 let viewer = g:netrw_browsex_viewer
3371 let viewopt = ""
3372 endif
3373" call Decho("viewer<".viewer."> viewopt<".viewopt.">")
3374 endif
3375
3376 " execute the file handler
3377 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
3378" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
3379 let ret= netrwFileHandlers#Invoke(exten,fname)
3380
3381 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
3382" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003383" call Decho("exe silent !".viewer." ".viewopt.shellescape(fname,1).redir)
3384 exe "silent !".viewer." ".viewopt.shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003385 let ret= v:shell_error
3386
3387 elseif has("win32") || has("win64")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003388 if executable("start")
3389" call Decho('exe silent !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
3390 exe 'silent !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
3391 elseif executable("rundll32")
3392" call Decho('exe silent !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
3393 exe 'silent !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
3394 else
3395 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
3396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003397 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3398 let ret= v:shell_error
3399
3400 elseif has("unix") && executable("gnome-open") && !s:haskdeinit
Bram Moolenaarc236c162008-07-13 17:41:49 +00003401" call Decho("exe silent !gnome-open ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003402 exe "sil !gnome-open ".shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003403 let ret= v:shell_error
3404
3405 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaarc236c162008-07-13 17:41:49 +00003406" call Decho("exe silent !kfmclient exec ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003407 exe "sil !kfmclient exec ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003408 let ret= v:shell_error
3409
3410 elseif has("macunix") && executable("open")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003411" call Decho("exe silent !open ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003412 exe "sil !open ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003413 let ret= v:shell_error
3414
3415 else
3416 " netrwFileHandlers#Invoke() always returns 0
3417 let ret= netrwFileHandlers#Invoke(exten,fname)
3418 endif
3419
3420 " if unsuccessful, attempt netrwFileHandlers#Invoke()
3421 if ret
3422 let ret= netrwFileHandlers#Invoke(exten,fname)
3423 endif
3424
Bram Moolenaarc236c162008-07-13 17:41:49 +00003425 " restoring redraw! after external file handlers
3426 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00003427
3428 " cleanup: remove temporary file,
3429 " delete current buffer if success with handler,
3430 " return to prior buffer (directory listing)
3431 " Feb 12, 2008: had to de-activiate removal of
3432 " temporary file because it wasn't getting seen.
3433" if a:remote == 1 && fname != a:fname
3434" call Decho("deleting temporary file<".fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00003435" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003436" endif
3437
3438 if a:remote == 1
3439 setlocal bh=delete bt=nofile
3440 if g:netrw_use_noswf
3441 setlocal noswf
3442 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003443 exe "keepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003444" redraw!
3445 endif
3446
3447" call Dret("NetrwBrowseX")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003448endfun
3449
3450" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003451" s:NetrwChgPerm: (implements "gp") change file permission {{{2
3452fun! s:NetrwChgPerm(islocal,curdir)
3453" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
3454 call inputsave()
3455 let newperm= input("Enter new permission: ")
3456 call inputrestore()
3457 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'')
3458 let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'')
3459" call Decho("chgperm<".chgperm.">")
3460 call system(chgperm)
3461 if v:shell_error != 0
3462 call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
3463 endif
3464 if a:islocal
3465 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
3466 endif
3467" call Dret("s:NetrwChgPerm")
3468endfun
3469
3470" ---------------------------------------------------------------------
3471" s:NetrwClearExplore: clear explore variables (if any) {{{2
3472fun! s:NetrwClearExplore()
3473" call Dfunc("s:NetrwClearExplore()")
3474 2match none
3475 if exists("s:explore_match") |unlet s:explore_match |endif
3476 if exists("s:explore_indx") |unlet s:explore_indx |endif
3477 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
3478 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
3479 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
3480 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
3481 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
3482 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
3483 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
3484" redraw!
3485 echo " "
3486 echo " "
3487" call Dret("s:NetrwClearExplore")
3488endfun
3489
3490" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491" netrw#Explore: launch the local browser in the directory of the current file {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003492" indx: == -1: Nexplore
3493" == -2: Pexplore
3494" == +: this is overloaded:
3495" * If Nexplore/Pexplore is in use, then this refers to the
3496" indx'th item in the w:netrw_explore_list[] of items which
3497" matched the */pattern **/pattern *//pattern **//pattern
3498" * If Hexplore or Vexplore, then this will override
3499" g:netrw_winsize to specify the qty of rows or columns the
3500" newly split window should have.
3501" dosplit==0: the window will be split iff the current file has been modified
3502" dosplit==1: the window will be split before running the local browser
3503" style == 0: Explore style == 1: Explore!
3504" == 2: Hexplore style == 3: Hexplore!
3505" == 4: Vexplore style == 5: Vexplore!
3506" == 6: Texplore
Bram Moolenaar9964e462007-05-05 17:54:07 +00003507fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003508" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." a:0=".a:0)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003509 if !exists("b:netrw_curdir")
3510 let b:netrw_curdir= getcwd()
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003511" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003513 let curdir = simplify(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003514 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
3515" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516
3517 " save registers
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003518 sil! let keepregstar = @*
3519 sil! let keepregplus = @+
3520 sil! let keepregslash= @/
Bram Moolenaar9964e462007-05-05 17:54:07 +00003521
3522 " if dosplit or file has been modified
3523 if a:dosplit || &modified || a:style == 6
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003524" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003525 call s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003526 let winsize= g:netrw_winsize
3527 if a:indx > 0
3528 let winsize= a:indx
3529 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003530
3531 if a:style == 0 " Explore, Sexplore
3532" call Decho("style=0: Explore or Sexplore")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003533 exe winsize."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003534
3535 elseif a:style == 1 "Explore!, Sexplore!
3536" call Decho("style=1: Explore! or Sexplore!")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003537 exe winsize."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538
3539 elseif a:style == 2 " Hexplore
3540" call Decho("style=2: Hexplore")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003541 exe "bel ".winsize."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003542
3543 elseif a:style == 3 " Hexplore!
3544" call Decho("style=3: Hexplore!")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003545 exe "abo ".winsize."wincmd s"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003546
3547 elseif a:style == 4 " Vexplore
3548" call Decho("style=4: Vexplore")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003549 exe "lefta ".winsize."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003550
3551 elseif a:style == 5 " Vexplore!
3552" call Decho("style=5: Vexplore!")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003553 exe "rightb ".winsize."wincmd v"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003554
3555 elseif a:style == 6 " Texplore
3556 call s:SaveBufVars()
3557" call Decho("style = 6: Texplore")
3558 tabnew
3559 call s:RestoreBufVars()
3560 endif
3561 call s:RestoreWinVars()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003562" else " Decho
3563" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003565 keepj norm! 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003566
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003567 if a:0 > 0
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003568" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003569 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003570" call Decho("case a:1: ~ and unix or cygwin")
3571 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003572" call Decho("using dirname<".dirname."> (case: ~ && unix||cygwin)")
3573 elseif a:1 == '.'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003574" call Decho("case a:1: .")
3575 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00003576 if dirname !~ '/$'
3577 let dirname= dirname."/"
3578 endif
3579" call Decho("using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")")
3580 elseif a:1 =~ '\$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003581" call Decho("case a:1: $")
3582 let dirname= simplify(expand(a:1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003583" call Decho("using user-specified dirname<".dirname."> with $env-var")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003584 elseif a:1 !~ '^\*/'
3585" call Decho("case a:1: other, not pattern or filepattern")
3586 let dirname= simplify(a:1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003587" call Decho("using user-specified dirname<".dirname.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003588 else
3589" call Decho("case a:1: pattern or filepattern")
3590 let dirname= a:1
Bram Moolenaar9964e462007-05-05 17:54:07 +00003591 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003592 else
3593 " clear explore
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003594" call Decho("case a:0=".a:0.": clearing Explore list")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003595 call s:NetrwClearExplore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003596" call Dret("netrw#Explore : cleared list")
3597 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00003598 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003599
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003600" call Decho("dirname<".dirname.">")
3601 if dirname =~ '\.\./\=$'
3602 let dirname= simplify(fnamemodify(dirname,':p:h'))
3603 elseif dirname =~ '\.\.' || dirname == '.'
3604 let dirname= simplify(fnamemodify(dirname,':p'))
3605 endif
3606" call Decho("dirname<".dirname."> (after simplify)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003607
Bram Moolenaar446cb832008-06-24 21:56:24 +00003608 if dirname =~ '/\*\*/'
3609 " handle .../**/.../filepat
3610" call Decho("case Explore .../**/.../filepat")
3611 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
3612 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
3613 let b:netrw_curdir = prefixdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003615 let b:netrw_curdir= getcwd().'/'.prefixdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00003616 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003617 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
3618 let starpat= 4;
3619" call Decho("pwd<".getcwd()."> dirname<".dirname.">")
3620" call Decho("case Explore ../**/../filepat (starpat=".starpat.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003621
Bram Moolenaar446cb832008-06-24 21:56:24 +00003622 elseif dirname =~ '^\*//'
3623 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
3624" call Decho("case Explore *//pattern")
3625 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
3626 let starpat= 1
3627" call Decho("Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
3628 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
3629
3630 elseif dirname =~ '^\*\*//'
3631 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
3632" call Decho("case Explore **//pattern")
3633 let pattern= substitute(dirname,'^\*\*//','','')
3634 let starpat= 2
3635" call Decho("Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
3636
3637 elseif dirname =~ '^\*/'
3638 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
3639 let starpat= 3
3640" call Decho("case Explore */filepat (starpat=".starpat.")")
3641
3642 elseif dirname=~ '^\*\*/'
3643 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
3644 let starpat= 4
3645" call Decho("case Explore **/filepat (starpat=".starpat.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646
Bram Moolenaar446cb832008-06-24 21:56:24 +00003647 else
3648 let starpat= 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649" call Decho("default case: starpat=".starpat)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003650 endif
3651
3652 if starpat == 0 && a:indx >= 0
3653 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaar5c736222010-01-06 20:54:52 +01003654" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname."> Explore Hexplore Vexplore Sexplore")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003655 if dirname == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01003656 let dirname= curfiledir
3657" call Decho("empty dirname, using current file's directory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003658 endif
3659 if dirname =~ '^scp:' || dirname =~ '^ftp:'
3660" call Decho("calling NetrwBrowse(0,dirname<".dirname.">)")
3661 call s:NetrwBrowse(0,dirname)
3662 else
3663 if dirname == ""|let dirname= getcwd()|endif
3664" call Decho("calling LocalBrowseCheck(dirname<".dirname.">)")
3665 call netrw#LocalBrowseCheck(dirname)
3666 endif
3667
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668" call Decho("curdir<".curdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003669 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003670 keepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003671 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003672 keepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003673 endif
3674
3675 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
3676 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
3677 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
3678 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
3679 elseif a:indx <= 0
3680 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003682 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
3683" call Decho("set up <s-up> and <s-down> maps")
3684 let s:didstarstar= 1
3685 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
3686 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
3687 endif
3688
3689 if has("path_extra")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003690" call Decho("starpat=".starpat.": has +path_extra")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003691 if !exists("w:netrw_explore_indx")
3692 let w:netrw_explore_indx= 0
3693 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694
Bram Moolenaar9964e462007-05-05 17:54:07 +00003695 let indx = a:indx
Bram Moolenaar446cb832008-06-24 21:56:24 +00003696" call Decho("starpat=".starpat.": set indx= [a:indx=".indx."]")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697
Bram Moolenaar9964e462007-05-05 17:54:07 +00003698 if indx == -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003699 " Nexplore
3700" call Decho("case Nexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003701 if !exists("w:netrw_explore_list") " sanity check
3702 call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003703 sil! let @* = keepregstar
3704 sil! let @+ = keepregstar
3705 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00003706" call Dret("netrw#Explore")
3707 return
3708 endif
3709 let indx= w:netrw_explore_indx
3710 if indx < 0 | let indx= 0 | endif
3711 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
3712 let curfile= w:netrw_explore_list[indx]
3713" call Decho("indx=".indx." curfile<".curfile.">")
3714 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
3715 let indx= indx + 1
3716" call Decho("indx=".indx." (Nexplore while loop)")
3717 endwhile
3718 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
3719" call Decho("Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
3720
3721 elseif indx == -2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003722 " Pexplore
3723" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003724 if !exists("w:netrw_explore_list") " sanity check
3725 call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003726 sil! let @* = keepregstar
3727 sil! let @+ = keepregstar
3728 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00003729" call Dret("netrw#Explore")
3730 return
3731 endif
3732 let indx= w:netrw_explore_indx
3733 if indx < 0 | let indx= 0 | endif
3734 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
3735 let curfile= w:netrw_explore_list[indx]
3736" call Decho("indx=".indx." curfile<".curfile.">")
3737 while indx >= 0 && curfile == w:netrw_explore_list[indx]
3738 let indx= indx - 1
3739" call Decho("indx=".indx." (Pexplore while loop)")
3740 endwhile
3741 if indx < 0 | let indx= 0 | endif
3742" call Decho("Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
3743
3744 else
3745 " Explore -- initialize
3746 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747" call Decho("starpat=".starpat.": case Explore: initialize (indx=".indx.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003748 call s:NetrwClearExplore()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003749 let w:netrw_explore_indx= 0
3750 if !exists("b:netrw_curdir")
3751 let b:netrw_curdir= getcwd()
3752 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003753" call Decho("starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003754
Bram Moolenaar446cb832008-06-24 21:56:24 +00003755 " switch on starpat to build the w:netrw_explore_list of files
3756 if starpat == 1
3757 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
3758" call Decho("starpat=".starpat.": build *//pattern list")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759" call Decho("pattern<".pattern.">")
3760 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003761 exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762 catch /^Vim\%((\a\+)\)\=:E480/
3763 call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
3764" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
3765 return
3766 endtry
3767 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003768 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
3769
3770 elseif starpat == 2
3771 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
3772" call Decho("starpat=".starpat.": build **//pattern list")
3773 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003774 exe "sil keepj noautocmd vimgrep /".pattern."/gj "."**/*"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776 call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003777 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778 silent! let @* = keepregstar
3779 silent! let @+ = keepregstar
3780 silent! let @/ = keepregslash
3781" call Dret("netrw#Explore : no files matched pattern")
3782 return
3783 endtry
3784 let s:netrw_curdir = b:netrw_curdir
3785 let w:netrw_explore_list = getqflist()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003786 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003787
3788 elseif starpat == 3
3789 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
3790" call Decho("starpat=".starpat.": build */filepat list")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003791 let filepat= substitute(dirname,'^\*/','','')
3792 let filepat= substitute(filepat,'^[%#<]','\\&','')
3793" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
3794" call Decho("filepat<".filepat.">")
3795 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
3796 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003797
3798 elseif starpat == 4
3799 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
3800" call Decho("starpat=".starpat.": build **/filepat list")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003802 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
3803 endif " switch on starpat to build w:netrw_explore_list
Bram Moolenaar9964e462007-05-05 17:54:07 +00003804
3805 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806" call Decho("w:netrw_explore_list<".string(w:netrw_explore_list).">")
3807" call Decho("w:netrw_explore_listlen=".w:netrw_explore_listlen)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003808
3809 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
3810 call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003811 sil! let @* = keepregstar
3812 sil! let @+ = keepregstar
3813 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00003814" call Dret("netrw#Explore : no files matched")
3815 return
3816 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 endif " if indx ... endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003818
3819 " NetrwStatusLine support - for exploring support
3820 let w:netrw_explore_indx= indx
Bram Moolenaar5c736222010-01-06 20:54:52 +01003821" call Decho("w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003822
3823 " wrap the indx around, but issue a note
3824 if indx >= w:netrw_explore_listlen || indx < 0
3825" call Decho("wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")")
3826 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
3827 let w:netrw_explore_indx= indx
3828 call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003829 endif
3830
3831 exe "let dirfile= w:netrw_explore_list[".indx."]"
3832" call Decho("dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
3833 let newdir= substitute(dirfile,'/[^/]*$','','e')
3834" call Decho("newdir<".newdir.">")
3835
3836" call Decho("calling LocalBrowseCheck(newdir<".newdir.">)")
3837 call netrw#LocalBrowseCheck(newdir)
3838 if !exists("w:netrw_liststyle")
3839 let w:netrw_liststyle= g:netrw_liststyle
3840 endif
3841 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003842 keepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003843 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003844 keepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003845 endif
3846 let w:netrw_explore_mtchcnt = indx + 1
3847 let w:netrw_explore_bufnr = bufnr("%")
3848 let w:netrw_explore_line = line(".")
3849 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
3850" call Decho("explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line)
3851
3852 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853" call Decho("your vim does not have +path_extra")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003854 if !exists("g:netrw_quiet")
3855 call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
3856 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003857 sil! let @* = keepregstar
3858 sil! let @+ = keepregstar
3859 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00003860" call Dret("netrw#Explore : missing +path_extra")
3861 return
3862 endif
3863
3864 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003865" call Decho("default case: Explore newdir<".dirname.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003866 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003867 sil! unlet w:netrw_treedict
3868 sil! unlet w:netrw_treetop
Bram Moolenaar9964e462007-05-05 17:54:07 +00003869 endif
3870 let newdir= dirname
3871 if !exists("b:netrw_curdir")
3872 call netrw#LocalBrowseCheck(getcwd())
3873 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003875 endif
3876 endif
3877
Bram Moolenaar446cb832008-06-24 21:56:24 +00003878 " visual display of **/ **// */ Exploration files
Bram Moolenaar5c736222010-01-06 20:54:52 +01003879" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"))
3880" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003881 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003882" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003883 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
3884 " only update match list if current directory isn't the same as before
Bram Moolenaar5c736222010-01-06 20:54:52 +01003885" call Decho("only update match list if current directory not the same as before")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003886 let s:explore_prvdir = b:netrw_curdir
3887 let s:explore_match = ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01003888 let dirlen = s:Strlen(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889 if b:netrw_curdir !~ '/$'
3890 let dirlen= dirlen + 1
3891 endif
3892 let prvfname= ""
3893 for fname in w:netrw_explore_list
3894" call Decho("fname<".fname.">")
3895 if fname =~ '^'.b:netrw_curdir
3896 if s:explore_match == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01003897 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003899 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003900 endif
3901 elseif fname !~ '^/' && fname != prvfname
3902 if s:explore_match == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01003903 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003905 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 endif
3907 endif
3908 let prvfname= fname
3909 endfor
3910" call Decho("explore_match<".s:explore_match.">")
3911 exe "2match netrwMarkFile /".s:explore_match."/"
3912 endif
3913 echo "<s-up>==Pexplore <s-down>==Nexplore"
3914 else
3915 2match none
3916 if exists("s:explore_match") | unlet s:explore_match | endif
3917 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
3918 echo " "
3919" call Decho("cleared explore match list")
3920 endif
3921
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003922 sil! let @* = keepregstar
3923 sil! let @+ = keepregstar
3924 sil! let @/ = keepregslash
Bram Moolenaar9964e462007-05-05 17:54:07 +00003925" call Dret("netrw#Explore : @/<".@/.">")
3926endfun
3927
3928" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003929" s:NetrwExploreListUniq: {{{2
3930fun! s:NetrwExploreListUniq(explist)
3931" call Dfunc("s:NetrwExploreListUniq(explist)")
3932
3933 " this assumes that the list is already sorted
3934 let newexplist= []
3935 for member in a:explist
3936 if !exists("uniqmember") || member != uniqmember
3937 let uniqmember = member
3938 let newexplist = newexplist + [ member ]
3939 endif
3940 endfor
3941
3942" call Dret("s:NetrwExploreListUniq")
3943 return newexplist
3944endfun
3945
3946" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
3948" and switches the hiding mode. The actual hiding is done by
3949" s:NetrwListHide().
3950" g:netrw_hide= 0: show all
3951" 1: show not-hidden files
3952" 2: show hidden files only
3953fun! s:NetrwHide(islocal)
3954" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
3955 let svpos= netrw#NetrwSavePosn()
3956
3957 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3958" call Decho(((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">")
3959" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">")
3960
3961 " hide the files in the markfile list
3962 for fname in s:netrwmarkfilelist_{bufnr("%")}
3963" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." isk=".&isk)
3964 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
3965 " remove fname from hiding list
3966 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
3967 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
3968 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
3969" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">")
3970 else
3971 " append fname to hiding list
3972 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
3973 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
3974 else
3975 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
3976 endif
3977" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">")
3978 endif
3979 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01003980 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 let g:netrw_hide= 1
3982
3983 else
3984
3985 " switch between show-all/show-not-hidden/show-hidden
3986 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003987 exe "keepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 if g:netrw_hide && g:netrw_list_hide == ""
3989 call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
3990" call Dret("NetrwHide")
3991 return
3992 endif
3993 endif
3994
3995 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
3996 call netrw#NetrwRestorePosn(svpos)
3997" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003998endfun
3999
4000" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001" s:NetrwHidden: invoked by "gh" {{{2
4002fun! s:NetrwHidden(islocal)
4003" call Dfunc("s:NetrwHidden()")
4004 " save current position
4005 let svpos= netrw#NetrwSavePosn()
4006
4007 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
4008 " remove pattern from hiding list
4009 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004010 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
4012 else
4013 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
4014 endif
4015
4016 " refresh screen and return to saved position
4017 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4018 call netrw#NetrwRestorePosn(svpos)
4019" call Dret("s:NetrwHidden")
4020endfun
4021
4022" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004023" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
4024fun! s:NetrwHome()
4025 if exists("g:netrw_home")
4026 let home= g:netrw_home
4027 else
4028 " go to vim plugin home
4029 for home in split(&rtp,',') + ['']
4030 if isdirectory(home) && filewritable(home) | break | endif
4031 let basehome= substitute(home,'[/\\]\.vim$','','')
4032 if isdirectory(basehome) && filewritable(basehome)
4033 let home= basehome."/.vim"
4034 break
4035 endif
4036 endfor
4037 if home == ""
4038 " just pick the first directory
4039 let home= substitute(&rtp,',.*$','','')
4040 endif
4041 if (has("win32") || has("win95") || has("win64") || has("win16"))
4042 let home= substitute(home,'/','\\','g')
4043 endif
4044 endif
4045 " insure that the home directory exists
4046 if !isdirectory(home)
4047 if exists("g:netrw_mkdir")
4048 call system(g:netrw_mkdir." ".shellescape(home))
4049 else
4050 call mkdir(home)
4051 endif
4052 endif
4053 let g:netrw_home= home
4054 return home
4055endfun
4056
4057" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004058" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
4059fun! s:NetrwLeftmouse(islocal)
4060" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004061
4062 " check if the status bar was clicked on instead of a file/directory name
4063 call feedkeys("\<LeftMouse>")
4064 let c= getchar()
4065 let mouse_lnum = v:mouse_lnum
4066 let wlastline = line('w$')
4067 let lastline = line('$')
4068" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr())
4069" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0))
4070 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
4071 " appears to be a status bar leftmouse click
4072" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
4073 return
4074 endif
4075 if v:mouse_col != col('.')
4076" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
4077 return
4078 endif
4079
Bram Moolenaar446cb832008-06-24 21:56:24 +00004080 if a:islocal
4081 if exists("b:netrw_curdir")
4082 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
4083 endif
4084 else
4085 if exists("b:netrw_curdir")
4086 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
4087 endif
4088 endif
4089" call Dret("s:NetrwLeftmouse")
4090endfun
4091
4092" ---------------------------------------------------------------------
4093" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
4094" separated patterns given in g:netrw_list_hide
4095fun! s:NetrwListHide()
4096" call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">")
4097
4098 " find a character not in the "hide" string to use as a separator for :g and :v commands
4099 " How-it-works: take the hiding command, convert it into a range. Duplicate
4100 " characters don't matter. Remove all such characters from the '/~...90'
4101 " string. Use the first character left as a separator character.
4102 let listhide= g:netrw_list_hide
4103 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
4104" call Decho("sep=".sep)
4105
4106 while listhide != ""
4107 if listhide =~ ','
4108 let hide = substitute(listhide,',.*$','','e')
4109 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
4110 else
4111 let hide = listhide
4112 let listhide = ""
4113 endif
4114
4115 " Prune the list by hiding any files which match
4116 if g:netrw_hide == 1
4117" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004118 exe 'sil keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004119 elseif g:netrw_hide == 2
4120" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004121 exe 'sil keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004122 endif
4123 endwhile
4124 if g:netrw_hide == 2
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004125 exe 'sil keepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
4126 exe 'sil keepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004127 endif
4128
4129" call Dret("NetrwListHide")
4130endfun
4131
4132" ---------------------------------------------------------------------
4133" NetrwHideEdit: allows user to edit the file/directory hiding list
4134fun! s:NetrwHideEdit(islocal)
4135" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
4136
4137 " save current cursor position
4138 let svpos= netrw#NetrwSavePosn()
4139
4140 " get new hiding list from user
4141 call inputsave()
4142 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
4143 call inputrestore()
4144 let g:netrw_list_hide= newhide
4145" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
4146
4147 " refresh the listing
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004148 silent keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149
4150 " restore cursor position
4151 call netrw#NetrwRestorePosn(svpos)
4152
4153" call Dret("NetrwHideEdit")
4154endfun
4155
4156" ---------------------------------------------------------------------
4157" NetSortSequence: allows user to edit the sorting sequence
4158fun! s:NetSortSequence(islocal)
4159" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
4160
4161 let svpos= netrw#NetrwSavePosn()
4162 call inputsave()
4163 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
4164 call inputrestore()
4165
4166 " refresh the listing
4167 let g:netrw_sort_sequence= newsortseq
4168 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4169 call netrw#NetrwRestorePosn(svpos)
4170
4171" call Dret("NetSortSequence")
4172endfun
4173
4174" ---------------------------------------------------------------------
4175" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
4176fun! s:NetrwMakeDir(usrhost)
4177" call Dfunc("NetrwMakeDir(usrhost<".a:usrhost.">)")
4178
4179 " get name of new directory from user. A bare <CR> will skip.
4180 " if its currently a directory, also request will be skipped, but with
4181 " a message.
4182 call inputsave()
4183 let newdirname= input("Please give directory name: ")
4184 call inputrestore()
4185" call Decho("newdirname<".newdirname.">")
4186
4187 if newdirname == ""
4188" call Dret("NetrwMakeDir : user aborted with bare <cr>")
4189 return
4190 endif
4191
4192 if a:usrhost == ""
4193" call Decho("local mkdir")
4194
4195 " Local mkdir:
4196 " sanity checks
4197 let fullnewdir= b:netrw_curdir.'/'.newdirname
4198" call Decho("fullnewdir<".fullnewdir.">")
4199 if isdirectory(fullnewdir)
4200 if !exists("g:netrw_quiet")
4201 call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
4202 endif
4203" call Dret("NetrwMakeDir : directory<".newdirname."> exists previously")
4204 return
4205 endif
4206 if s:FileReadable(fullnewdir)
4207 if !exists("g:netrw_quiet")
4208 call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
4209 endif
4210" call Dret("NetrwMakeDir : file<".newdirname."> exists previously")
4211 return
4212 endif
4213
4214 " requested new local directory is neither a pre-existing file or
4215 " directory, so make it!
4216 if exists("*mkdir")
4217 call mkdir(fullnewdir,"p")
4218 else
4219 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004220 exe 'keepj lcd '.fnameescape(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004221" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004222" call Decho("exe silent! !".g:netrw_local_mkdir.' '.shellescape(newdirname,1))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004223 exe "sil! !".g:netrw_local_mkdir.' '.shellescape(newdirname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004224 if !g:netrw_keepdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004225 exe 'keepj lcd '.fnameescape(netrw_origdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004226" call Decho("netrw_keepdir=".g:netrw_keepdir.": keepjumps lcd ".fnameescape(netrw_origdir)." getcwd<".getcwd().">")
4227 endif
4228 endif
4229
4230 if v:shell_error == 0
4231 " refresh listing
4232" call Decho("refresh listing")
4233 let svpos= netrw#NetrwSavePosn()
4234 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
4235 call netrw#NetrwRestorePosn(svpos)
4236 elseif !exists("g:netrw_quiet")
4237 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
4238 endif
4239" redraw!
4240
4241 elseif !exists("b:netrw_method") || b:netrw_method == 4
4242 " Remote mkdir:
4243" call Decho("remote mkdir")
4244 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
4245 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaarc236c162008-07-13 17:41:49 +00004246" call Decho("exe silent! !".mkdircmd." ".shellescape(newdirname,1))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004247 exe "sil! !".mkdircmd." ".shellescape(newdirname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004248 if v:shell_error == 0
4249 " refresh listing
4250 let svpos= netrw#NetrwSavePosn()
4251 call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
4252 call netrw#NetrwRestorePosn(svpos)
4253 elseif !exists("g:netrw_quiet")
4254 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
4255 endif
4256" redraw!
4257
4258 elseif b:netrw_method == 2
4259 " COMBAK -- future work
4260 call netrw#ErrorMsg(s:ERROR,"making directories via ftp not currently supported",68)
4261 elseif b:netrw_method == 3
4262 " COMBAK -- future work
4263 call netrw#ErrorMsg(s:ERROR,"making directories via ftp not currently supported",68)
4264 endif
4265
4266" call Dret("NetrwMakeDir")
4267endfun
4268
4269" ---------------------------------------------------------------------
4270" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
4271" mark and unmark files. If a markfile list exists,
4272" then the rename and delete functions will use it instead
4273" of whatever may happen to be under the cursor at that
4274" moment. When the mouse and gui are available,
4275" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004276"
4277" Creates two lists
4278" s:netrwmarkfilelist -- holds complete paths to all marked files
4279" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
4280"
4281" Creates a marked file match string
4282" s:netrwmarfilemtch_# -- used with 2match to display marked files
4283"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004284" Creates a buffer version of islocal
4285" b:netrw_islocal
4286"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287fun! s:NetrwMarkFile(islocal,fname)
4288" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
4289 let curbufnr= bufnr("%")
4290 let curdir = b:netrw_curdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01004291 let trailer = '[@=|\/\*]\=\>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 if exists("s:netrwmarkfilelist_{curbufnr}")
4293 " markfile list exists
4294" call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
4295" call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">")
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004296 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297
4298 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004299 " append filename to buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
4301 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004302 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(a:fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303
4304 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00004305 " remove filename from buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
4307 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
4308 if s:netrwmarkfilelist_{curbufnr} == []
4309 " local markfilelist is empty; remove it entirely
Bram Moolenaar5c736222010-01-06 20:54:52 +01004310" call Decho("markfile list now empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 call s:NetrwUnmarkList(curbufnr,curdir)
4312 else
4313 " rebuild match list to display markings correctly
4314" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr)
4315 let s:netrwmarkfilemtch_{curbufnr}= ""
4316 let first = 1
4317 for fname in s:netrwmarkfilelist_{curbufnr}
4318 if first
Bram Moolenaar5c736222010-01-06 20:54:52 +01004319 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004321 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|\<'.escape(fname,g:netrw_markfileesc."'".g:netrw_markfileesc."'").trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 endif
4323 let first= 0
4324 endfor
4325" call Decho("ending s:netrwmarkfilelist_"curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
4326" call Decho("ending s:netrwmarkfilemtch_"curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
4327 endif
4328 endif
4329
4330 else
4331 " initialize new markfilelist
4332
4333" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr)
4334 let s:netrwmarkfilelist_{curbufnr}= []
4335 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
4336" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
4337
4338 " build initial markfile matching pattern
4339 if a:fname =~ '/$'
4340 let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc)
4341 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004342 let s:netrwmarkfilemtch_{curbufnr}= '\<'.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00004343 endif
4344" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
4345 endif
4346
4347 " handle global markfilelist
4348 if exists("s:netrwmarkfilelist")
4349 let dname= s:ComposePath(b:netrw_curdir,a:fname)
4350 if index(s:netrwmarkfilelist,dname) == -1
4351 " append new filename to global markfilelist
4352 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
4353" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">")
4354 else
4355 " remove new filename from global markfilelist
4356" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")")
4357 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
4358" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">")
4359 if s:netrwmarkfilelist == []
4360 unlet s:netrwmarkfilelist
4361 endif
4362 endif
4363 else
4364 " initialize new global-directory markfilelist
4365 let s:netrwmarkfilelist= []
4366 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
4367" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">")
4368 endif
4369
4370 " set up 2match'ing to netrwmarkfilemtch list
4371 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
4372" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004373 if exists("g:did_drchip_netrwlist_syntax")
4374 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
4375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 else
4377" call Decho("2match none")
4378 2match none
4379 endif
4380" call Dret("s:NetrwMarkFile : netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">")
4381endfun
4382
4383" ---------------------------------------------------------------------
4384" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
4385" compress/decompress files using the programs
4386" in g:netrw_compress and g:netrw_uncompress,
4387" using g:netrw_compress_suffix to know which to
4388" do. By default:
4389" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004390" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391fun! s:NetrwMarkFileCompress(islocal)
4392" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
4393 let svpos = netrw#NetrwSavePosn()
4394 let curdir = b:netrw_curdir
4395 let curbufnr = bufnr("%")
4396
4397 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
4398 for fname in s:netrwmarkfilelist_{curbufnr}
4399 " for every filename in the marked list
4400 for sfx in sort(keys(g:netrw_decompress))
4401 if fname =~ '\'.sfx.'$'
4402 " fname has a suffix indicating that its compressed; apply associated decompression routine
Bram Moolenaar5c736222010-01-06 20:54:52 +01004403 let exe= netrw#WinPath(g:netrw_decompress[sfx])
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404" call Decho("fname<".fname."> is compressed so decompress with <".exe.">")
4405 if a:islocal
4406 if g:netrw_keepdir
Bram Moolenaarc236c162008-07-13 17:41:49 +00004407 let fname= shellescape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 endif
4409 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004410 let fname= shellescape(b:netrw_curdir.fname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004411 endif
4412 if executable(exe)
4413 if a:islocal
4414 call system(exe." ".fname)
4415 else
4416 call s:RemoteSystem(exe." ".fname)
4417 endif
4418 else
4419 call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
4420 endif
4421 break
4422 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004423 unlet sfx
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424 endfor
4425 if exists("exe")
4426 unlet exe
4427 elseif a:islocal
4428 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01004429 call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 else
4431 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01004432 call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433 endif
4434 endfor
4435 call s:NetrwUnmarkList(curbufnr,curdir)
4436 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4437 call netrw#NetrwRestorePosn(svpos)
4438 endif
4439" call Dret("s:NetrwMarkFileCompress")
4440endfun
4441
4442" ---------------------------------------------------------------------
4443" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
4444" If no marked files, then set up directory as the
4445" target. Currently does not support copying entire
4446" directories. Uses the local-buffer marked file list.
4447" Returns 1=success (used by NetrwMarkFileMove())
4448" 0=failure
4449fun! s:NetrwMarkFileCopy(islocal)
4450" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---').">")
4451
4452 " sanity checks
4453 if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')})
4454 call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
4455" call Dret("s:NetrwMarkFileCopy 0")
4456 return 0
4457 endif
4458" call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')}))
4459 if !exists("s:netrwmftgt")
4460 call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
4461" call Dret("s:NetrwMarkFileCopy 0")
4462 return 0
4463 endif
4464" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
4465 let curdir = b:netrw_curdir
4466 let curbufnr = bufnr("%")
4467
4468 if a:islocal && s:netrwmftgt_islocal
4469 " Copy marked files, local directory to local directory
4470" call Decho("copy from local to local")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004471 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472" call Decho("system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt).")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004473 call system(netrw#WinPath(g:netrw_localcopycmd)." ".args." ".shellescape(s:netrwmftgt))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474
4475 elseif a:islocal && !s:netrwmftgt_islocal
4476 " Copy marked files, local directory to remote directory
4477" call Decho("copy from local to remote")
4478 call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
4479
4480 elseif !a:islocal && s:netrwmftgt_islocal
4481" call Decho("copy from remote to local")
4482 call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
4483
4484 elseif !a:islocal && !s:netrwmftgt_islocal
4485" call Decho("copy from remote to remote")
4486 let curdir = getcwd()
4487 let tmpdir = s:GetTempfile("")
4488 if tmpdir !~ '/'
4489 let tmpdir= curdir."/".tmpdir
4490 endif
4491 if exists("*mkdir")
4492 call mkdir(tmpdir)
4493 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004494 exe "sil! !".g:netrw_local_mkdir.' '.shellescape(tmpdir,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 endif
4496 if isdirectory(tmpdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004497 exe "keepj lcd ".fnameescape(tmpdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498 call netrw#NetrwObtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004499 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500 call s:NetrwUpload(localfiles,s:netrwmftgt)
4501 if getcwd() == tmpdir
4502 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 endfor
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004505 exe "keepj lcd ".fnameescape(curdir)
4506 exe "sil !".g:netrw_local_rmdir." ".shellescape(tmpdir,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004508 exe "keepj lcd ".fnameescape(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 endif
4510 endif
4511 endif
4512
4513 " -------
4514 " cleanup
4515 " -------
4516" call Decho("cleanup")
4517
4518 " remove markings from local buffer
4519 call s:NetrwUnmarkList(curbufnr,curdir)
4520
4521 " refresh buffers
4522 if !s:netrwmftgt_islocal
4523 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
4524 endif
4525 if a:islocal
4526 call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
4527 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004528 if g:netrw_fastbrowse <= 1
4529 call s:LocalBrowseShellCmdRefresh()
4530 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531
4532" call Dret("s:NetrwMarkFileCopy 1")
4533 return 1
4534endfun
4535
4536" ---------------------------------------------------------------------
4537" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
4538" invoke vim's diff mode on the marked files.
4539" Either two or three files can be so handled.
4540" Uses the global marked file list.
4541fun! s:NetrwMarkFileDiff(islocal)
4542" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
4543 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004545 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 let cnt = 0
4547 let curdir = b:netrw_curdir
4548 for fname in s:netrwmarkfilelist
4549 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 if cnt == 1
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004551" call Decho("diffthis: fname<".fname.">")
4552 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553 diffthis
4554 elseif cnt == 2 || cnt == 3
4555 vsplit
4556 wincmd l
4557" call Decho("diffthis: ".fname)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004558 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559 diffthis
4560 else
4561 break
4562 endif
4563 endfor
4564 call s:NetrwUnmarkList(curbufnr,curdir)
4565 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004566
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567" call Dret("s:NetrwMarkFileDiff")
4568endfun
4569
4570" ---------------------------------------------------------------------
4571" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
4572" Uses global markfilelist
4573fun! s:NetrwMarkFileEdit(islocal)
4574" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
4575
4576 let curdir = b:netrw_curdir
4577 let curbufnr = bufnr("%")
4578 if exists("s:netrwmarkfilelist_{curbufnr}")
4579 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004580 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 " unmark markedfile list
4582" call s:NetrwUnmarkList(curbufnr,curdir)
4583 call s:NetrwUnmarkAll()
4584" call Decho("exe silent args ".flist)
4585 exe "silent args ".flist
4586 endif
4587
4588" call Dret("s:NetrwMarkFileEdit")
4589endfun
4590
4591" ---------------------------------------------------------------------
4592" s:NetrwMarkFileExe: (invoked by mx) execute arbitrary command on marked files, one at a time {{{2
4593" Uses the local marked-file list.
4594fun! s:NetrwMarkFileExe(islocal)
4595" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")")
4596 let svpos = netrw#NetrwSavePosn()
4597 let curdir = b:netrw_curdir
4598 let curbufnr = bufnr("%")
4599
4600 if exists("s:netrwmarkfilelist_{curbufnr}")
4601 " get the command
4602 call inputsave()
4603 let cmd= input("Enter command: ","","file")
4604 call inputrestore()
4605" call Decho("cmd<".cmd.">")
4606
4607 " apply command to marked files. Substitute: filename -> %
4608 " If no %, then append a space and the filename to the command
4609 for fname in s:netrwmarkfilelist_{curbufnr}
4610 if a:islocal
4611 if g:netrw_keepdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01004612 let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004613 endif
4614 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004615 let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616 endif
4617 if cmd =~ '%'
4618 let xcmd= substitute(cmd,'%',fname,'g')
4619 else
4620 let xcmd= cmd.' '.fname
4621 endif
4622 if a:islocal
4623" call Decho("local: xcmd<".xcmd.">")
4624 let ret= system(xcmd)
4625 else
4626" call Decho("remote: xcmd<".xcmd.">")
4627 let ret= s:RemoteSystem(xcmd)
4628 endif
4629 if v:shell_error < 0
4630 call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
4631 break
4632 else
4633 echo ret
4634 endif
4635 endfor
4636
4637 " unmark marked file list
4638 call s:NetrwUnmarkList(curbufnr,curdir)
4639
4640 " refresh the listing
4641 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4642 call netrw#NetrwRestorePosn(svpos)
4643 else
4644 call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
4645 endif
4646
4647" call Dret("s:NetrwMarkFileExe")
4648endfun
4649
4650" ---------------------------------------------------------------------
4651" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
4652" as the marked file(s) (toggles suffix presence)
4653" Uses the local marked file list.
4654fun! s:NetrwMarkHideSfx(islocal)
4655" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
4656 let svpos = netrw#NetrwSavePosn()
4657 let curbufnr = bufnr("%")
4658
4659 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
4660 if exists("s:netrwmarkfilelist_{curbufnr}")
4661
4662 for fname in s:netrwmarkfilelist_{curbufnr}
4663" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
4664 " construct suffix pattern
4665 if fname =~ '\.'
4666 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
4667 else
4668 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
4669 endif
4670 " determine if its in the hiding list or not
4671 let inhidelist= 0
4672 if g:netrw_list_hide != ""
4673 let itemnum = 0
4674 let hidelist= split(g:netrw_list_hide,',')
4675 for hidepat in hidelist
4676 if sfxpat == hidepat
4677 let inhidelist= 1
4678 break
4679 endif
4680 let itemnum= itemnum + 1
4681 endfor
4682 endif
4683" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
4684 if inhidelist
4685 " remove sfxpat from list
4686 call remove(hidelist,itemnum)
4687 let g:netrw_list_hide= join(hidelist,",")
4688 elseif g:netrw_list_hide != ""
4689 " append sfxpat to non-empty list
4690 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
4691 else
4692 " set hiding list to sfxpat
4693 let g:netrw_list_hide= sfxpat
4694 endif
4695 endfor
4696
4697 " refresh the listing
4698 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4699 call netrw#NetrwRestorePosn(svpos)
4700 else
4701 call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
4702 endif
4703
4704" call Dret("s:NetrwMarkHideSfx")
4705endfun
4706
4707" ---------------------------------------------------------------------
4708" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
4709" Uses the global markfilelist
4710fun! s:NetrwMarkFileGrep(islocal)
4711" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
4712 let svpos = netrw#NetrwSavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004713 let curbufnr = bufnr("%")
4714
4715 if exists("s:netrwmarkfilelist")
4716" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004717 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004718 call s:NetrwUnmarkAll()
4719
4720 " ask user for pattern
4721 call inputsave()
4722 let pat= input("Enter pattern: ","")
4723 call inputrestore()
4724 if pat !~ '^\s'
4725 if pat !~ '^/'
4726 let pat= '/'.pat.'/'
4727 endif
4728 let pat= " ".pat
4729 endif
4730
4731 " use vimgrep for both local and remote
4732" call Decho("exe vimgrep".pat." ".netrwmarkfilelist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004733 try
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004734 exe "keepj noautocmd vimgrep".pat." ".netrwmarkfilelist
Bram Moolenaar5c736222010-01-06 20:54:52 +01004735 catch /^Vim\%((\a\+)\)\=:E480/
4736 call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
4737" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pattern.">")
4738 return
4739 endtry
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740
4741 2match none
4742 call netrw#NetrwRestorePosn(svpos)
4743 endif
4744
4745" call Dret("s:NetrwMarkFileGrep")
4746endfun
4747
4748" ---------------------------------------------------------------------
4749" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
4750" uses the global marked file list
4751" s:netrwmfloc= 0: target directory is remote
4752" = 1: target directory is local
4753fun! s:NetrwMarkFileMove(islocal)
4754" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
4755 let curdir = b:netrw_curdir
4756 let curbufnr = bufnr("%")
4757
4758 " sanity check
4759 if !exists("s:netrwmarkfilelist_{bufnr('%')}") || empty(s:netrwmarkfilelist_{bufnr('%')})
4760 call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
4761" call Dret("s:NetrwMarkFileMove")
4762 return
4763 endif
4764" call Decho("sanity chk passed: s:netrwmarkfilelist_".bufnr('%')."<".string(s:netrwmarkfilelist_{bufnr('%')}))
4765 if !exists("s:netrwmftgt")
4766 call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
4767" call Dret("s:NetrwMarkFileCopy 0")
4768 return 0
4769 endif
4770" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
4771
4772 if a:islocal && s:netrwmftgt_islocal
4773 " move: local -> local
4774" call Decho("move from local to local")
4775" call Decho("(s:NetrwMarkFileMove) local to local move")
4776 if executable(g:netrw_localmovecmd)
4777 for fname in s:netrwmarkfilelist_{bufnr("%")}
4778" call Decho("system(".g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt).")")
4779 let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".shellescape(s:netrwmftgt))
4780 if v:shell_error < 0
4781 call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> failed, aborting",54)
4782 break
4783 endif
4784 endfor
4785 else
4786 call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> is not executable!",57)
4787 endif
4788
4789 elseif a:islocal && !s:netrwmftgt_islocal
4790 " move: local -> remote
4791" call Decho("move from local to remote")
4792" call Decho("copy")
4793 let mflist= s:netrwmarkfilelist_{bufnr("%")}
4794 call s:NetrwMarkFileCopy(a:islocal)
4795" call Decho("remove")
4796 for fname in mflist
4797 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
4798 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
4799 endfor
4800 unlet mflist
4801
4802 elseif !a:islocal && s:netrwmftgt_islocal
4803 " move: remote -> local
4804" call Decho("move from remote to local")
4805" call Decho("copy")
4806 let mflist= s:netrwmarkfilelist_{bufnr("%")}
4807 call s:NetrwMarkFileCopy(a:islocal)
4808" call Decho("remove")
4809 for fname in mflist
4810 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
4811 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
4812 endfor
4813 unlet mflist
4814
4815 elseif !a:islocal && !s:netrwmftgt_islocal
4816 " move: remote -> remote
4817" call Decho("move from remote to remote")
4818" call Decho("copy")
4819 let mflist= s:netrwmarkfilelist_{bufnr("%")}
4820 call s:NetrwMarkFileCopy(a:islocal)
4821" call Decho("remove")
4822 for fname in mflist
4823 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
4824 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
4825 endfor
4826 unlet mflist
4827 endif
4828
4829 " -------
4830 " cleanup
4831 " -------
4832" call Decho("cleanup")
4833
4834 " remove markings from local buffer
4835 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
4836
4837 " refresh buffers
4838 if !s:netrwmftgt_islocal
4839 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
4840 endif
4841 if a:islocal
4842 call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
4843 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004844 if g:netrw_fastbrowse <= 1
4845 call s:LocalBrowseShellCmdRefresh()
4846 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004847
4848" call Dret("s:NetrwMarkFileMove")
4849endfun
4850
4851" ---------------------------------------------------------------------
4852" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
4853" using the hardcopy command. Local marked-file list only.
4854fun! s:NetrwMarkFilePrint(islocal)
4855" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
4856 let curbufnr= bufnr("%")
4857 if exists("s:netrwmarkfilelist_{curbufnr}")
4858 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
4859 let curdir = b:netrw_curdir
4860 call s:NetrwUnmarkList(curbufnr,curdir)
4861 for fname in netrwmarkfilelist
4862 if a:islocal
4863 if g:netrw_keepdir
4864 let fname= s:ComposePath(curdir,fname)
4865 endif
4866 else
4867 let fname= curdir.fname
4868 endif
4869 1split
4870 " the autocmds will handle both local and remote files
4871" call Decho("exe silent e ".escape(fname,' '))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004872 exe "silent e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873" call Decho("hardcopy")
4874 hardcopy
4875 q
4876 endfor
4877 2match none
4878 endif
4879" call Dret("s:NetrwMarkFilePrint")
4880endfun
4881
4882" ---------------------------------------------------------------------
4883" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
4884" files when given a regexp (for which a prompt is
4885" issued).
4886fun! s:NetrwMarkFileRegexp(islocal)
4887" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
4888
4889 " get the regular expression
4890 call inputsave()
4891 let regexp= input("Enter regexp: ","","file")
4892 call inputrestore()
4893
4894 if a:islocal
4895 " get the matching list of files using local glob()
4896" call Decho("handle local regexp")
4897 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004898 let files = glob(s:ComposePath(dirname,regexp))
4899" call Decho("files<".files.">")
4900 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901
4902 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01004903 for fname in filelist
4904" call Decho("fname<".fname.">")
4905 call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
4906 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907
4908 else
4909" call Decho("handle remote regexp")
4910
4911 " convert displayed listing into a filelist
4912 let eikeep = &ei
4913 let areg = @a
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004914 sil keepj %y a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 set ei=all ma
4916" call Decho("set ei=all ma")
4917 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +01004918 call s:NetrwEnew()
4919 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004920 sil keepj norm! "ap
4921 keepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 let bannercnt= search('^" =====','W')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004923 exe "sil keepj 1,".bannercnt."d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 set bt=nofile
4925 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004926 sil keepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01004927 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004928 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004929 sil keepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004931 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004932 sil keepj %s/^| //e
4933 sil! keepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01004934 call histdel("/",-1)
4935 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 endif
4937 " convert regexp into the more usual glob-style format
4938 let regexp= substitute(regexp,'\*','.*','g')
4939" call Decho("regexp<".regexp.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004940 exe "sil! keepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 let filelist= getline(1,line("$"))
4943 q!
4944 for filename in filelist
4945 call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
4946 endfor
4947 unlet filelist
4948 let @a = areg
4949 let &ei = eikeep
4950 endif
4951
4952" call Dret("s:NetrwMarkFileRegexp")
4953endfun
4954
4955" ---------------------------------------------------------------------
4956" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
4957" Uses the local marked file list.
4958fun! s:NetrwMarkFileSource(islocal)
4959" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
4960 let curbufnr= bufnr("%")
4961 if exists("s:netrwmarkfilelist_{curbufnr}")
4962 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
4963 let curdir = b:netrw_curdir
4964 call s:NetrwUnmarkList(curbufnr,curdir)
4965 for fname in netrwmarkfilelist
4966 if a:islocal
4967 if g:netrw_keepdir
4968 let fname= s:ComposePath(curdir,fname)
4969 endif
4970 else
4971 let fname= curdir.fname
4972 endif
4973 " the autocmds will handle sourcing both local and remote files
Bram Moolenaarc236c162008-07-13 17:41:49 +00004974" call Decho("exe so ".fnameescape(fname))
4975 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004976 endfor
4977 2match none
4978 endif
4979" call Dret("s:NetrwMarkFileSource")
4980endfun
4981
4982" ---------------------------------------------------------------------
4983" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
4984" Uses the global markfilelist
4985fun! s:NetrwMarkFileTag(islocal)
4986" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
4987 let svpos = netrw#NetrwSavePosn()
4988 let curdir = b:netrw_curdir
4989 let curbufnr = bufnr("%")
4990
4991 if exists("s:netrwmarkfilelist")
4992" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004993 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004994 call s:NetrwUnmarkAll()
4995
4996 if a:islocal
4997 if executable(g:netrw_ctags)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")")
4999 call system(g:netrw_ctags." ".netrwmarkfilelist)
5000 else
5001 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
5002 endif
5003 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00005004 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 call netrw#NetrwObtain(a:islocal,"tags")
5006 let curdir= b:netrw_curdir
5007 1split
5008 e tags
5009 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
5010" call Decho("curdir<".curdir."> path<".path.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005011 exe 'keepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005012 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005013 wq!
5014 endif
5015 2match none
5016 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5017 call netrw#NetrwRestorePosn(svpos)
5018 endif
5019
5020" call Dret("s:NetrwMarkFileTag")
5021endfun
5022
5023" ---------------------------------------------------------------------
5024" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
5025" Sets up two variables,
5026" s:netrwmftgt : holds the target directory
5027" s:netrwmftgt_islocal : 0=target directory is remote
5028" 1=target directory is local
5029fun! s:NetrwMarkFileTgt(islocal)
5030" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
5031 let svpos = netrw#NetrwSavePosn()
5032 let curdir = b:netrw_curdir
5033 let hadtgt = exists("s:netrwmftgt")
5034 if !exists("w:netrw_bannercnt")
5035 let w:netrw_bannercnt= b:netrw_bannercnt
5036 endif
5037
5038 " set up target
5039 if line(".") < w:netrw_bannercnt
5040 " if cursor in banner region, use b:netrw_curdir for the target
5041 let s:netrwmftgt= b:netrw_curdir
5042" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">")
5043
5044 else
5045 " get word under cursor.
5046 " * If directory, use it for the target.
5047 " * If file, use b:netrw_curdir for the target
5048 let curword= s:NetrwGetWord()
5049 let tgtdir = s:ComposePath(curdir,curword)
5050 if a:islocal && isdirectory(tgtdir)
5051 let s:netrwmftgt = tgtdir
5052" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">")
5053 elseif !a:islocal && tgtdir =~ '/$'
5054 let s:netrwmftgt = tgtdir
5055" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">")
5056 else
5057 let s:netrwmftgt = curdir
5058" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">")
5059 endif
5060 endif
5061 if a:islocal
5062 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
5063 let s:netrwmftgt= simplify(s:netrwmftgt)
5064" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">")
5065 endif
5066 if g:netrw_cygwin
5067 let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','')
5068 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
5069 endif
5070 let s:netrwmftgt_islocal= a:islocal
5071
Bram Moolenaar5c736222010-01-06 20:54:52 +01005072 if g:netrw_fastbrowse <= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 call s:LocalBrowseShellCmdRefresh()
5074 endif
5075 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5076 call netrw#NetrwRestorePosn(svpos)
5077 if !hadtgt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005078 sil! keepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079 endif
5080
5081" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
5082endfun
5083
5084" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00005085" s:NetrwOpenFile: query user for a filename and open it {{{2
5086fun! s:NetrwOpenFile(islocal)
5087" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
5088 call inputsave()
5089 let fname= input("Enter filename: ")
5090 call inputrestore()
5091 if fname !~ '[/\\]'
5092 if exists("b:netrw_curdir")
5093 if exists("g:netrw_quiet")
5094 let netrw_quiet_keep = g:netrw_quiet
5095 endif
5096 let g:netrw_quiet = 1
5097 if b:netrw_curdir =~ '/$'
5098 exe "e ".fnameescape(b:netrw_curdir.fname)
5099 else
5100 exe "e ".fnameescape(b:netrw_curdir."/".fname)
5101 endif
5102 if exists("netrw_quiet_keep")
5103 let g:netrw_quiet= netrw_quiet_keep
5104 else
5105 unlet g:netrw_quiet
5106 endif
5107 endif
5108 else
5109 exe "e ".fnameescape(fname)
5110 endif
5111" call Dret("s:NetrwOpenFile")
5112endfun
5113
5114" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115" s:NetrwUnmarkList: delete local marked file lists and remove their contents from the global marked-file list {{{2
5116fun! s:NetrwUnmarkList(curbufnr,curdir)
5117" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
5118
5119 " remove all files in local marked-file list from global list
5120 if exists("s:netrwmarkfilelist_{a:curbufnr}")
5121 for mfile in s:netrwmarkfilelist_{a:curbufnr}
5122 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
5123 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
5124 call remove(s:netrwmarkfilelist,idx) " remove from global list
5125 endfor
5126 if s:netrwmarkfilelist == []
5127 unlet s:netrwmarkfilelist
5128 endif
5129
5130 " getting rid of the local marked-file lists is easy
5131 unlet s:netrwmarkfilelist_{a:curbufnr}
5132 endif
5133 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
5134 unlet s:netrwmarkfilemtch_{a:curbufnr}
5135 endif
5136 2match none
5137" call Dret("s:NetrwUnmarkList")
5138endfun
5139
5140" ---------------------------------------------------------------------
5141" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
5142fun! s:NetrwUnmarkAll()
5143" call Dfunc("s:NetrwUnmarkAll()")
5144 if exists("s:netrwmarkfilelist")
5145 unlet s:netrwmarkfilelist
5146 endif
5147 silent call s:NetrwUnmarkAll2()
5148 2match none
5149" call Dret("s:NetrwUnmarkAll")
5150endfun
5151
5152" ---------------------------------------------------------------------
5153" s:NetrwUnmarkAll2: {{{2
5154fun! s:NetrwUnmarkAll2()
5155" call Dfunc("s:NetrwUnmarkAll2()")
5156 redir => netrwmarkfilelist_let
5157 let
5158 redir END
5159 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
5160 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
5161 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
5162 for flist in netrwmarkfilelist_list
5163 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
5164 unlet s:netrwmarkfilelist_{curbufnr}
5165 unlet s:netrwmarkfilemtch_{curbufnr}
5166 endfor
5167" call Dret("s:NetrwUnmarkAll2")
5168endfun
5169
5170" ---------------------------------------------------------------------
5171" s:NetrwUnMarkFile: {{{2
5172fun! s:NetrwUnMarkFile(islocal)
5173" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
5174 let svpos = netrw#NetrwSavePosn()
5175 let curbufnr = bufnr("%")
5176
5177 " unmark marked file list (although I expect s:NetrwUpload()
5178 " to do it, I'm just making sure)
5179 if exists("s:netrwmarkfilelist_{bufnr('%')}")
5180" call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%"))
5181 unlet s:netrwmarkfilelist
5182 unlet s:netrwmarkfilelist_{curbufnr}
5183 unlet s:netrwmarkfilemtch_{curbufnr}
5184 2match none
5185 endif
5186
5187" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5188 call netrw#NetrwRestorePosn(svpos)
5189" call Dret("s:NetrwUnMarkFile")
5190endfun
5191
5192" ---------------------------------------------------------------------
5193" s:NetrwMenu: generates the menu for gvim and netrw {{{2
5194fun! s:NetrwMenu(domenu)
5195
5196 if !exists("g:NetrwMenuPriority")
5197 let g:NetrwMenuPriority= 80
5198 endif
5199
5200 if has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu
5201" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
5202
5203 if !exists("s:netrw_menu_enabled") && a:domenu
5204" call Decho("initialize menu")
5205 let s:netrw_menu_enabled= 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005206 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
5207 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
5208 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
5209 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
5210 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
5211 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
5212 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
5213 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
5214 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
5215 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
5216 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
5217 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
5218 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
5219 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005220 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005221 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
5222 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
5223 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
5224 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
5225 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
5226 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
5227 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
5228 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
5229 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
5230 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
5231 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
5232 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
5233 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
5234 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
5235 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
5236 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
5237 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
5238 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
5239 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
5240 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
5241 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
5242 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
5243 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
5244 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
5245 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
5246 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
5247 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
5248 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
5249 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
5250 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1 '.g:NetrwTopLvlMenu.'Style.Listing\ Style\ (thin-long-wide-tree)<tab>i i'
5251 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show<tab>a a'
5252 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
5253 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method\ (name-time-size)<tab>s s'
5254 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
5255 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005256 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
Bram Moolenaar446cb832008-06-24 21:56:24 +00005257 let s:netrw_menucnt= 28
5258
5259 elseif !a:domenu
5260 let s:netrwcnt = 0
5261 let curwin = winnr()
5262 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
5263 exe curwin."wincmd w"
5264
5265 if s:netrwcnt <= 1
5266" call Decho("clear menus")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005267 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaar446cb832008-06-24 21:56:24 +00005268" call Decho('exe silent! unmenu '.g:NetrwTopLvlMenu.'*')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005269 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00005270 endif
5271 endif
5272" call Dret("NetrwMenu")
5273 endif
5274
5275endfun
5276
5277" ---------------------------------------------------------------------
5278" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
5279" Used by the O maps (as <SID>NetrwObtain())
5280fun! s:NetrwObtain(islocal)
5281" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
5282
5283 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005284 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://'
5285 call netrw#NetrwObtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00005286 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
5287 else
5288 call netrw#NetrwObtain(a:islocal,expand("<cWORD>"))
5289 endif
5290
5291" call Dret("NetrwObtain")
5292endfun
5293
5294" ---------------------------------------------------------------------
5295" netrw#NetrwObtain: {{{2
5296" netrw#NetrwObtain(islocal,fname[,tgtdirectory])
5297" islocal=0 obtain from remote source
5298" =1 obtain from local source
5299" fname : a filename or a list of filenames
5300" tgtdir : optional place where files are to go (not present, uses getcwd())
5301fun! netrw#NetrwObtain(islocal,fname,...)
5302" call Dfunc("netrw#NetrwObtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
5303 " NetrwStatusLine support - for obtaining support
5304
5305 if type(a:fname) == 1
5306 let fnamelist= [ a:fname ]
5307 elseif type(a:fname) == 3
5308 let fnamelist= a:fname
5309 else
5310 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
5311" call Dret("netrw#NetrwObtain")
5312 return
5313 endif
5314" call Decho("fnamelist<".string(fnamelist).">")
5315 if a:0 > 0
5316 let tgtdir= a:1
5317 else
5318 let tgtdir= getcwd()
5319 endif
5320" call Decho("tgtdir<".tgtdir.">")
5321
Bram Moolenaar5c736222010-01-06 20:54:52 +01005322 if exists("b:netrw_islocal") && b:netrw_islocal
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005323 " obtain a file from local b:netrw_curdir to (local) tgtdir
5324" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005325 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
5326 let topath= s:ComposePath(tgtdir,"")
5327 if (has("win32") || has("win95") || has("win64") || has("win16"))
5328 " transfer files one at time
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005329" call Decho("transfer files one at a time")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005330 for fname in fnamelist
Bram Moolenaarc236c162008-07-13 17:41:49 +00005331" call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")")
5332 call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005333 endfor
5334 else
5335 " transfer files with one command
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005336" call Decho("transfer files with one command")
5337 let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005338" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")")
5339 call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
5340 endif
5341 elseif !exists("b:netrw_curdir")
5342 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
5343 else
5344 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
5345 endif
5346
5347 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005348 " obtain files from remote b:netrw_curdir to local tgtdir
5349" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005350 if type(a:fname) == 1
5351 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
5352 endif
5353 call s:NetrwMethod(b:netrw_curdir)
5354
5355 if b:netrw_method == 4
5356 " obtain file using scp
5357" call Decho("obtain via scp (method#4)")
5358 if exists("g:netrw_port") && g:netrw_port != ""
5359 let useport= " ".g:netrw_scpport." ".g:netrw_port
5360 else
5361 let useport= ""
5362 endif
5363 if b:netrw_fname =~ '/'
5364 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
5365 else
5366 let path= ""
5367 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005368 let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005369" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1))
5370 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005371
5372 elseif b:netrw_method == 2
5373 " obtain file using ftp + .netrc
5374" call Decho("obtain via ftp+.netrc (method #2)")
5375 call s:SaveBufVars()|silent keepjumps new|call s:RestoreBufVars()
5376 let tmpbufnr= bufnr("%")
5377 setlocal ff=unix
5378 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005379 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00005380" call Decho("filter input: ".getline('$'))
5381 endif
5382
5383 if exists("b:netrw_fname") && b:netrw_fname != ""
5384 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
5385" call Decho("filter input: ".getline('$'))
5386 endif
5387
5388 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005389 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005390" call Decho("filter input: ".getline('$'))
5391 endif
5392 for fname in fnamelist
5393 call setline(line("$")+1,'get "'.fname.'"')
5394" call Decho("filter input: ".getline('$'))
5395 endfor
5396 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00005397" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
5398 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00005400" call Decho("executing: %!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
5401 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402 endif
5403 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
5404 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
5405 let debugkeep= &debug
5406 setlocal debug=msg
5407 call netrw#ErrorMsg(s:ERROR,getline(1),4)
5408 let &debug= debugkeep
5409 endif
5410
5411 elseif b:netrw_method == 3
5412 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
5413" call Decho("obtain via ftp+mipf (method #3)")
5414 call s:SaveBufVars()|silent keepjumps new|call s:RestoreBufVars()
5415 let tmpbufnr= bufnr("%")
5416 setlocal ff=unix
5417
5418 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005419 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420" call Decho("filter input: ".getline('$'))
5421 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005422 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423" call Decho("filter input: ".getline('$'))
5424 endif
5425
5426 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005427 keepj put =g:netrw_uid
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428" call Decho("filter input: ".getline('$'))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005429 keepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430" call Decho("filter input: ".getline('$'))
5431 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005432 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433" call Decho("filter input: ".getline('$'))
5434 endif
5435
5436 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005437 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438" call Decho("filter input: ".getline('$'))
5439 endif
5440
5441 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005442 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443" call Decho("filter input: ".getline('$'))
5444 endif
5445
5446 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005447 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448" call Decho("filter input: ".getline('$'))
5449 endif
5450
5451 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005452 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005453" call Decho("filter input: ".getline('$'))
5454 endif
5455 for fname in fnamelist
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005456 keepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005457 endfor
5458" call Decho("filter input: ".getline('$'))
5459
5460 " perform ftp:
5461 " -i : turns off interactive prompting from ftp
5462 " -n unix : DON'T use <.netrc>, even though it exists
5463 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005464 keepj norm! 1Gdd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005465" call Decho("executing: %!".g:netrw_ftp_cmd." -i -n")
5466 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
5467 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
5468 if getline(1) !~ "^$"
5469" call Decho("error<".getline(1).">")
5470 if !exists("g:netrw_quiet")
5471 call netrw#ErrorMsg(s:ERROR,getline(1),5)
5472 endif
5473 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005474 elseif !exists("b:netrw_method") || b:netrw_method < 0
5475" call Dfunc("netrw#NetrwObtain : unsupported method")
5476 return
5477 endif
5478
5479 " restore status line
5480 if type(a:fname) == 1 && exists("s:netrw_users_stl")
5481 call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005482 endif
5483
5484 endif
5485
5486 " cleanup
5487 if exists("tmpbufnr")
5488 if bufnr("%") != tmpbufnr
5489 exe tmpbufnr."bw!"
5490 else
5491 q!
5492 endif
5493 endif
5494
5495" call Dret("netrw#NetrwObtain")
5496endfun
5497
5498" ---------------------------------------------------------------------
5499" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
5500" If there's only one window, then the window will first be split.
5501" Returns:
5502" choice = 0 : didn't have to choose
5503" choice = 1 : saved modified file in window first
5504" choice = 2 : didn't save modified file, opened window
5505" choice = 3 : cancel open
5506fun! s:NetrwPrevWinOpen(islocal)
5507" call Dfunc("NetrwPrevWinOpen(islocal=".a:islocal.")")
5508
5509 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
5510 let curdir = b:netrw_curdir
5511
5512 " get last window number and the word currently under the cursor
5513 let lastwinnr = winnr("$")
5514 let curword = s:NetrwGetWord()
5515 let choice = 0
5516" call Decho("lastwinnr=".lastwinnr." curword<".curword.">")
5517
5518 let didsplit = 0
5519 if lastwinnr == 1
5520 " if only one window, open a new one first
5521" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
5522 if g:netrw_preview
5523" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".g:netrw_winsize."wincmd s")
5524 exe (g:netrw_alto? "top " : "bot ")."vert ".g:netrw_winsize."wincmd s"
5525 else
5526" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s")
5527 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
5528 endif
5529 let didsplit = 1
5530
5531 else
5532 call s:SaveBufVars()
5533" call Decho("wincmd p")
5534 wincmd p
5535 call s:RestoreBufVars()
5536 " if the previous window's buffer has been changed (is modified),
5537 " and it doesn't appear in any other extant window, then ask the
5538 " user if s/he wants to abandon modifications therein.
5539 let bnr = winbufnr(0)
5540 let bnrcnt = 0
5541 if &mod
5542" call Decho("detected: prev window's buffer has been modified: bnr=".bnr." winnr#".winnr())
5543 let eikeep= &ei
5544 set ei=all
5545 windo if winbufnr(0) == bnr | let bnrcnt=bnrcnt+1 | endif
5546 exe bnr."wincmd p"
5547 let &ei= eikeep
5548" call Decho("bnr=".bnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr#".winnr())
5549 if bnrcnt == 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01005550 let bufname = bufname(winbufnr(winnr()))
5551 let choice = confirm("Save modified file<".bufname.">?","&Yes\n&No\n&Cancel")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005552" call Decho("bufname<".bufname."> choice=".choice." winnr#".winnr())
5553
5554 if choice == 1
5555 " Yes -- write file & then browse
5556 let v:errmsg= ""
5557 silent w
5558 if v:errmsg != ""
5559 call netrw#ErrorMsg(s:ERROR,"unable to write <".bufname.">!",30)
5560 if didsplit
5561 q
5562 else
5563 wincmd p
5564 endif
5565" call Dret("NetrwPrevWinOpen ".choice." : unable to write <".bufname.">")
5566 return choice
5567 endif
5568
5569 elseif choice == 2
5570 " No -- don't worry about changed file, just browse anyway
5571 setlocal nomod
5572 call netrw#ErrorMsg(s:WARNING,bufname." changes to ".bufname." abandoned",31)
5573 wincmd p
5574
5575 else
5576 " Cancel -- don't do this
5577 if didsplit
5578 q
5579 else
5580 wincmd p
5581 endif
5582" call Dret("NetrwPrevWinOpen ".choice." : cancelled")
5583 return choice
5584 endif
5585 endif
5586 endif
5587 endif
5588
5589 " restore b:netrw_curdir (window split/enew may have lost it)
5590 let b:netrw_curdir= curdir
5591 if a:islocal < 2
5592 if a:islocal
5593 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
5594 else
5595 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
5596 endif
5597 endif
5598" call Dret("NetrwPrevWinOpen ".choice)
5599 return choice
5600endfun
5601
5602" ---------------------------------------------------------------------
5603" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
5604" Always assumed to be local -> remote
5605" call s:NetrwUpload(filename, target)
5606" call s:NetrwUpload(filename, target, fromdirectory)
5607fun! s:NetrwUpload(fname,tgt,...)
5608" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
5609
5610 if a:tgt =~ '^\a\+://'
5611 let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','')
5612 else
5613 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
5614 endif
5615" call Decho("tgtdir<".tgtdir.">")
5616
5617 if a:0 > 0
5618 let fromdir= a:1
5619 else
5620 let fromdir= getcwd()
5621 endif
5622" call Decho("fromdir<".fromdir.">")
5623
5624 if type(a:fname) == 1
5625 " handle uploading a single file using NetWrite
5626" call Decho("handle uploading a single file via NetWrite")
5627 1split
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005628" call Decho("exe e ".fnameescape(a:fname))
5629 exe "e ".fnameescape(a:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005630" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines")
5631 if a:tgt =~ '/$'
5632 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00005633" call Decho("exe w! ".fnameescape(wfname))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005634 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005635 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00005636" call Decho("writing local->remote: exe w ".fnameescape(a:tgt))
5637 exe "w ".fnameescape(a:tgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005638" call Decho("done writing local->remote")
5639 endif
5640 q!
5641
5642 elseif type(a:fname) == 3
5643 " handle uploading a list of files via scp
5644" call Decho("handle uploading a list of files via scp")
5645 let curdir= getcwd()
5646 if a:tgt =~ '^scp:'
5647 exe "keepjumps silent lcd ".fnameescape(fromdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005648 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
5649 let args = join(map(filelist,"shellescape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005650 if exists("g:netrw_port") && g:netrw_port != ""
5651 let useport= " ".g:netrw_scpport." ".g:netrw_port
5652 else
5653 let useport= ""
5654 endif
5655 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
5656 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00005657" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1))
5658 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005659 exe "keepjumps silent lcd ".fnameescape(curdir)
5660
5661 elseif a:tgt =~ '^ftp:'
5662 call s:NetrwMethod(a:tgt)
5663
5664 if b:netrw_method == 2
5665 " handle uploading a list of files via ftp+.netrc
5666 let netrw_fname = b:netrw_fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005667 sil keepj new
Bram Moolenaar446cb832008-06-24 21:56:24 +00005668" call Decho("filter input window#".winnr())
5669
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005670 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00005671" call Decho("filter input: ".getline('$'))
5672
5673 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005674 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005675" call Decho("filter input: ".getline('$'))
5676 endif
5677
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005678 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005679" call Decho("filter input: ".getline('$'))
5680
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005681 keepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005682" call Decho("filter input: ".getline('$'))
5683
5684 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005685 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005686" call Decho("filter input: ".getline('$'))
5687 endfor
5688
5689 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00005690" call Decho("executing: ".s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
5691 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005692 else
5693" call Decho("filter input window#".winnr())
Bram Moolenaarc236c162008-07-13 17:41:49 +00005694" call Decho("executing: ".s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
5695 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005696 endif
5697 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005698 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01005699 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005700 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
5701 call netrw#ErrorMsg(s:ERROR,getline(1),14)
5702 else
5703 bw!|q
5704 endif
5705
5706 elseif b:netrw_method == 3
5707 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
5708 let netrw_fname= b:netrw_fname
5709 call s:SaveBufVars()|silent keepjumps new|call s:RestoreBufVars()
5710 let tmpbufnr= bufnr("%")
5711 setlocal ff=unix
5712
5713 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005714 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00005715" call Decho("filter input: ".getline('$'))
5716 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005717 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00005718" call Decho("filter input: ".getline('$'))
5719 endif
5720
5721 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005722 keepj put =g:netrw_uid
Bram Moolenaar446cb832008-06-24 21:56:24 +00005723" call Decho("filter input: ".getline('$'))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005724 keepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005725" call Decho("filter input: ".getline('$'))
5726 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005727 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005728" call Decho("filter input: ".getline('$'))
5729 endif
5730
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005731 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005732" call Decho("filter input: ".getline('$'))
5733
5734 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005735 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005736" call Decho("filter input: ".getline('$'))
5737 endif
5738
5739 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005740 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005741" call Decho("filter input: ".getline('$'))
5742 endif
5743
5744 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005745 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005746" call Decho("filter input: ".getline('$'))
5747 endfor
5748
5749 " perform ftp:
5750 " -i : turns off interactive prompting from ftp
5751 " -n unix : DON'T use <.netrc>, even though it exists
5752 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005753 keepj norm! 1Gdd
Bram Moolenaar446cb832008-06-24 21:56:24 +00005754" call Decho("executing: ".s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n")
5755 exe s:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n"
5756 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005757 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01005758 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005759 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
5760 let debugkeep= &debug
5761 setlocal debug=msg
5762 call netrw#ErrorMsg(s:ERROR,getline(1),15)
5763 let &debug = debugkeep
5764 let mod = 1
5765 else
5766 bw!|q
5767 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005768 elseif !exists("b:netrw_method") || b:netrw_method < 0
5769" call Dfunc("netrw#NetrwUpload : unsupported method")
5770 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00005771 endif
5772 else
5773 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
5774 endif
5775 endif
5776
5777" call Dret("s:NetrwUpload")
5778endfun
5779
5780" ---------------------------------------------------------------------
5781" s:NetrwPreview: {{{2
5782fun! s:NetrwPreview(path) range
5783" call Dfunc("NetrwPreview(path<".a:path.">)")
5784 call s:NetrwOptionSave("s:")
5785 call s:NetrwSafeOptions()
5786 if has("quickfix")
5787 if !isdirectory(a:path)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005788 if g:netrw_preview && !g:netrw_alto
5789 let pvhkeep= &pvh
5790 let &pvh = winwidth(0) - g:netrw_winsize
5791 endif
5792 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
5793 if exists("pvhkeep")
5794 let &pvh= pvhkeep
5795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005796 elseif !exists("g:netrw_quiet")
5797 call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
5798 endif
5799 elseif !exists("g:netrw_quiet")
5800 call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
5801 endif
5802 call s:NetrwOptionRestore("s:")
5803" call Dret("NetrwPreview")
5804endfun
5805
5806" ---------------------------------------------------------------------
5807" s:NetrwRefresh: {{{2
5808fun! s:NetrwRefresh(islocal,dirname)
5809" call Dfunc("NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
5810 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
5811 " NetrwBrowseChgDir() may clear the display; hence a NetrwSavePosn() may not work if its placed here.
5812 " Also, NetrwBrowseChgDir() now does a NetrwSavePosn() itself.
5813 setlocal ma noro
5814" call Decho("setlocal ma noro")
5815" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005816 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00005817 if a:islocal
5818 call netrw#LocalBrowseCheck(a:dirname)
5819 else
5820 call s:NetrwBrowse(a:islocal,a:dirname)
5821 endif
5822 call netrw#NetrwRestorePosn()
5823
5824 " restore file marks
5825 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
5826" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
5827 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
5828 else
5829" call Decho("2match none")
5830 2match none
5831 endif
5832
5833" redraw!
5834" call Dret("NetrwRefresh")
5835endfun
5836
5837" ---------------------------------------------------------------------
5838" s:NetrwRefreshDir: refreshes a directory by name {{{2
5839" Called by NetrwMarkFileCopy()
5840" Interfaces to s:NetrwRefresh() and s:LocalBrowseShellCmdRefresh()
5841fun! s:NetrwRefreshDir(islocal,dirname)
5842" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) fastbrowse=".g:netrw_fastbrowse)
5843 if g:netrw_fastbrowse == 0
5844 " slowest mode (keep buffers refreshed, local or remote)
5845" call Decho("slowest mode: keep buffers refreshed, local or remote")
5846 let tgtwin= bufwinnr(a:dirname)
5847" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin)
5848
5849 if tgtwin > 0
5850 " tgtwin is being displayed, so refresh it
5851 let curwin= winnr()
5852" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")")
5853 exe tgtwin."wincmd w"
5854 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5855 exe curwin."wincmd w"
5856
5857 elseif bufnr(a:dirname) > 0
5858 let bn= bufnr(a:dirname)
5859" call Decho("bd bufnr(".a:dirname.")=".bn)
5860 exe "silent bd ".bn
5861 endif
5862
5863 elseif g:netrw_fastbrowse <= 1
5864" call Decho("medium-speed mode: refresh local buffers only")
5865 call s:LocalBrowseShellCmdRefresh()
5866 endif
5867" call Dret("s:NetrwRefreshDir")
5868endfun
5869
5870" ---------------------------------------------------------------------
5871" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
5872" What this function does is to compute a priority for the patterns
5873" in the g:netrw_sort_sequence. It applies a substitute to any
5874" "files" that satisfy each pattern, putting the priority / in
5875" front. An "*" pattern handles the default priority.
5876fun! s:NetrwSetSort()
5877" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
5878 if w:netrw_liststyle == s:LONGLIST
5879 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
5880 else
5881 let seqlist = g:netrw_sort_sequence
5882 endif
5883 " sanity check -- insure that * appears somewhere
5884 if seqlist == ""
5885 let seqlist= '*'
5886 elseif seqlist !~ '\*'
5887 let seqlist= seqlist.',*'
5888 endif
5889 let priority = 1
5890 while seqlist != ""
5891 if seqlist =~ ','
5892 let seq = substitute(seqlist,',.*$','','e')
5893 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
5894 else
5895 let seq = seqlist
5896 let seqlist = ""
5897 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01005899 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01005901 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005903 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00005904 endif
5905" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
5906
5907 " sanity check
5908 if w:netrw_bannercnt > line("$")
5909 " apparently no files were left after a Hiding pattern was used
5910" call Dret("SetSort : no files left after hiding")
5911 return
5912 endif
5913 if seq == '*'
5914 let starpriority= spriority
5915 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005916 exe 'sil keepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005917 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918 " sometimes multiple sorting patterns will match the same file or directory.
5919 " The following substitute is intended to remove the excess matches.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005920 exe 'sil keepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005921 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922 endif
5923 let priority = priority + 1
5924 endwhile
5925 if exists("starpriority")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005926 exe 'sil keepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005927 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005928 endif
5929
5930 " Following line associated with priority -- items that satisfy a priority
5931 " pattern get prefixed by ###/ which permits easy sorting by priority.
5932 " Sometimes files can satisfy multiple priority patterns -- only the latest
5933 " priority pattern needs to be retained. So, at this point, these excess
5934 " priority prefixes need to be removed, but not directories that happen to
5935 " be just digits themselves.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005936 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01005937 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938
5939" call Dret("SetSort")
5940endfun
5941
5942" =====================================================================
5943" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
5944fun! s:NetrwSortStyle(islocal)
5945" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
5946 call s:NetrwSaveWordPosn()
5947 let svpos= netrw#NetrwSavePosn()
5948
5949 let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005950 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5952 call netrw#NetrwRestorePosn(svpos)
5953
5954" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
5955endfun
5956
5957" ---------------------------------------------------------------------
5958" s:NetrwSplit: mode {{{2
5959" =0 : net and o
5960" =1 : net and t
5961" =2 : net and v
5962" =3 : local and o
5963" =4 : local and t
5964" =5 : local and v
5965fun! s:NetrwSplit(mode)
5966" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
5967
5968 call s:SaveWinVars()
5969
5970 if a:mode == 0
5971 " remote and o
5972" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s")
5973 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
5974 let s:didsplit= 1
5975 call s:RestoreWinVars()
5976 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
5977 unlet s:didsplit
5978
5979 elseif a:mode == 1
5980 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00005982" call Decho("tabnew")
5983 tabnew
5984 let s:didsplit= 1
5985 call s:RestoreWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005987 unlet s:didsplit
5988
5989 elseif a:mode == 2
5990 " remote and v
5991" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v")
5992 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
5993 let s:didsplit= 1
5994 call s:RestoreWinVars()
5995 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
5996 unlet s:didsplit
5997
5998 elseif a:mode == 3
5999 " local and o
6000" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s")
6001 exe (g:netrw_alto? "bel " : "abo ").g:netrw_winsize."wincmd s"
6002 let s:didsplit= 1
6003 call s:RestoreWinVars()
6004 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
6005 unlet s:didsplit
6006
6007 elseif a:mode == 4
6008 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00006009 let cursorword = s:NetrwGetWord()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006010 let netrw_curdir= s:NetrwTreeDir()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006011" call Decho("tabnew")
6012 tabnew
6013 let b:netrw_curdir= netrw_curdir
6014 let s:didsplit= 1
6015 call s:RestoreWinVars()
6016 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
6017 unlet s:didsplit
6018
6019 elseif a:mode == 5
6020 " local and v
6021" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v")
6022 exe (g:netrw_altv? "rightb " : "lefta ").g:netrw_winsize."wincmd v"
6023 let s:didsplit= 1
6024 call s:RestoreWinVars()
6025 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
6026 unlet s:didsplit
6027
6028 else
6029 call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
6030 endif
6031
6032" call Dret("s:NetrwSplit")
6033endfun
6034
6035" ---------------------------------------------------------------------
6036" NetrwStatusLine: {{{2
6037fun! NetrwStatusLine()
6038
6039" vvv NetrwStatusLine() debugging vvv
6040" let g:stlmsg=""
6041" if !exists("w:netrw_explore_bufnr")
6042" let g:stlmsg="!X<explore_bufnr>"
6043" elseif w:netrw_explore_bufnr != bufnr("%")
6044" let g:stlmsg="explore_bufnr!=".bufnr("%")
6045" endif
6046" if !exists("w:netrw_explore_line")
6047" let g:stlmsg=" !X<explore_line>"
6048" elseif w:netrw_explore_line != line(".")
6049" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
6050" endif
6051" if !exists("w:netrw_explore_list")
6052" let g:stlmsg=" !X<explore_list>"
6053" endif
6054" ^^^ NetrwStatusLine() debugging ^^^
6055
6056 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")
6057 " restore user's status line
6058 let &stl = s:netrw_users_stl
6059 let &laststatus = s:netrw_users_ls
6060 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
6061 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
6062 return ""
6063 else
6064 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
6065 endif
6066endfun
6067
6068" ---------------------------------------------------------------------
6069" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
6070" (full path directory with trailing slash returned)
6071fun! s:NetrwTreeDir()
6072" call Dfunc("NetrwTreeDir() curline#".line(".")."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
6073
6074 let treedir= b:netrw_curdir
6075" call Decho("set initial treedir<".treedir.">")
6076 let s:treecurpos= netrw#NetrwSavePosn()
6077
6078 if w:netrw_liststyle == s:TREELIST
6079" call Decho("w:netrrw_liststyle is TREELIST:")
6080" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006081
6082 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006083 if getline('.') =~ '/$'
6084 let treedir= substitute(getline('.'),'^\%(| \)*\([^|].\{-}\)$','\1','e')
6085 else
6086 let treedir= ""
6087 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006088" call Decho("treedir<".treedir.">")
6089
6090 " detect user attempting to close treeroot
6091 if getline('.') !~ '|' && getline('.') != '..'
6092" call Decho("user attempted to close treeroot")
6093 " now force a refresh
6094" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006095 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006096" call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
6097 return b:netrw_curdir
6098 endif
6099
6100 " elide all non-depth information
6101 let depth = substitute(getline('.'),'^\(\%(| \)*\)[^|].\{-}$','\1','e')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006102" call Decho("depth<".depth."> 1st subst (non-depth info removed)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006103
6104 " elide first depth
6105 let depth = substitute(depth,'^| ','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006106" call Decho("depth<".depth."> 2nd subst (first depth removed)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006107
6108 " construct treedir by searching backwards at correct depth
6109" call Decho("constructing treedir<".treedir."> depth<".depth.">")
6110 while depth != "" && search('^'.depth.'[^|].\{-}/$','bW')
6111 let dirname= substitute(getline('.'),'^\(| \)*','','e')
6112 let treedir= dirname.treedir
6113 let depth = substitute(depth,'^| ','','')
6114" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">")
6115 endwhile
6116 if w:netrw_treetop =~ '/$'
6117 let treedir= w:netrw_treetop.treedir
6118 else
6119 let treedir= w:netrw_treetop.'/'.treedir
6120 endif
6121" call Decho("bufnr(.)=".bufnr("%")." line($)=".line("$")." line(.)=".line("."))
6122 endif
6123 let treedir= substitute(treedir,'//$','/','')
6124
Bram Moolenaar446cb832008-06-24 21:56:24 +00006125" call Dret("NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
6126 return treedir
6127endfun
6128
6129" ---------------------------------------------------------------------
6130" s:NetrwTreeDisplay: recursive tree display {{{2
6131fun! s:NetrwTreeDisplay(dir,depth)
6132" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
6133
6134 " insure that there are no folds
6135 setlocal nofen
6136
6137 " install ../ and shortdir
6138 if a:depth == ""
6139 call setline(line("$")+1,'../')
6140" call Decho("setline#".line("$")." ../ (depth is zero)")
6141 endif
6142 if a:dir =~ '^\a\+://'
6143 if a:dir == w:netrw_treetop
6144 let shortdir= a:dir
6145 else
6146 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
6147 endif
6148 call setline(line("$")+1,a:depth.shortdir)
6149 else
6150 let shortdir= substitute(a:dir,'^.*/','','e')
6151 call setline(line("$")+1,a:depth.shortdir.'/')
6152 endif
6153" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">")
6154
6155 " append a / to dir if its missing one
6156 let dir= a:dir
6157 if dir !~ '/$'
6158 let dir= dir.'/'
6159 endif
6160
6161 " display subtrees (if any)
6162 let depth= "| ".a:depth
6163
6164" call Decho("display subtrees with depth<".depth."> and current leaves")
6165 for entry in w:netrw_treedict[a:dir]
6166 let direntry= substitute(dir.entry,'/$','','e')
6167" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">")
6168 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
6169" call Decho("<".direntry."> is a key in treedict - display subtree for it")
6170 call s:NetrwTreeDisplay(direntry,depth)
6171 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
6172" call Decho("<".direntry."/> is a key in treedict - display subtree for it")
6173 call s:NetrwTreeDisplay(direntry.'/',depth)
6174 else
6175" call Decho("<".entry."> is not a key in treedict (no subtree)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006176 sil! keepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006177 endif
6178 endfor
6179" call Dret("NetrwTreeDisplay")
6180endfun
6181
6182" ---------------------------------------------------------------------
6183" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
6184fun! s:NetrwTreeListing(dirname)
6185 if w:netrw_liststyle == s:TREELIST
6186" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
6187" call Decho("curdir<".a:dirname.">")
6188" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exit")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"))
6189
6190 " update the treetop
6191" call Decho("update the treetop")
6192 if !exists("w:netrw_treetop")
6193 let w:netrw_treetop= a:dirname
6194" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)")
6195 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
6196 let w:netrw_treetop= a:dirname
6197" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)")
6198 endif
6199
6200 " insure that we have at least an empty treedict
6201 if !exists("w:netrw_treedict")
6202 let w:netrw_treedict= {}
6203 endif
6204
6205 " update the directory listing for the current directory
6206" call Decho("updating dictionary with ".a:dirname.":[..directory listing..]")
6207" call Decho("bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006208 exe "sil! keepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006209 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006210" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006211 exe "sil! keepj ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006212
6213 " if past banner, record word
6214 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
6215 let fname= expand("<cword>")
6216 else
6217 let fname= ""
6218 endif
6219" call Decho("fname<".fname.">")
6220
6221 " display from treetop on down
6222 call s:NetrwTreeDisplay(w:netrw_treetop,"")
6223
6224" call Dret("NetrwTreeListing : bufname<".expand("%").">")
6225 endif
6226endfun
6227
6228" ---------------------------------------------------------------------
6229" s:NetrwWideListing: {{{2
6230fun! s:NetrwWideListing()
6231
6232 if w:netrw_liststyle == s:WIDELIST
6233" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
6234 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006235 " cpf: characters per filename
6236 " fpl: filenames per line
6237 " fpc: filenames per column
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238 setlocal ma noro
6239" call Decho("setlocal ma noro")
6240 let b:netrw_cpf= 0
6241 if line("$") >= w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006242 exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006243 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244 else
6245" call Dret("NetrwWideListing")
6246 return
6247 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006248 let b:netrw_cpf= b:netrw_cpf + 2
6249" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250
6251 " determine qty files per line (fpl)
6252 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
6253 if w:netrw_fpl <= 0
6254 let w:netrw_fpl= 1
6255 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006256" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257
6258 " make wide display
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006259 exe 'sil keepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006260 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
6262 let newcolstart = w:netrw_bannercnt + fpc
6263 let newcolend = newcolstart + fpc - 1
6264" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006265 sil! let keepregstar = @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00006266 while line("$") >= newcolstart
6267 if newcolend > line("$") | let newcolend= line("$") | endif
6268 let newcolqty= newcolend - newcolstart
6269 exe newcolstart
6270 if newcolqty == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006271 exe "sil! keepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006273 exe "sil! keepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006275 exe "sil! keepj ".newcolstart.','.newcolend.'d'
6276 exe 'sil! keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 endwhile
6278 silent! let @*= keepregstar
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006279 exe "sil! keepj ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006280 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 setlocal noma nomod ro
6282" call Dret("NetrwWideListing")
6283 endif
6284
6285endfun
6286
6287" ---------------------------------------------------------------------
6288" s:PerformListing: {{{2
6289fun! s:PerformListing(islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006290" call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291
6292 call s:NetrwSafeOptions()
6293 setlocal noro ma
6294" call Decho("setlocal noro ma")
6295
6296" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
6297" call Decho("(netrw) Processing your browsing request...")
6298" endif " Decho
6299
6300" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
6301 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6302 " force a refresh for tree listings
6303" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006304 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 endif
6306
6307 " save current directory on directory history list
Bram Moolenaar5c736222010-01-06 20:54:52 +01006308 call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309
6310 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01006311 if g:netrw_banner
6312" call Decho("set up banner")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006313 keepj put ='\" ============================================================================'
6314 keepj put ='\" Netrw Directory Listing (netrw '.g:loaded_netrw.')'
6315 keepj put ='\" '.b:netrw_curdir
6316 keepj 1d
Bram Moolenaar5c736222010-01-06 20:54:52 +01006317 let w:netrw_bannercnt= 3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006318 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01006319 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006320 keepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01006321 let w:netrw_bannercnt= 1
6322 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323
6324 let sortby= g:netrw_sort_by
6325 if g:netrw_sort_direction =~ "^r"
6326 let sortby= sortby." reversed"
6327 endif
6328
6329 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01006330 if g:netrw_banner
6331" call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">")
6332 if g:netrw_sort_by =~ "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333" call Decho("directories will be sorted by name")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006334 " sorted by name
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006335 keepj put ='\" Sorted by '.sortby
6336 keepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01006337 let w:netrw_bannercnt= w:netrw_bannercnt + 2
6338 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00006339" call Decho("directories will be sorted by size or time")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006340 " sorted by size or date
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006341 keepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01006342 let w:netrw_bannercnt= w:netrw_bannercnt + 1
6343 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006344 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346
6347 " show copy/move target, if any
Bram Moolenaar5c736222010-01-06 20:54:52 +01006348 if g:netrw_banner
6349 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
6350" call Decho("show copy/move target<".s:netrwmftgt.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006351 keepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01006352 if s:netrwmftgt_islocal
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006353 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006354 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006355 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006356 endif
6357 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01006359" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006360 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006361 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006362 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363
6364 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01006365 if g:netrw_banner
6366" call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)")
6367 if g:netrw_list_hide != "" && g:netrw_hide
6368 if g:netrw_hide == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006369 keepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01006370 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006371 keepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01006372 endif
6373 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006375 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006376 keepj put ='\" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec'
6377 keepj put ='\" ============================================================================'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006378 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006380
6381 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01006382 if g:netrw_banner
6383 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006384 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01006385" call Decho("bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"))
6386 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387
6388 " set up syntax highlighting {{{3
6389" call Decho("set up syntax highlighting")
6390 if has("syntax")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006391 setf netrw
Bram Moolenaar446cb832008-06-24 21:56:24 +00006392 if !exists("g:syntax_on") || !g:syntax_on
6393 setlocal ft=
6394 endif
6395 endif
6396
6397 " get list of files
6398" call Decho("Get list of files - islocal=".a:islocal)
6399 if a:islocal
6400 call s:LocalListing()
6401 else " remote
6402 call s:NetrwRemoteListing()
6403 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006404" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405
6406 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01006407 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006408" call Decho("manipulate directory listing (hide)")
6409" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
6410 if g:netrw_hide && g:netrw_list_hide != ""
6411 call s:NetrwListHide()
6412 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006413 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">")
6415
6416 if g:netrw_sort_by =~ "^n"
6417 " sort by name
6418 call s:NetrwSetSort()
6419
Bram Moolenaar5c736222010-01-06 20:54:52 +01006420 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")")
6422 if g:netrw_sort_direction =~ 'n'
6423 " normal direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006424 exe 'sil keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006425 else
6426 " reverse direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006427 exe 'sil keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 endif
6429 endif
6430 " remove priority pattern prefix
6431" call Decho("remove priority pattern prefix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006432 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006433 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434
6435 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01006436 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction)
6438 if g:netrw_sort_direction =~ 'n'
6439" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006440 exe 'sil! keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006441 else
6442" call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort!')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006443 exe 'sil! keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00006444 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006445 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006446 call histdel("/",-1)
6447 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006448 endif
6449
6450 elseif g:netrw_sort_direction =~ 'r'
6451" call Decho('reverse the sorted listing')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006452 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006453 exe 'sil! keepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01006454 call histdel("/",-1)
6455 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006456 endif
6457 endif
6458
6459 " convert to wide/tree listing {{{3
6460" call Decho("modify display if wide/tree listing style")
6461 call s:NetrwWideListing()
6462 call s:NetrwTreeListing(b:netrw_curdir)
6463
Bram Moolenaar5c736222010-01-06 20:54:52 +01006464 if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006465 " place cursor on the top-left corner of the file listing
6466" call Decho("place cursor on top-left corner of file listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006467 exe 'sil! keepj '.w:netrw_bannercnt
6468 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006469 endif
6470
6471 " record previous current directory
6472 let w:netrw_prvdir= b:netrw_curdir
6473" call Decho("record netrw_prvdir<".w:netrw_prvdir.">")
6474
6475 " save certain window-oriented variables into buffer-oriented variables {{{3
6476 call s:SetBufWinVars()
6477 call s:NetrwOptionRestore("w:")
6478
6479 " set display to netrw display settings
6480" call Decho("set display to netrw display settings (noma nomod etc)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006481 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00006482 if exists("s:treecurpos")
6483
6484 call netrw#NetrwRestorePosn(s:treecurpos)
6485 unlet s:treecurpos
6486 endif
6487
6488" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
6489endfun
6490
6491" ---------------------------------------------------------------------
6492" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00006493fun! s:SetupNetrwStatusLine(statline)
6494" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
6495
6496 if !exists("s:netrw_setup_statline")
6497 let s:netrw_setup_statline= 1
6498" call Decho("do first-time status line setup")
6499
6500 if !exists("s:netrw_users_stl")
6501 let s:netrw_users_stl= &stl
6502 endif
6503 if !exists("s:netrw_users_ls")
6504 let s:netrw_users_ls= &laststatus
6505 endif
6506
6507 " set up User9 highlighting as needed
6508 let keepa= @a
6509 redir @a
6510 try
6511 hi User9
6512 catch /^Vim\%((\a\+)\)\=:E411/
6513 if &bg == "dark"
6514 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
6515 else
6516 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
6517 endif
6518 endtry
6519 redir END
6520 let @a= keepa
6521 endif
6522
6523 " set up status line (may use User9 highlighting)
6524 " insure that windows have a statusline
6525 " make sure statusline is displayed
6526 let &stl=a:statline
6527 setlocal laststatus=2
6528" call Decho("stl=".&stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006529 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00006530
6531" call Dret("SetupNetrwStatusLine : stl=".&stl)
6532endfun
6533
6534" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006535" Remote Directory Browsing Support: {{{1
6536" ===========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00006537
6538" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006539" s:NetrwRemoteListing: {{{2
6540fun! s:NetrwRemoteListing()
6541" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00006542
Bram Moolenaar446cb832008-06-24 21:56:24 +00006543 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006544
Bram Moolenaar446cb832008-06-24 21:56:24 +00006545 " sanity check:
6546 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
6547" call Decho("b:netrw_method=".b:netrw_method)
6548 if !executable("ftp")
6549 if !exists("g:netrw_quiet")
6550 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
6551 endif
6552 call s:NetrwOptionRestore("w:")
6553" call Dret("s:NetrwRemoteListing")
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006554 return
6555 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006556
6557 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
6558 if !exists("g:netrw_quiet")
6559 if g:netrw_list_cmd == ""
6560 call netrw#ErrorMsg(s:ERROR,g:netrw_ssh_cmd." is not executable on your system",47)
6561 else
6562 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
6563 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006564 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006565
Bram Moolenaar446cb832008-06-24 21:56:24 +00006566 call s:NetrwOptionRestore("w:")
6567" call Dret("s:NetrwRemoteListing")
6568 return
6569 endif " (remote handling sanity check)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006570
Bram Moolenaar446cb832008-06-24 21:56:24 +00006571 if exists("b:netrw_method")
6572" call Decho("setting w:netrw_method<".b:netrw_method.">")
6573 let w:netrw_method= b:netrw_method
6574 endif
6575
6576 if s:method == "ftp"
6577 " use ftp to get remote file listing
6578" call Decho("use ftp to get remote file listing")
6579 let s:method = "ftp"
6580 let listcmd = g:netrw_ftp_list_cmd
6581 if g:netrw_sort_by =~ '^t'
6582 let listcmd= g:netrw_ftp_timelist_cmd
6583 elseif g:netrw_sort_by =~ '^s'
6584 let listcmd= g:netrw_ftp_sizelist_cmd
6585 endif
6586" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)")
6587 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006588" exe "sil! keepalt keepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006589
6590 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
6591 " shorten the listing
6592" call Decho("generate short listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006593 exe "sil! keepalt keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006594
6595 " cleanup
6596 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006597 exe "sil! keepalt keepj g/".g:netrw_ftp_browse_reject."/keepj d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01006598 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006599 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006600 sil! keepj %s/\r$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006601 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006602
6603 " if there's no ../ listed, then put ./ and ../ in
6604 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006605 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006606 let line2= search('^\.\.\/\%(\s\|$\)','cnW')
6607 if line2 == 0
6608" call Decho("netrw is putting ./ and ../ into listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006609 sil! keepj put='../'
6610 sil! keepj put='./'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006612 exe "sil! keepj ".line1
6613 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006614
6615" call Decho("line1=".line1." line2=".line2." line(.)=".line("."))
6616 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
6617" call Decho("M$ ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006618 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006619 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006620 else " normal ftp cleanup
6621" call Decho("normal ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006622 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
6623 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
6624 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006625 call histdel("/",-1)
6626 call histdel("/",-1)
6627 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006628 endif
6629 endif
6630
6631 else
6632 " use ssh to get remote file listing {{{3
6633" call Decho("use ssh to get remote file listing: s:path<".s:path.">")
6634 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
6635" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)")
6636 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006637" call Decho("1: exe silent r! ".shellescape(listcmd.s:path, 1))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006638 exe "sil! keepj r! ".listcmd.shellescape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006639 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006640 sil! keepj g/^Listing directory/keepj d
6641 sil! keepj g/^d[-rwx][-rwx][-rwx]/keepj s+$+/+e
6642 sil! keepj g/^l[-rwx][-rwx][-rwx]/keepj s+$+@+e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006643 call histdel("/",-1)
6644 call histdel("/",-1)
6645 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006646 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006647 sil! keepj g/^[dlsp-][-rwx][-rwx][-rwx]/keepj s/^.*\s\(\S\+\)$/\1/e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006648 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006649 endif
6650 else
6651 if s:path == ""
6652" call Decho("2: exe silent r! ".listcmd)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006653 exe "sil! keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006654 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00006655" call Decho("3: exe silent r! ".listcmd.' '.shellescape(s:path,1))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006656 exe "sil! keepalt r! ".listcmd.' '.shellescape(s:path,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006657" call Decho("listcmd<".listcmd."> path<".s:path.">")
6658 endif
6659 endif
6660
6661 " cleanup
6662 if g:netrw_ftp_browse_reject != ""
6663" call Decho("(cleanup) exe silent! g/".g:netrw_ssh_browse_reject."/keepjumps d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006664 exe "sil! g/".g:netrw_ssh_browse_reject."/keepj d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01006665 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006666 endif
6667 endif
6668
6669 if w:netrw_liststyle == s:LONGLIST
6670 " do a long listing; these substitutions need to be done prior to sorting {{{3
6671" call Decho("fix long listing:")
6672
6673 if s:method == "ftp"
6674 " cleanup
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006675 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00006676 while getline('.') =~ g:netrw_ftp_browse_reject
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006677 sil! keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006678 endwhile
6679 " if there's no ../ listed, then put ./ and ../ in
6680 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006681 sil! keepj 1
6682 sil! keepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00006683 let line2= line(".")
6684 if line2 == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006685 exe 'sil! keepj '.w:netrw_bannercnt."put='./'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006686 if b:netrw_curdir != '/'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006687 exe 'sil! keepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006688 endif
6689 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006690 exe "sil! keepj ".line1
6691 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006692 endif
6693
6694 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
6695" call Decho("M$ ftp site listing cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006696 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006697 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
6698" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006699 exe 'sil keepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
6700 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
6701 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01006702 call histdel("/",-1)
6703 call histdel("/",-1)
6704 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006705 endif
6706 endif
6707
6708" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006709" exe "keepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006710" endif " Decho
6711" call Dret("s:NetrwRemoteListing")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00006712endfun
6713
Bram Moolenaar446cb832008-06-24 21:56:24 +00006714" ---------------------------------------------------------------------
6715" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
6716fun! s:NetrwRemoteRm(usrhost,path) range
6717" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
6718" call Decho("firstline=".a:firstline." lastline=".a:lastline)
6719 let svpos= netrw#NetrwSavePosn()
6720
6721 let all= 0
6722 if exists("s:netrwmarkfilelist_{bufnr('%')}")
6723 " remove all marked files
Bram Moolenaar5c736222010-01-06 20:54:52 +01006724" call Decho("remove all marked files with bufnr#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006725 for fname in s:netrwmarkfilelist_{bufnr("%")}
6726 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
6727 if ok =~ 'q\%[uit]'
6728 break
6729 elseif ok =~ 'a\%[ll]'
6730 let all= 1
6731 endif
6732 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01006733 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006734
6735 else
6736 " remove files specified by range
Bram Moolenaar5c736222010-01-06 20:54:52 +01006737" call Decho("remove files specified by range")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006738
6739 " preparation for removing multiple files/directories
6740 let ctr= a:firstline
6741
6742 " remove multiple files and directories
6743 while ctr <= a:lastline
6744 exe ctr
6745 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
6746 if ok =~ 'q\%[uit]'
6747 break
6748 elseif ok =~ 'a\%[ll]'
6749 let all= 1
6750 endif
6751 let ctr= ctr + 1
6752 endwhile
6753 endif
6754
6755 " refresh the (remote) directory listing
6756" call Decho("refresh remote directory listing")
6757 call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
6758 call netrw#NetrwRestorePosn(svpos)
6759
6760" call Dret("s:NetrwRemoteRm")
6761endfun
6762
6763" ---------------------------------------------------------------------
6764" s:NetrwRemoteRmFile: {{{2
6765fun! s:NetrwRemoteRmFile(path,rmfile,all)
6766" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
6767
6768 let all= a:all
6769 let ok = ""
6770
6771 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
6772 " attempt to remove file
6773" call Decho("attempt to remove file (all=".all.")")
6774 if !all
6775 echohl Statement
6776" call Decho("case all=0:")
6777 call inputsave()
6778 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
6779 call inputrestore()
6780 echohl NONE
6781 if ok == ""
6782 let ok="no"
6783 endif
6784 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
6785 if ok =~ 'a\%[ll]'
6786 let all= 1
6787 endif
6788 endif
6789
6790 if all || ok =~ 'y\%[es]' || ok == ""
6791" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""))
6792 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
6793" call Decho("case ftp:")
6794 let path= a:path
6795 if path =~ '^\a\+://'
6796 let path= substitute(path,'^\a\+://[^/]\+/','','')
6797 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006798 sil! keepj .,$d
Bram Moolenaar446cb832008-06-24 21:56:24 +00006799 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
6800 else
6801" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">")
6802 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
6803" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
6804 if !exists("b:netrw_curdir")
6805 call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
6806 let ok="q"
6807 else
6808 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
6809" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
6810" call Decho("remotedir<".remotedir.">")
6811" call Decho("rmfile<".a:rmfile.">")
6812 if remotedir != ""
6813 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile))
6814 else
6815 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile))
6816 endif
6817" call Decho("call system(".netrw_rm_cmd.")")
6818 let ret= system(netrw_rm_cmd)
6819 if ret != 0
6820 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
6821 endif
6822" call Decho("returned=".ret." errcode=".v:shell_error)
6823 endif
6824 endif
6825 elseif ok =~ 'q\%[uit]'
6826" call Decho("ok==".ok)
6827 break
6828 endif
6829
6830 else
6831 " attempt to remove directory
6832" call Decho("attempt to remove directory")
6833 if !all
6834 call inputsave()
6835 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
6836 call inputrestore()
6837 if ok == ""
6838 let ok="no"
6839 endif
6840 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
6841 if ok =~ 'a\%[ll]'
6842 let all= 1
6843 endif
6844 endif
6845
6846 if all || ok =~ 'y\%[es]' || ok == ""
6847 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
6848 call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
6849 else
6850 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01006851 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006852" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
Bram Moolenaarc236c162008-07-13 17:41:49 +00006853 let ret= system(netrw_rmdir_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854" call Decho("returned=".ret." errcode=".v:shell_error)
6855
6856 if v:shell_error != 0
Bram Moolenaarc236c162008-07-13 17:41:49 +00006857" call Decho("v:shell_error not 0")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006858 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.shellescape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
Bram Moolenaarc236c162008-07-13 17:41:49 +00006859" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
6860 let ret= system(netrw_rmf_cmd)
6861" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862
6863 if v:shell_error != 0 && !exists("g:netrw_quiet")
6864 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
6865 endif
6866 endif
6867 endif
6868
6869 elseif ok =~ 'q\%[uit]'
6870 break
6871 endif
6872 endif
6873
6874" call Dret("s:NetrwRemoteRmFile ".ok)
6875 return ok
6876endfun
6877
6878" ---------------------------------------------------------------------
6879" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
6880" This function assumes that a long listing will be received. Size, time,
6881" and reverse sorts will be requested of the server but not otherwise
6882" enforced here.
6883fun! s:NetrwRemoteFtpCmd(path,listcmd)
6884" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) netrw_method=".w:netrw_method)
6885" call Decho("line($)=".line("$")." bannercnt=".w:netrw_bannercnt)
6886
6887 " because WinXX ftp uses unix style input
6888 let ffkeep= &ff
6889 setlocal ma ff=unix noro
6890" call Decho("setlocal ma ff=unix noro")
6891
6892 " clear off any older non-banner lines
6893 " note that w:netrw_bannercnt indexes the line after the banner
6894" call Decho('exe silent! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)")
6895 exe "silent! keepjumps ".w:netrw_bannercnt.",$d"
6896
6897 ".........................................
6898 if w:netrw_method == 2 || w:netrw_method == 5
6899 " ftp + <.netrc>: Method #2
6900 if a:path != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006901 keepj put ='cd \"'.a:path.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 endif
6903 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006904 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905" call Decho("filter input: ".getline('.'))
6906 endif
6907 call setline(line("$")+1,a:listcmd)
6908" exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
6909 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00006910" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
6911 exe s:netrw_silentxfer." keepjumps ".w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00006913" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
6914 exe s:netrw_silentxfer." keepjumps ".w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006915 endif
6916
6917 ".........................................
6918 elseif w:netrw_method == 3
6919 " ftp + machine,id,passwd,filename: Method #3
6920 setlocal ff=unix
6921 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006922 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006924 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 endif
6926
6927 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006928 keepj put =g:netrw_uid
6929 keepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006931 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 endif
6933
6934 if a:path != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006935 keepj put ='cd \"'.a:path.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
6937 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006938 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939" call Decho("filter input: ".getline('.'))
6940 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006941 keepj call setline(line("$")+1,a:listcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
6943 " perform ftp:
6944 " -i : turns off interactive prompting from ftp
6945 " -n unix : DON'T use <.netrc>, even though it exists
6946 " -n win32: quit being obnoxious about password
6947" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
6948" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i -n")
6949 exe s:netrw_silentxfer.w:netrw_bannercnt.",$!".g:netrw_ftp_cmd." -i -n"
6950
6951 ".........................................
6952 else
6953 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",23)
6954 endif
6955
6956 " cleanup for Windows
6957 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006958 sil! keepj %s/\r$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006959 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960 endif
6961 if a:listcmd == "dir"
6962 " infer directory/link based on the file permission string
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006963 sil! keepj g/d\%([-r][-w][-x]\)\{3}/keepj s@$@/@
6964 sil! keepj g/l\%([-r][-w][-x]\)\{3}/keepj s/$/@/
Bram Moolenaar5c736222010-01-06 20:54:52 +01006965 call histdel("/",-1)
6966 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006968 exe "sil! keepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006969 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 endif
6971 endif
6972
6973 " ftp's listing doesn't seem to include ./ or ../
6974 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006975 exe 'keepj '.w:netrw_bannercnt
6976 keepj put ='./'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 endif
6978 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006979 exe 'keepj '.w:netrw_bannercnt
6980 keepj put ='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 endif
6982
6983 " restore settings
6984 let &ff= ffkeep
6985" call Dret("NetrwRemoteFtpCmd")
6986endfun
6987
6988" ---------------------------------------------------------------------
6989" s:NetrwRemoteRename: rename a remote file or directory {{{2
6990fun! s:NetrwRemoteRename(usrhost,path) range
6991" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
6992
6993 " preparation for removing multiple files/directories
6994 let svpos = netrw#NetrwSavePosn()
6995 let ctr = a:firstline
6996 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
6997
6998 " rename files given by the markfilelist
6999 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7000 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7001" call Decho("oldname<".oldname.">")
7002 if exists("subfrom")
7003 let newname= substitute(oldname,subfrom,subto,'')
7004" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7005 else
7006 call inputsave()
7007 let newname= input("Moving ".oldname." to : ",oldname)
7008 call inputrestore()
7009 if newname =~ '^s/'
7010 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
7011 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
7012 let newname = substitute(oldname,subfrom,subto,'')
7013" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7014 endif
7015 endif
7016
7017 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
7018 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
7019 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007020 let oldname= shellescape(a:path.oldname)
7021 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007022" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
7023 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007024 endif
7025
7026 endfor
7027 call s:NetrwUnMarkFile(1)
7028
7029 else
7030
7031 " attempt to rename files/directories
7032 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007033 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007034
7035 let oldname= s:NetrwGetWord()
7036" call Decho("oldname<".oldname.">")
7037
7038 call inputsave()
7039 let newname= input("Moving ".oldname." to : ",oldname)
7040 call inputrestore()
7041
7042 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
7043 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
7044 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007045 let oldname= shellescape(a:path.oldname)
7046 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007047" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
7048 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049 endif
7050
7051 let ctr= ctr + 1
7052 endwhile
7053 endif
7054
7055 " refresh the directory
7056 call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
7057 call netrw#NetrwRestorePosn(svpos)
7058
7059" call Dret("NetrwRemoteRename")
7060endfun
7061
7062" ---------------------------------------------------------------------
7063" Local Directory Browsing Support: {{{1
7064" ==========================================
7065
7066" ---------------------------------------------------------------------
7067" netrw#LocalBrowseCheck: {{{2
7068fun! netrw#LocalBrowseCheck(dirname)
7069 " unfortunate interaction -- split window debugging can't be
7070 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
7071 " event triggers another call to LocalBrowseCheck() when attempts
7072 " to write to the DBG buffer are made.
7073 " The &ft == "netrw" test was installed because the BufEnter event
7074 " would hit when re-entering netrw windows, creating unexpected
7075 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007076" call Decho("netrw#LocalBrowseCheck: isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : "")))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 if isdirectory(a:dirname)
7078" call Decho(" ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$"))
7079 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname)
7080 silent! call s:NetrwBrowse(1,a:dirname)
7081 elseif &ft == "netrw" && line("$") == 1
7082 silent! call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007083 elseif exists("s:treeforceredraw")
7084 unlet s:treeforceredraw
7085 silent! call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007086 endif
7087 endif
7088 " not a directory, ignore it
7089endfun
7090
7091" ---------------------------------------------------------------------
7092" s:LocalListing: does the job of "ls" for local directories {{{2
7093fun! s:LocalListing()
7094" call Dfunc("s:LocalListing()")
7095" call Decho("&ma=".&ma)
7096" call Decho("&mod=".&mod)
7097" call Decho("&ro=".&ro)
7098" call Decho("bufname(%)<".bufname("%").">")
7099
7100" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif
7101" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist")|endif
7102
7103 " get the list of files contained in the current directory
7104 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007105 let dirnamelen = s:Strlen(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 let filelist = glob(s:ComposePath(dirname,"*"))
7107" call Decho("glob(dirname<".dirname."/*>)=".filelist)
7108 if filelist != ""
7109 let filelist= filelist."\n"
7110 endif
7111 let filelist= filelist.glob(s:ComposePath(dirname,".*"))
7112" call Decho("glob(dirname<".dirname."/.*>)=".filelist)
7113
7114 " Coding choice: either elide ./ if present
7115 " or include ./ if not present
7116 if filelist =~ '[\\/]\.[\\/]\=\(\n\|$\)'
7117 " elide /path/. from glob() entries if present
7118" call Decho("elide /path/. from glob entries if present")
7119 let filelist = substitute(filelist,'\n','\t','g')
7120 let filelist = substitute(filelist,'^[^\t]\+[/\\]\.\t','','')
7121 let filelist = substitute(filelist,'[^\t]\+[/\\]\.$','','')
7122 let filelist = substitute(filelist,'\t\zs[^\t]\+[/\\]\.\t','','')
7123 let filelist = substitute(filelist,'\t','\n','g')
7124 endif
7125" call Decho("filelist<".filelist.">")
7126 if filelist !~ '[\\/]\.\.[\\/]\=\(\n\|$\)'
7127 " include ../ in the glob() entry if its missing
7128" call Decho("forcibly tacking on ..")
7129 let filelist= filelist."\n".s:ComposePath(b:netrw_curdir,"../")
7130" call Decho("filelist<".filelist.">")
7131 endif
7132 if b:netrw_curdir == '/'
7133 " remove .. from filelist when current directory is root directory
7134" call Decho("remove .. from filelist")
7135 let filelist= substitute(filelist,'/\.\.\n','','')
7136 endif
7137 " remove multiple contiguous newlines
7138 let filelist= substitute(filelist,'\n\{2,}','\n','ge')
7139 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7140 " change all \s to /s
7141" call Decho('change all \s to /s')
7142 let filelist= substitute(filelist,'\','/','g')
7143 else
7144 " escape all \s to \\
7145" call Decho('escape all \s to \\')
7146 let filelist= substitute(filelist,'\','\\','g')
7147 endif
7148
7149" call Decho("(before while) dirname<".dirname.">")
7150" call Decho("(before while) dirnamelen<".dirnamelen.">")
7151" call Decho("(before while) filelist<".filelist.">")
7152
7153 while filelist != ""
7154 if filelist =~ '\n'
7155 let filename = substitute(filelist,'\n.*$','','e')
7156 let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e')
7157 else
7158 let filename = filelist
7159 let filelist = ""
7160 endif
7161" call Decho(" ")
7162" call Decho("(while) filelist<".filelist.">")
7163" call Decho("(while) filename<".filename.">")
7164
7165 if getftype(filename) == "link"
7166 " indicate a symbolic link
7167" call Decho("indicate <".filename."> is a symbolic link with trailing @")
7168 let pfile= filename."@"
7169
7170 elseif getftype(filename) == "socket"
7171 " indicate a socket
7172" call Decho("indicate <".filename."> is a socket with trailing =")
7173 let pfile= filename."="
7174
7175 elseif getftype(filename) == "fifo"
7176 " indicate a fifo
7177" call Decho("indicate <".filename."> is a fifo with trailing |")
7178 let pfile= filename."|"
7179
7180 elseif isdirectory(filename)
7181 " indicate a directory
7182" call Decho("indicate <".filename."> is a directory with trailing /")
7183 let pfile= filename."/"
7184
7185 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename)
7186 if (has("win32") || has("win95") || has("win64") || has("win16"))
7187 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
7188 " indicate an executable
7189" call Decho("indicate <".filename."> is executable with trailing *")
7190 let pfile= filename."*"
7191 else
7192 " normal file
7193 let pfile= filename
7194 endif
7195 elseif executable(filename)
7196 " indicate an executable
7197" call Decho("indicate <".filename."> is executable with trailing *")
7198 let pfile= filename."*"
7199 else
7200 " normal file
7201 let pfile= filename
7202 endif
7203
7204 else
7205 " normal file
7206 let pfile= filename
7207 endif
7208" call Decho("pfile<".pfile."> (after *@/ appending)")
7209
7210 if pfile =~ '//$'
7211 let pfile= substitute(pfile,'//$','/','e')
7212" call Decho("change // to /: pfile<".pfile.">")
7213 endif
7214 let pfile= strpart(pfile,dirnamelen)
7215 let pfile= substitute(pfile,'^[/\\]','','e')
7216" call Decho("filename<".filename.">")
7217" call Decho("pfile <".pfile.">")
7218
7219 if w:netrw_liststyle == s:LONGLIST
7220 let sz = getfsize(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007221 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaar446cb832008-06-24 21:56:24 +00007222 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
7223" call Decho("sz=".sz." fsz=".fsz)
7224 endif
7225
7226 if g:netrw_sort_by =~ "^t"
7227 " sort by time (handles time up to 1 quintillion seconds, US)
7228" call Decho("getftime(".filename.")=".getftime(filename))
7229 let t = getftime(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007230 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar446cb832008-06-24 21:56:24 +00007231" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
7232 let ftpfile= ft.'/'.pfile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007233 sil! keepj put=ftpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007234
7235 elseif g:netrw_sort_by =~ "^s"
7236 " sort by size (handles file sizes up to 1 quintillion bytes, US)
7237" call Decho("getfsize(".filename.")=".getfsize(filename))
7238 let sz = getfsize(filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007239 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar446cb832008-06-24 21:56:24 +00007240" call Decho("exe keepjumps put ='".fsz.'/'.filename."'")
7241 let fszpfile= fsz.'/'.pfile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007242 sil! keepj put =fszpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007243
7244 else
7245 " sort by name
7246" call Decho("exe keepjumps put ='".pfile."'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007247 sil! keepj put=pfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007248 endif
7249 endwhile
7250
7251 " cleanup any windows mess at end-of-line
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007252 sil! keepj g/^$/d
7253 sil! keepj %s/\r$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007254 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255 exe "setlocal ts=".g:netrw_maxfilenamelen
7256" call Decho("setlocal ts=".g:netrw_maxfilenamelen)
7257
7258" call Dret("s:LocalListing")
7259endfun
7260
7261" ---------------------------------------------------------------------
7262" s:LocalBrowseShellCmdRefresh: this function is called after a user has {{{2
7263" performed any shell command. The idea is to cause all local-browsing
7264" buffers to be refreshed after a user has executed some shell command,
7265" on the chance that s/he removed/created a file/directory with it.
7266fun! s:LocalBrowseShellCmdRefresh()
7267" call Dfunc("LocalBrowseShellCmdRefresh() browselist=".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "empty")." ".tabpagenr("$")." tabs")
7268 " determine which buffers currently reside in a tab
7269 if !exists("s:netrw_browselist")
7270" call Dret("LocalBrowseShellCmdRefresh : browselist is empty")
7271 return
7272 endif
7273 if !exists("w:netrw_bannercnt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007274" call Dret("LocalBrowseShellCmdRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007275 return
7276 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007277 if exists("s:locbrowseshellcmd")
7278 if s:locbrowseshellcmd
7279 let s:locbrowseshellcmd= 0
7280" call Dret("LocalBrowseShellCmdRefresh : NetrwBrowse itself caused the refresh")
7281 return
7282 endif
7283 let s:locbrowseshellcmd= 0
7284 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007285 let itab = 1
7286 let buftablist = []
7287 while itab <= tabpagenr("$")
7288 let buftablist = buftablist + tabpagebuflist()
7289 let itab = itab + 1
7290 tabn
7291 endwhile
7292" call Decho("buftablist".string(buftablist))
7293" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">")
7294 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
7295 " | refresh any netrw window
7296 " | wipe out any non-displaying netrw buffer
7297 let curwin = winnr()
7298 let ibl = 0
7299 for ibuf in s:netrw_browselist
7300" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf))
7301 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
7302 " wipe out any non-displaying netrw buffer
7303" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007304 exe "sil! bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007305 call remove(s:netrw_browselist,ibl)
7306" call Decho("browselist=".string(s:netrw_browselist))
7307 continue
7308 elseif index(tabpagebuflist(),ibuf) != -1
7309 " refresh any netrw buffer
7310" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
7311 exe bufwinnr(ibuf)."wincmd w"
7312 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
7313 endif
7314 let ibl= ibl + 1
7315 endfor
7316 exe curwin."wincmd w"
7317
7318" call Dret("LocalBrowseShellCmdRefresh")
7319endfun
7320
7321" ---------------------------------------------------------------------
7322" s:NetrwLocalRm: {{{2
7323fun! s:NetrwLocalRm(path) range
7324" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
7325" call Decho("firstline=".a:firstline." lastline=".a:lastline)
7326
7327 " preparation for removing multiple files/directories
7328 let ret = 0
7329 let all = 0
7330 let svpos = netrw#NetrwSavePosn()
7331
7332 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7333 " remove all marked files
7334" call Decho("remove all marked files")
7335 for fname in s:netrwmarkfilelist_{bufnr("%")}
7336 let ok= s:NetrwLocalRmFile(a:path,fname,all)
7337 if ok =~ 'q\%[uit]' || ok == "no"
7338 break
7339 elseif ok =~ 'a\%[ll]'
7340 let all= 1
7341 endif
7342 endfor
7343 call s:NetrwUnMarkFile(1)
7344
7345 else
7346 " remove (multiple) files and directories
7347" call Decho("remove files in range [".a:firstline.",".a:lastline."]")
7348
7349 let ctr = a:firstline
7350 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007351 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007352
7353 " sanity checks
7354 if line(".") < w:netrw_bannercnt
7355 let ctr= ctr + 1
7356 continue
7357 endif
7358 let curword= s:NetrwGetWord()
7359 if curword == "./" || curword == "../"
7360 let ctr= ctr + 1
7361 continue
7362 endif
7363 let ok= s:NetrwLocalRmFile(a:path,curword,all)
7364 if ok =~ 'q\%[uit]' || ok == "no"
7365 break
7366 elseif ok =~ 'a\%[ll]'
7367 let all= 1
7368 endif
7369 let ctr= ctr + 1
7370 endwhile
7371 endif
7372
7373 " refresh the directory
7374" call Decho("bufname<".bufname("%").">")
7375 if bufname("%") != "NetrwMessage"
7376 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
7377 call netrw#NetrwRestorePosn(svpos)
7378 endif
7379
7380" call Dret("s:NetrwLocalRm")
7381endfun
7382
7383" ---------------------------------------------------------------------
7384" s:NetrwLocalRmFile: remove file fname given the path {{{2
7385" Give confirmation prompt unless all==1
7386fun! s:NetrwLocalRmFile(path,fname,all)
7387" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
7388
7389 let all= a:all
7390 let ok = ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007391 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392 let rmfile= s:ComposePath(a:path,a:fname)
7393" call Decho("rmfile<".rmfile.">")
7394
7395 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
7396 " attempt to remove file
7397" call Decho("attempt to remove file<".rmfile.">")
7398 if !all
7399 echohl Statement
7400 call inputsave()
7401 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
7402 call inputrestore()
7403 echohl NONE
7404 if ok == ""
7405 let ok="no"
7406 endif
7407" call Decho("response: ok<".ok.">")
7408 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
7409" call Decho("response: ok<".ok."> (after sub)")
7410 if ok =~ 'a\%[ll]'
7411 let all= 1
7412 endif
7413 endif
7414
7415 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00007416 let ret= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417" call Decho("errcode=".v:shell_error." ret=".ret)
7418 endif
7419
7420 else
7421 " attempt to remove directory
7422 if !all
7423 echohl Statement
7424 call inputsave()
7425 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
7426 call inputrestore()
7427 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
7428 if ok == ""
7429 let ok="no"
7430 endif
7431 if ok =~ 'a\%[ll]'
7432 let all= 1
7433 endif
7434 endif
7435 let rmfile= substitute(rmfile,'[\/]$','','e')
7436
7437 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar5c736222010-01-06 20:54:52 +01007438" call Decho("1st attempt: system(netrw#WinPath(".g:netrw_local_rmdir.') '.shellescape(rmfile).')')
7439 call system(netrw#WinPath(g:netrw_local_rmdir).' '.shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007440" call Decho("v:shell_error=".v:shell_error)
7441
7442 if v:shell_error != 0
7443" call Decho("2nd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00007444 let errcode= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445" call Decho("errcode=".errcode)
7446
7447 if errcode != 0
7448 if has("unix")
7449" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00007450 call system("rm ".shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 if v:shell_error != 0 && !exists("g:netrw_quiet")
7452 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
7453 let ok="no"
7454 endif
7455 elseif !exists("g:netrw_quiet")
7456 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
7457 let ok="no"
7458 endif
7459 endif
7460 endif
7461 endif
7462 endif
7463
7464" call Dret("s:NetrwLocalRmFile ".ok)
7465 return ok
7466endfun
7467
7468" ---------------------------------------------------------------------
7469" s:NetrwLocalRename: rename a remote file or directory {{{2
7470fun! s:NetrwLocalRename(path) range
7471" call Dfunc("NetrwLocalRename(path<".a:path.">)")
7472
7473 " preparation for removing multiple files/directories
7474 let ctr = a:firstline
7475 let svpos= netrw#NetrwSavePosn()
7476
7477 " rename files given by the markfilelist
7478 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7479 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7480" call Decho("oldname<".oldname.">")
7481 if exists("subfrom")
7482 let newname= substitute(oldname,subfrom,subto,'')
7483" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7484 else
7485 call inputsave()
7486 let newname= input("Moving ".oldname." to : ",oldname)
7487 call inputrestore()
7488 if newname =~ '^s/'
7489 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
7490 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
7491" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
7492 let newname = substitute(oldname,subfrom,subto,'')
7493 endif
7494 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007495 call rename(oldname,newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007496 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01007497 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007498
7499 else
7500
7501 " attempt to rename files/directories
7502 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007503 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007504
7505 " sanity checks
7506 if line(".") < w:netrw_bannercnt
7507 let ctr= ctr + 1
7508 continue
7509 endif
7510 let curword= s:NetrwGetWord()
7511 if curword == "./" || curword == "../"
7512 let ctr= ctr + 1
7513 continue
7514 endif
7515
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007516 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517 let oldname= s:ComposePath(a:path,curword)
7518" call Decho("oldname<".oldname.">")
7519
7520 call inputsave()
7521 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
7522 call inputrestore()
7523
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007524 call rename(oldname,newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007525" call Decho("renaming <".oldname."> to <".newname.">")
7526
7527 let ctr= ctr + 1
7528 endwhile
7529 endif
7530
7531 " refresh the directory
7532" call Decho("refresh the directory listing")
7533 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
7534 call netrw#NetrwRestorePosn(svpos)
7535
7536" call Dret("NetrwLocalRename")
7537endfun
7538
7539" ---------------------------------------------------------------------
7540" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
7541"
7542" g:netrw_ Directory Is
7543" fastbrowse Local Remote
7544" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
7545" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
7546" fast 2 H H
7547"
7548" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
7549" Hiding a buffer means that it will be re-used when examined, hence "fast".
7550" (re-using a buffer may not be as accurate)
7551fun! s:LocalFastBrowser()
7552" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
7553
7554 " initialize browselist, a list of buffer numbers that the local browser has used
7555 if !exists("s:netrw_browselist")
7556" call Decho("initialize s:netrw_browselist")
7557 let s:netrw_browselist= []
7558 endif
7559
7560 " append current buffer to fastbrowse list
7561 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
7562" call Decho("appendng current buffer to browselist")
7563 call add(s:netrw_browselist,bufnr("%"))
7564" call Decho("browselist=".string(s:netrw_browselist))
7565 endif
7566
7567 " enable autocmd events to handle refreshing/removing local browser buffers
7568 " If local browse buffer is currently showing: refresh it
7569 " If local browse buffer is currently hidden : wipe it
7570 if !exists("s:netrw_browser_shellcmd") && g:netrw_fastbrowse <= 1
7571" call Decho("setting up local-browser shell command refresh")
7572 let s:netrw_browser_shellcmd= 1
7573 augroup AuNetrwShellCmd
7574 au!
7575 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01007576" call Decho("autocmd: ShellCmdPost * call s:LocalBrowseShellCmdRefresh()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007577 au ShellCmdPost * call s:LocalBrowseShellCmdRefresh()
7578 else
7579 au ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007580" call Decho("autocmd: ShellCmdPost,FocusGained * call s:LocalBrowseShellCmdRefresh()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007581 endif
7582 augroup END
7583 endif
7584
7585 " user must have changed fastbrowse to its fast setting, so remove
7586 " the associated autocmd events
7587 if g:netrw_fastbrowse > 1 && exists("s:netrw_browser_shellcmd")
7588" call Decho("remove AuNetrwShellCmd autcmd group")
7589 unlet s:netrw_browser_shellcmd
7590 augroup AuNetrwShellCmd
7591 au!
7592 augroup END
7593 augroup! AuNetrwShellCmd
7594 endif
7595
7596" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
7597endfun
7598
7599" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00007600" Support Functions: {{{1
7601
Bram Moolenaar488c6512005-08-11 20:09:58 +00007602" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00007603" netrw#ErrorMsg: {{{2
7604" 0=note = s:NOTE
7605" 1=warning = s:WARNING
7606" 2=error = s:ERROR
Bram Moolenaar5c736222010-01-06 20:54:52 +01007607" Dec 03, 2009 : max errnum currently is 76
Bram Moolenaar9964e462007-05-05 17:54:07 +00007608fun! netrw#ErrorMsg(level,msg,errnum)
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007609" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
Bram Moolenaar9964e462007-05-05 17:54:07 +00007610
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007611 if a:level == 1
7612 let level= "**warning** (netrw) "
7613 elseif a:level == 2
7614 let level= "**error** (netrw) "
7615 else
7616 let level= "**note** (netrw) "
Bram Moolenaar9964e462007-05-05 17:54:07 +00007617 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007618" call Decho("level=".level)
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007619
7620 if g:netrw_use_errorwindow
7621 " (default) netrw creates a one-line window to show error/warning
7622 " messages (reliably displayed)
7623
Bram Moolenaar446cb832008-06-24 21:56:24 +00007624 " record current window number for NetrwRestorePosn()'s benefit
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007625 let s:winBeforeErr= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007626" call Decho("s:winBeforeErr=".s:winBeforeErr)
7627
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007628 " getting messages out reliably is just plain difficult!
7629 " This attempt splits the current window, creating a one line window.
7630 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007631" call Decho("write to NetrwMessage buffer")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007632 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007633" call Decho("setlocal ma noro")
7634 setlocal ma noro
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007635 call setline(line("$")+1,level.a:msg)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007636 keepj $
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007637 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00007638" call Decho("create a NetrwMessage buffer window")
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007639 bo 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +01007640 call s:NetrwEnew()
7641 call s:NetrwSafeOptions()
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007642 setlocal bt=nofile
7643 file NetrwMessage
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644" call Decho("setlocal ma noro")
7645 setlocal ma noro
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007646 call setline(line("$"),level.a:msg)
7647 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007648" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr())
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007649 if &fo !~ '[ta]'
7650 syn clear
7651 syn match netrwMesgNote "^\*\*note\*\*"
7652 syn match netrwMesgWarning "^\*\*warning\*\*"
7653 syn match netrwMesgError "^\*\*error\*\*"
7654 hi link netrwMesgWarning WarningMsg
7655 hi link netrwMesgError Error
7656 endif
7657 setlocal noma ro bh=wipe
7658
7659 else
7660 " (optional) netrw will show messages using echomsg. Even if the
7661 " message doesn't appear, at least it'll be recallable via :messages
Bram Moolenaar446cb832008-06-24 21:56:24 +00007662" redraw!
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007663 if a:level == s:WARNING
7664 echohl WarningMsg
7665 elseif a:level == s:ERROR
7666 echohl Error
7667 endif
7668 echomsg level.a:msg
7669" call Decho("echomsg ***netrw*** ".a:msg)
7670 echohl None
7671 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00007672
7673" call Dret("netrw#ErrorMsg")
7674endfun
7675
7676" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007677" netrw#NetrwRestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2
7678fun! netrw#NetrwRestorePosn(...)
7679" call Dfunc("netrw#NetrwRestorePosn() a:0=".a:0." winnr=".(exists("w:netrw_winnr")? w:netrw_winnr : -1)." line=".(exists("w:netrw_line")? w:netrw_line : -1)." col=".(exists("w:netrw_col")? w:netrw_col : -1)." hline=".(exists("w:netrw_hline")? w:netrw_hline : -1))
7680 let eikeep= &ei
7681 set ei=all
7682 if expand("%") == "NetrwMessage"
7683 exe s:winBeforeErr."wincmd w"
7684 endif
7685
7686 if a:0 > 0
7687 exe a:1
7688 endif
7689
7690 " restore window
7691 if exists("w:netrw_winnr")
7692" call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007693 exe "sil! ".w:netrw_winnr."wincmd w"
Bram Moolenaarc236c162008-07-13 17:41:49 +00007694 endif
7695 if v:shell_error == 0
7696 " as suggested by Bram M: redraw on no error
7697 " allows protocol error messages to remain visible
7698" redraw!
7699 endif
7700
7701 " restore top-of-screen line
7702 if exists("w:netrw_hline")
7703" call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007704 exe "keepj norm! ".w:netrw_hline."G0z\<CR>"
Bram Moolenaarc236c162008-07-13 17:41:49 +00007705 endif
7706
7707 " restore position
7708 if exists("w:netrw_line") && exists("w:netrw_col")
7709" call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007710 exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaarc236c162008-07-13 17:41:49 +00007711 endif
7712
7713 let &ei= eikeep
7714" call Dret("netrw#NetrwRestorePosn")
7715endfun
7716
7717" ---------------------------------------------------------------------
7718" netrw#NetrwSavePosn: saves position of cursor on screen {{{2
7719fun! netrw#NetrwSavePosn()
7720" call Dfunc("netrw#NetrwSavePosn()")
7721 " Save current line and column
7722 let w:netrw_winnr= winnr()
7723 let w:netrw_line = line(".")
7724 let w:netrw_col = virtcol(".")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007725" call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007726
7727 " Save top-of-screen line
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007728 keepj norm! H0
Bram Moolenaarc236c162008-07-13 17:41:49 +00007729 let w:netrw_hline= line(".")
7730
7731 " set up string holding position parameters
7732 let ret = "let w:netrw_winnr=".w:netrw_winnr."|let w:netrw_line=".w:netrw_line."|let w:netrw_col=".w:netrw_col."|let w:netrw_hline=".w:netrw_hline
7733
7734 call netrw#NetrwRestorePosn()
7735" call Dret("netrw#NetrwSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline)
7736 return ret
7737endfun
7738
7739" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00007740" netrw#RFC2396: converts %xx into characters {{{2
7741fun! netrw#RFC2396(fname)
7742" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
7743 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
7744" call Dret("netrw#RFC2396 ".fname)
7745 return fname
7746endfun
7747
7748" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007749" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
7750fun! s:ComposePath(base,subdir)
7751" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
7752
7753 if(has("amiga"))
7754" call Decho("amiga")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007755 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +00007756 if ec != '/' && ec != ':'
7757 let ret = a:base . "/" . a:subdir
7758 else
7759 let ret = a:base . a:subdir
7760 endif
7761
7762 elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
7763" call Decho("windows")
7764 let ret= a:subdir
7765
Bram Moolenaar5c736222010-01-06 20:54:52 +01007766 elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
7767" call Decho("windows")
7768 if a:base =~ '[/\\]$'
7769 let ret= a:base.a:subdir
7770 else
7771 let ret= a:base."/".a:subdir
7772 endif
7773
Bram Moolenaarc236c162008-07-13 17:41:49 +00007774 elseif a:base =~ '^\a\+://'
7775" call Decho("remote linux/macos")
7776 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
7777 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
7778 if a:subdir == '../'
7779 if curpath =~ '[^/]/[^/]\+/$'
7780 let curpath= substitute(curpath,'[^/]\+/$','','')
7781 else
7782 let curpath=""
7783 endif
7784 let ret= urlbase.curpath
7785 else
7786 let ret= urlbase.curpath.a:subdir
7787 endif
7788" call Decho("urlbase<".urlbase.">")
7789" call Decho("curpath<".curpath.">")
7790" call Decho("ret<".ret.">")
7791
7792 else
7793" call Decho("local linux/macos")
7794 let ret = substitute(a:base."/".a:subdir,"//","/","g")
7795 if a:base =~ '^//'
7796 " keeping initial '//' for the benefit of network share listing support
7797 let ret= '/'.ret
7798 endif
7799 let ret= simplify(ret)
7800 endif
7801
7802" call Dret("s:ComposePath ".ret)
7803 return ret
7804endfun
7805
7806" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00007807" s:FileReadable: o/s independent filereadable {{{2
7808fun! s:FileReadable(fname)
7809" call Dfunc("s:FileReadable(fname<".a:fname.">)")
7810
7811 if g:netrw_cygwin
7812 let ret= filereadable(substitute(a:fname,'/cygdrive/\(.\)','\1:/',''))
7813 else
7814 let ret= filereadable(a:fname)
7815 endif
7816
7817" call Dret("s:FileReadable ".ret)
7818 return ret
7819endfun
7820
7821" ---------------------------------------------------------------------
7822" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
7823" Places correct suffix on end of temporary filename,
7824" using the suffix provided with fname
7825fun! s:GetTempfile(fname)
7826" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
7827
7828 if !exists("b:netrw_tmpfile")
7829 " get a brand new temporary filename
7830 let tmpfile= tempname()
7831" call Decho("tmpfile<".tmpfile."> : from tempname()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007832
Bram Moolenaarc236c162008-07-13 17:41:49 +00007833 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar9964e462007-05-05 17:54:07 +00007834" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007835
Bram Moolenaar9964e462007-05-05 17:54:07 +00007836 " sanity check -- does the temporary file's directory exist?
7837 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007838" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar9964e462007-05-05 17:54:07 +00007839 call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
7840" call Dret("s:GetTempfile getcwd<".getcwd().">")
7841 return ""
7842 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843
Bram Moolenaar9964e462007-05-05 17:54:07 +00007844 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar5c736222010-01-06 20:54:52 +01007845 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX()
Bram Moolenaar9964e462007-05-05 17:54:07 +00007846" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007847
Bram Moolenaar9964e462007-05-05 17:54:07 +00007848 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 if g:netrw_cygwin != 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00007850 let tmpfile = substitute(tmpfile,'^\(\a\):','/cygdrive/\1','e')
7851 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 if !exists("+shellslash") || !&ssl
7853 let tmpfile = substitute(tmpfile,'/','\','g')
7854 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00007855 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +00007857 endif
7858 let b:netrw_tmpfile= tmpfile
7859" call Decho("o/s dependent fixed tempname<".tmpfile.">")
7860 else
7861 " re-use temporary filename
7862 let tmpfile= b:netrw_tmpfile
7863" call Decho("tmpfile<".tmpfile."> re-using")
7864 endif
7865
7866 " use fname's suffix for the temporary file
7867 if a:fname != ""
7868 if a:fname =~ '\.[^./]\+$'
7869" call Decho("using fname<".a:fname.">'s suffix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007870 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00007871 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007872 elseif a:fname =~ '.txz$'
7873 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +00007874 else
7875 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
7876 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00007877" call Decho("suffix<".suffix.">")
7878 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
7879" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)")
7880 let tmpfile .= suffix
7881" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
7882 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
7883 endif
7884 endif
7885
Bram Moolenaarc236c162008-07-13 17:41:49 +00007886" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap)
Bram Moolenaar9964e462007-05-05 17:54:07 +00007887" call Dret("s:GetTempfile <".tmpfile.">")
7888 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +00007890
7891" ---------------------------------------------------------------------
7892" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +00007893" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +00007894fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00007896 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user.s:machine,'')
7897 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007898 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00007899 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00007900 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00007901 else
7902 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
7903 endif
7904" call Dret("s:MakeSshCmd <".sshcmd.">")
7905 return sshcmd
7906endfun
7907
7908" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007909" s:NetrwBMShow: {{{2
7910fun! s:NetrwBMShow()
7911" call Dfunc("s:NetrwBMShow()")
7912 redir => bmshowraw
7913 menu
7914 redir END
7915 let bmshowlist = split(bmshowraw,'\n')
7916 if bmshowlist != []
7917 let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"')
7918 if bmshowfuncs != []
7919 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
7920 if bmshowfunc =~ '^call.*BMShow()'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007921 exe "sil! ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +00007922 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00007925" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
7926endfun
7927
7928" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007929" s:NetrwCursorline: {{{2
7930fun! s:NetrwCursorline()
7931 if !exists("w:netrw_liststyle")
7932 let w:netrw_liststyle= g:netrw_liststyle
7933 endif
7934" call Dfunc("s:NetrwCursorline() liststyle=".w:netrw_liststyle." g:netrw_cursorline=".g:netrw_cursorline." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
7935 "
7936 if w:netrw_liststyle != s:WIDELIST
7937 " thin-long-tree listings
7938 if g:netrw_cursorline == 2
7939 setlocal cursorline
7940 let &l:cursorcolumn= s:netrw_usercuc
7941" call Decho("setlocal cursorline (cursorcolumn is ".((s:netrw_usercuc)? "on" : "off").")")
7942 elseif g:netrw_cursorline
7943 setlocal cursorline
7944" call Decho("setlocal cursorline")
7945 endif
7946
7947 else
7948 " wide listings
7949 if g:netrw_cursorline == 2
7950 setlocal cursorline cursorcolumn
7951" call Decho("setlocal cursorline cursorcolumn")
7952 elseif g:netrw_cursorline
7953 let &l:cursorline= s:netrw_usercul
7954" call Decho("cursorline is ".((s:netrw_usercul)? "on" : "off").")")
7955 endif
7956 endif
7957" call Dret("s:NetrwCursorline : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
7958endfun
7959
7960" ---------------------------------------------------------------------
7961" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
7962fun! s:RestoreCursorline()
7963" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
7964 let &l:cursorline = s:netrw_usercul
7965 let &l:cursorcolumn = s:netrw_usercuc
7966" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
7967endfun
7968
7969" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007970" s:NetrwDelete: Deletes a file. {{{2
7971" Uses Steve Hall's idea to insure that Windows paths stay
7972" acceptable. No effect on Unix paths.
7973" Examples of use: let result= s:NetrwDelete(path)
7974fun! s:NetrwDelete(path)
7975" call Dfunc("s:NetrwDelete(path<".a:path.">)")
7976
Bram Moolenaar5c736222010-01-06 20:54:52 +01007977 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007978 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7979 if exists("+shellslash")
7980 let sskeep= &shellslash
7981 setlocal noshellslash
7982 let result = delete(path)
7983 let &shellslash = sskeep
7984 else
7985" call Decho("exe let result= ".a:cmd."('".path."')")
7986 let result= delete(path)
7987 endif
7988 else
7989" call Decho("let result= delete(".path.")")
7990 let result= delete(path)
7991 endif
7992 if result < 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01007993 call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007994 endif
7995
7996" call Dret("s:NetrwDelete ".result)
7997 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998endfun
7999
8000" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008001" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002fun! s:NetrwEnew(...)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008003" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01008004" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008005
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 " grab a function-local-variable copy of buffer variables
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008007" call Decho("make function-local copy of netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008008 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
8009 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
8010 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
8011 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
8012 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
8013 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
8014 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
8015 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
8016 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
8017 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
8018 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
8019 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
8020 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
8021 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
8022 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
8023 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
8024
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025 call s:NetrwOptionRestore("w:")
8026" call Decho("generate a buffer with keepjumps keepalt enew!")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008027 let netrw_keepdiff= &l:diff
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008028 keepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008029 let &l:diff= netrw_keepdiff
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008030" call Decho("bufnr($)=".bufnr("$"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031 call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008032
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 " copy function-local-variables to buffer variable equivalents
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008034" call Decho("copy function-local variables back to buffer netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008035 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
8036 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
8037 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
8038 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
8039 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
8040 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
8041 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
8042 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
8043 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
8044 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
8045 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
8046 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
8047 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
8048 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
8049 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
8050 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
8051
Bram Moolenaar5c736222010-01-06 20:54:52 +01008052 if a:0 > 0
8053 let b:netrw_curdir= a:1
8054 if b:netrw_curdir =~ '/$'
8055 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8056 file NetrwTreeListing
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008057 set bt=nowrite noswf
Bram Moolenaar5c736222010-01-06 20:54:52 +01008058 nno <silent> <buffer> [ :silent call <SID>TreeListMove('[')<cr>
8059 nno <silent> <buffer> ] :silent call <SID>TreeListMove(']')<cr>
8060 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008061 exe "sil! keepalt file ".fnameescape(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008062 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008063 endif
8064 endif
8065
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00008067endfun
8068
8069" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
8071" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
8072fun! s:NetrwSaveWordPosn()
8073" call Dfunc("NetrwSaveWordPosn()")
8074 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
8075" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
8076endfun
8077
8078" ---------------------------------------------------------------------
8079" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
8080" changed sorting, etc. Also see s:NetrwSaveWordPosn().
8081fun! s:NetrwRestoreWordPosn()
8082" call Dfunc("NetrwRestoreWordPosn()")
8083 silent! call search(s:netrw_saveword,'w')
8084" call Dret("NetrwRestoreWordPosn")
8085endfun
8086
8087" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008088" s:RestoreBufVars: {{{2
8089fun! s:RestoreBufVars()
8090" call Dfunc("s:RestoreBufVars()")
8091
8092 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
8093 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
8094 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
8095 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
8096 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
8097 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
8098
8099" call Dret("s:RestoreBufVars")
8100endfun
8101
8102" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008103" s:RemotePathAnalysis: {{{2
8104fun! s:RemotePathAnalysis(dirname)
8105" call Dfunc("s:RemotePathAnalysis()")
8106
8107 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
8108 let s:method = substitute(a:dirname,dirpat,'\1','')
8109 let s:user = substitute(a:dirname,dirpat,'\2','')
8110 let s:machine = substitute(a:dirname,dirpat,'\3','')
8111 let s:port = substitute(a:dirname,dirpat,'\4','')
8112 let s:path = substitute(a:dirname,dirpat,'\5','')
8113 let s:fname = substitute(a:dirname,'^.*/\ze.','','')
8114
8115" call Decho("set up s:method <".s:method .">")
8116" call Decho("set up s:user <".s:user .">")
8117" call Decho("set up s:machine<".s:machine.">")
8118" call Decho("set up s:port <".s:port.">")
8119" call Decho("set up s:path <".s:path .">")
8120" call Decho("set up s:fname <".s:fname .">")
8121
8122" call Dret("s:RemotePathAnalysis")
8123endfun
8124
8125" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008126" s:RemoteSystem: runs a command on a remote host using ssh {{{2
8127" Returns status
8128" Runs system() on
8129" [cd REMOTEDIRPATH;] a:cmd
8130" Note that it doesn't do shellescape(a:cmd)!
8131fun! s:RemoteSystem(cmd)
8132" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
8133 if !executable(g:netrw_ssh_cmd)
8134 call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
8135 elseif !exists("b:netrw_curdir")
8136 call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
8137 else
8138 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
8139 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
8140 if remotedir != ""
8141 let cmd= cmd.' cd '.shellescape(remotedir).";"
8142 else
8143 let cmd= cmd.' '
8144 endif
8145 let cmd= cmd.a:cmd
8146" call Decho("call system(".cmd.")")
8147 let ret= system(cmd)
8148 endif
8149" call Dret("s:RemoteSystem ".ret)
8150 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +00008151endfun
8152
8153" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008155fun! s:RestoreWinVars()
8156" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +00008157 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008158 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
8159 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
8160 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
8161 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
8162 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
8163 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
8164 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
8165 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
8166 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
8167 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
8168 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
8169 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +00008170 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
8171 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008172 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
8173 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
8174 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
8175" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +00008176endfun
8177
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008178" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008179" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
8180"
8181" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
8182" is true) and a command, :Rexplore, which call this function.
8183"
8184" s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir()
8185fun! s:NetrwRexplore(islocal,dirname)
8186" call Dfunc("s:NetrwRexplore(islocal=".a:islocal." dirname<".a:dirname.">)")
8187 if a:islocal
8188 call netrw#LocalBrowseCheck(a:dirname)
8189 else
8190 call s:NetrwBrowse(0,a:dirname)
8191 endif
8192 if exists("s:nbcd_curpos_{bufnr('%')}")
8193 call netrw#NetrwRestorePosn(s:nbcd_curpos_{bufnr('%')})
8194 unlet s:nbcd_curpos_{bufnr('%')}
8195 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008196 if exists("s:explore_match")
8197 exe "2match netrwMarkFile /".s:explore_match."/"
8198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199" call Dret("s:NetrwRexplore")
8200endfun
8201
8202" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00008203" s:SaveBufVars: {{{2
8204fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01008205" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00008206
8207 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
8208 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
8209 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
8210 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
8211 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
8212 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
8213
8214" call Dret("s:SaveBufVars")
8215endfun
8216
8217" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008218" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008219fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01008220" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00008221 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
8222 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
8223 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
8224 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
8225 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
8226 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
8227 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
8228 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
8229 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
8230 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
8231 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
8232 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
8233 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
8234 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
8235 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
8236 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
8237 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
8238 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
8239" call Dret("s:SaveWinVars")
8240endfun
8241
8242" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008243" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008244" To allow separate windows to have their own activities, such as
8245" Explore **/pattern, several variables have been made window-oriented.
8246" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +00008247" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008248" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +00008249fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +01008250" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00008251 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
8252 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
8253 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
8254 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
8255 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
8256 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
8257 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
8258 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
8259 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
8260 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
8261" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008262endfun
8263
8264" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008265" s:SetRexDir: set directory for :Rexplore {{{2
8266fun! s:SetRexDir(islocal,dirname)
8267" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)")
8268 " set up Rex and leftmouse-double-click
8269 if a:islocal
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008270 exe 'com! Rexplore call s:NetrwRexplore(1,"'.escape(a:dirname,'"\').'")'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008271 if g:netrw_retmap
Bram Moolenaar5c736222010-01-06 20:54:52 +01008272 if !hasmapto("<Plug>NetrwReturn") && maparg("<2-leftmouse>","n") == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00008273 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
8274 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008275 let dir = escape(a:dirname, s:netrw_map_escape)
8276 exe 'nnoremap <silent> <Plug>NetrwReturn :call <SID>NetrwRexplore(1,"'.dir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008277 endif
8278 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008279 exe 'com! Rexplore call s:NetrwRexplore(0,"'.escape(a:dirname,'"\').'")'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008280 if g:netrw_retmap
Bram Moolenaar5c736222010-01-06 20:54:52 +01008281 if !hasmapto("<Plug>NetrwReturn") && maparg("<2-leftmouse>","n") == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00008282 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
8283 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008284 let dir = escape(a:dirname, s:netrw_map_escape)
8285 exe 'nnoremap <silent> <Plug>NetrwReturn :call <SID>NetrwRexplore(0,"'.dir.'")<cr>'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286 endif
8287 endif
8288" call Dret("s:SetRexDir")
8289endfun
8290
8291" ---------------------------------------------------------------------
8292" s:Strlen: this function returns the length of a string, even if its {{{2
8293" using two-byte etc characters.
Bram Moolenaar5c736222010-01-06 20:54:52 +01008294" Solution from Nicolai Weibull, vim docs (:help strlen()), Tony Mechelynck,
8295" and a bit from me.
8296" if g:netrw_xstrlen is zero (default), then the builtin strlen() function is used.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008297fun! s:Strlen(x)
8298" call Dfunc("s:Strlen(x<".a:x.">")
8299 if g:netrw_xstrlen == 1
8300 " number of codepoints (Latin a + combining circumflex is two codepoints)
8301 " (comment from TM, solution from NW)
8302 let ret= strlen(substitute(a:x,'.','c','g'))
8303
8304 elseif g:netrw_xstrlen == 2
8305 " number of spacing codepoints (Latin a + combining circumflex is one spacing
8306 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
8307 " (comment from TM, solution from TM)
8308 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
8309
8310 elseif g:netrw_xstrlen == 3
8311 " virtual length (counting, for instance, tabs as anything between 1 and
8312 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
8313 " preceded by lam, one otherwise, etc.)
8314 " (comment from TM, solution from me)
8315 let modkeep= &mod
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008316 exe "keepj norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008317 call setline(line("."),a:x)
8318 let ret= virtcol("$") - 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008319 keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008320 let &mod= modkeep
8321
8322 else
8323 " at least give a decent default
Bram Moolenaar5c736222010-01-06 20:54:52 +01008324 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008325 endif
8326" call Dret("s:Strlen ".ret)
8327 return ret
8328endfun
8329
8330" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008331" s:TreeListMove: {{{2
8332fun! s:TreeListMove(dir)
8333" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
8334 let curline = getline('.')
8335 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
8336 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
8337 let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','')
8338 let indentm1 = substitute(curindent,'^| ','','')
8339" call Decho("prvline <".prvline."> #".line(".")-1)
8340" call Decho("curline <".curline."> #".line("."))
8341" call Decho("nxtline <".nxtline."> #".line(".")+1)
8342" call Decho("curindent<".curindent.">")
8343" call Decho("indentm1 <".indentm1.">")
8344
8345 if curline !~ '/$'
8346" call Decho('regfile')
8347 if a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008348 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008349 let nl = search('^'.indentm1.'[^|]','bWe') " search backwards from regular file
8350" call Decho("regfile srch back: ".nl)
8351 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008352 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +00008353 let nl = search('^'.indentm1.'[^|]','We') " search forwards from regular file
8354" call Decho("regfile srch fwd: ".nl)
8355 endif
8356
8357 elseif a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008358 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008359 let curline= line(".")
8360 let nl = search('^'.curindent.'[^|]','bWe') " search backwards From directory, same indentation
8361" call Decho("dir srch back ind: ".nl)
8362 if nl != 0
8363 if line(".") == curline-1
8364 let nl= search('^'.indentm1.'[^|]','bWe') " search backwards from directory, indentation - 1
8365" call Decho("dir srch back ind-1: ".nl)
8366 endif
8367 endif
8368
8369 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008370 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +00008371 let curline = line(".")
8372 let nl = search('^'.curindent.'[^|]','We') " search forwards from directory, same indentation
8373" call Decho("dir srch fwd ind: ".nl)
8374 if nl != 0
8375 if line(".") == curline+1
8376 let nl= search('^'.indentm1.'[^|]','We') " search forwards from directory, indentation - 1
8377" call Decho("dir srch fwd ind-1: ".nl)
8378 endif
8379 endif
8380
8381 endif
8382
8383" call Dret("s:TreeListMove")
8384endfun
8385
8386" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008387" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
8388" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
8389" can't be called except via emenu. But due to locale, that menu line may not be called
8390" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
8391fun! s:UpdateBuffersMenu()
8392" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008393 if has("gui") && has("menu") && has("gui_running") && &go =~ 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +00008394 try
8395 silent emenu Buffers.Refresh\ menu
8396 catch /^Vim\%((\a\+)\)\=:E/
8397 let v:errmsg= ""
8398 silent call s:NetrwBMShow()
8399 endtry
8400 endif
8401" call Dret("s:UpdateBuffersMenu")
8402endfun
8403
8404" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008405" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008406" Matching function to BufferWinVars()
8407fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +00008408" call Dfunc("s:UseBufWinVars()")
8409 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008410 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
8411 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
8412 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
8413 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
8414 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
8415 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
8416 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
8417 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
8418 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00008419" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008420endfun
8421
Bram Moolenaar1afcace2005-11-25 19:54:28 +00008422" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01008423" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
8424fun! netrw#WinPath(path)
8425" call Dfunc("netrw#WinPath(path<".a:path.">)")
8426 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
8427 " remove cygdrive prefix, if present
8428 let path = substitute(a:path,'/cygdrive/\(.\)','\1:','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00008429 " remove trailing slash (Win95)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008430 let path = substitute(path, '\(\\\|/\)$', '', 'g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00008431 " remove escaped spaces
8432 let path = substitute(path, '\ ', ' ', 'g')
8433 " convert slashes to backslashes
8434 let path = substitute(path, '/', '\', 'g')
8435 else
8436 let path= a:path
8437 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008438" call Dret("netrw#WinPath <".path.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008439 return path
8440endfun
8441
8442" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00008443" Settings Restoration: {{{2
Bram Moolenaar83bab712005-08-01 21:58:57 +00008444let &cpo= s:keepcpo
8445unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00008446
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +00008448" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449" vim:ts=8 fdm=marker