blob: d8d1857099a1b2fab9009d57c436591db8fb2ea4 [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 Moolenaar13600302014-05-22 18:26:40 +02003" Date: May 13, 2014
4" Version: 152
Bram Moolenaarff034192013-04-24 18:51:19 +02005" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaar8d043172014-01-23 14:24:41 +01007" Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{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 Moolenaar13600302014-05-22 18:26:40 +020025if v:version < 704 || !has("patch213")
26 if !exists("s:needpatch213")
27 echo "***sorry*** this version of netrw requires vim v7.4 with patch 213"
28 endif
29 let s:needpatch213= 1
30 finish
31endif
32let g:loaded_netrw = "v152"
Bram Moolenaar9964e462007-05-05 17:54:07 +000033if !exists("s:NOTE")
34 let s:NOTE = 0
35 let s:WARNING = 1
36 let s:ERROR = 2
37endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000038
Bram Moolenaar1afcace2005-11-25 19:54:28 +000039let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010040setl cpo&vim
41"let g:dechofuncname=1
Bram Moolenaar8d043172014-01-23 14:24:41 +010042"DechoRemOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000043"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw)
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000045" ======================
46" Netrw Variables: {{{1
47" ======================
48
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020050" netrw#ErrorMsg: {{{2
51" 0=note = s:NOTE
52" 1=warning = s:WARNING
53" 2=error = s:ERROR
Bram Moolenaar13600302014-05-22 18:26:40 +020054" Apr 16, 2014 : max errnum currently is 97
Bram Moolenaar5b435d62012-04-05 17:33:26 +020055fun! netrw#ErrorMsg(level,msg,errnum)
56" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
57
58 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020059" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020060 return
61 endif
62
63 if a:level == 1
64 let level= "**warning** (netrw) "
65 elseif a:level == 2
66 let level= "**error** (netrw) "
67 else
68 let level= "**note** (netrw) "
69 endif
70" call Decho("level=".level)
71
72 if g:netrw_use_errorwindow
73 " (default) netrw creates a one-line window to show error/warning
74 " messages (reliably displayed)
75
76 " record current window number for NetrwRestorePosn()'s benefit
77 let s:winBeforeErr= winnr()
78" call Decho("s:winBeforeErr=".s:winBeforeErr)
79
80 " getting messages out reliably is just plain difficult!
81 " This attempt splits the current window, creating a one line window.
82 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
83" call Decho("write to NetrwMessage buffer")
84 exe bufwinnr("NetrwMessage")."wincmd w"
85" call Decho("setl ma noro")
86 setl ma noro
87 keepj call setline(line("$")+1,level.a:msg)
88 keepj $
89 else
90" call Decho("create a NetrwMessage buffer window")
91 bo 1split
92 sil! call s:NetrwEnew()
93 sil! keepj call s:NetrwSafeOptions()
94 setl bt=nofile
95 keepj file NetrwMessage
Bram Moolenaarff034192013-04-24 18:51:19 +020096" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097 setl ma noro
98 call setline(line("$"),level.a:msg)
99 endif
100" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr())
101 if &fo !~ '[ta]'
102 syn clear
103 syn match netrwMesgNote "^\*\*note\*\*"
104 syn match netrwMesgWarning "^\*\*warning\*\*"
105 syn match netrwMesgError "^\*\*error\*\*"
106 hi link netrwMesgWarning WarningMsg
107 hi link netrwMesgError Error
108 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100109" call Decho("setl noma ro bh=wipe")
Bram Moolenaar13600302014-05-22 18:26:40 +0200110 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111
112 else
113 " (optional) netrw will show messages using echomsg. Even if the
114 " message doesn't appear, at least it'll be recallable via :messages
115" redraw!
116 if a:level == s:WARNING
117 echohl WarningMsg
118 elseif a:level == s:ERROR
119 echohl Error
120 endif
121 echomsg level.a:msg
122" call Decho("echomsg ***netrw*** ".a:msg)
123 echohl None
124 endif
125
126" call Dret("netrw#ErrorMsg")
127endfun
128
129" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +0100130" NetrwInit: initializes variables if they haven't been defined {{{2
131" Loosely, varname = value.
132fun s:NetrwInit(varname,value)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200133" call Decho("varname<".a:varname."> value=".a:value)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100134 if !exists(a:varname)
135 if type(a:value) == 0
136 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200137 elseif type(a:value) == 1 && a:value =~ '^[{[]'
138 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100139 elseif type(a:value) == 1
140 exe "let ".a:varname."="."'".a:value."'"
141 else
142 exe "let ".a:varname."=".a:value
143 endif
144 endif
145endfun
146
147" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000148" Netrw Constants: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100149call s:NetrwInit("g:netrw_dirhist_cnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000150if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100151 call s:NetrwInit("s:THINLIST",0)
152 call s:NetrwInit("s:LONGLIST",1)
153 call s:NetrwInit("s:WIDELIST",2)
154 call s:NetrwInit("s:TREELIST",3)
155 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000156endif
157
158" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000159" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200160call s:NetrwInit("g:netrw_use_errorwindow",1)
161
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000162if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100163 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000164 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100165 elseif executable("curl")
166 let g:netrw_dav_cmd = "curl"
167 else
168 let g:netrw_dav_cmd = ""
169 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000171if !exists("g:netrw_fetch_cmd")
172 if executable("fetch")
173 let g:netrw_fetch_cmd = "fetch -o"
174 else
175 let g:netrw_fetch_cmd = ""
176 endif
177endif
178if !exists("g:netrw_ftp_cmd")
179 let g:netrw_ftp_cmd = "ftp"
180endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200181let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200182if !exists("g:netrw_ftp_options")
183 let g:netrw_ftp_options= "-i -n"
184endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000185if !exists("g:netrw_http_cmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000186 if executable("elinks")
187 let g:netrw_http_cmd = "elinks"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100188 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000189 elseif executable("links")
190 let g:netrw_http_cmd = "links"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100191 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000192 elseif executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100193 let g:netrw_http_cmd = "curl"
194 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000195 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100196 let g:netrw_http_cmd = "wget"
197 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000198 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100199 let g:netrw_http_cmd = "fetch"
200 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000201 else
202 let g:netrw_http_cmd = ""
203 endif
204endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100205call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
207call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200208if !exists("g:netrw_scp_cmd")
209 if executable("scp")
210 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
211 elseif executable("pscp")
212 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
213 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
214 else
215 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
216 endif
217 else
218 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
219 endif
220endif
221
Bram Moolenaar5c736222010-01-06 20:54:52 +0100222call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
223call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000224
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000225if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000226 \ && exists("g:netrw_use_nt_rcp")
227 \ && g:netrw_use_nt_rcp
228 \ && executable( $SystemRoot .'/system32/rcp.exe')
229 let s:netrw_has_nt_rcp = 1
230 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000231else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000232 let s:netrw_has_nt_rcp = 0
233 let s:netrw_rcpmode = ''
234endif
235
236" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000237" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000238" Cygwin Detection ------- {{{3
239if !exists("g:netrw_cygwin")
240 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100241 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000242 let g:netrw_cygwin= 1
243 else
244 let g:netrw_cygwin= 0
245 endif
246 else
247 let g:netrw_cygwin= 0
248 endif
249endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000250" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100251call s:NetrwInit("g:netrw_alto" , &sb)
252call s:NetrwInit("g:netrw_altv" , &spr)
253call s:NetrwInit("g:netrw_banner" , 1)
254call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200255call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100256call s:NetrwInit("g:netrw_chgwin" , -1)
257call s:NetrwInit("g:netrw_compress" , "gzip")
258call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200259if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
260 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
261 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000262endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200263call s:NetrwInit("g:netrw_cursor" , 2)
264let s:netrw_usercul = &cursorline
265let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar8d043172014-01-23 14:24:41 +0100266call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000267" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200268call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100269call s:NetrwInit("g:netrw_dirhist_cnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200270call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200272call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273call s:NetrwInit("g:netrw_fastbrowse" , 1)
274call 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 +0000275if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000276 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
277 let g:netrw_ftp_list_cmd = "ls -lF"
278 let g:netrw_ftp_timelist_cmd = "ls -tlF"
279 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000280 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000281 let g:netrw_ftp_list_cmd = "dir"
282 let g:netrw_ftp_timelist_cmd = "dir"
283 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000284 endif
285endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000287" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100288call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000289if !exists("g:netrw_ignorenetrc")
290 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
291 let g:netrw_ignorenetrc= 1
292 else
293 let g:netrw_ignorenetrc= 0
294 endif
295endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100296call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000297if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000298 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000299 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200300 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000301 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
302 endif
303 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
304 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200305 " provide a scp-based default listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000306 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000307 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100308" call Decho("g:netrw_ssh_cmd." is not executable")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000309 let g:netrw_list_cmd= ""
310 endif
311endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100312call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000313" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200314if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200315 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200316 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
317endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100318if !exists("g:netrw_localcmdshell")
319 let g:netrw_localcmdshell= ""
320endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000321if !exists("g:netrw_localcopycmd")
322 if has("win32") || has("win95") || has("win64") || has("win16")
323 if g:netrw_cygwin
324 let g:netrw_localcopycmd= "cp"
325 else
Bram Moolenaar13600302014-05-22 18:26:40 +0200326 let g:netrw_localcopycmd= expand("$COMSPEC")." /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000327 endif
328 elseif has("unix") || has("macunix")
329 let g:netrw_localcopycmd= "cp"
330 else
331 let g:netrw_localcopycmd= ""
332 endif
333endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200334if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100335 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200336 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
337endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200338if has("win32") || has("win95") || has("win64") || has("win16")
339 if g:netrw_cygwin
340 call s:NetrwInit("g:netrw_localmkdir","mkdir")
341 else
342 let g:netrw_localmkdir= expand("$COMSPEC")." /c mkdir"
343 endif
344else
345 call s:NetrwInit("g:netrw_localmkdir","mkdir")
346endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200347call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200348if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200349 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200350 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
351endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000352if !exists("g:netrw_localmovecmd")
353 if has("win32") || has("win95") || has("win64") || has("win16")
354 if g:netrw_cygwin
355 let g:netrw_localmovecmd= "mv"
356 else
Bram Moolenaar13600302014-05-22 18:26:40 +0200357 let g:netrw_localmovecmd= expand("$COMSPEC")." /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000358 endif
359 elseif has("unix") || has("macunix")
360 let g:netrw_localmovecmd= "mv"
361 else
362 let g:netrw_localmovecmd= ""
363 endif
364endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200365if exists("g:netrw_local_rmdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200366 let g:netrw_localrmdir= g:netrw_local_rmdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200367 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
368endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200369if has("win32") || has("win95") || has("win64") || has("win16")
370 if g:netrw_cygwin
371 call s:NetrwInit("g:netrw_localrmdir","rmdir")
372 else
373 let g:netrw_localrmdir= expand("$COMSPEC")." /c rmdir"
374 endif
375else
376 call s:NetrwInit("g:netrw_localrmdir","rmdir")
377endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100378call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
379" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000380if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000381 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000382endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000383if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000384 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
385endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000386" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100387call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
388call s:NetrwInit("g:netrw_maxfilenamelen", 32)
389call s:NetrwInit("g:netrw_menu" , 1)
390call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200391call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~ '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100392call s:NetrwInit("g:netrw_retmap" , 0)
393if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
394 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
395elseif has("win32") || has("win95") || has("win64") || has("win16")
396 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
397else
398 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100400call s:NetrwInit("g:netrw_preview" , 0)
401call s:NetrwInit("g:netrw_scpport" , "-P")
402call s:NetrwInit("g:netrw_sshport" , "-p")
403call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
404call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
405call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100406call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
407" Default values - q-s ---------- {{{3
408call s:NetrwInit("g:netrw_quickhelp",0)
409let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
410 \ "%:create new file d:create new directory",
411 \ "o:split&open v:vert-split&open",
412 \ "i:style qf:file info O:obtain r:reverse p:preview",
413 \ "mf:mark file mt:set target mm:move mc:copy",
414 \ "-bookmarks- mb:make mB:delete qb:list gb:go to",
415 \ "-history- qb:list u:go up U:go down",
416 \ "-targets- mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100417" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
418call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200419call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100420call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
421call s:NetrwInit("g:netrw_sort_options" , "")
422call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000423if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100424 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200425 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100426 else
427 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000428 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000429endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100430call s:NetrwInit("g:netrw_special_syntax" , 0)
431call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100432call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000433" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100434call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200435if !exists("g:netrw_xstrlen")
436 if exists("g:Align_xstrlen")
437 let g:netrw_xstrlen= g:Align_xstrlen
438 elseif exists("g:drawit_xstrlen")
439 let g:netrw_xstrlen= g:drawit_xstrlen
440 elseif &enc == "latin1" || !has("multi_byte")
441 let g:netrw_xstrlen= 0
442 else
443 let g:netrw_xstrlen= 1
444 endif
445endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100446call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100447call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200448call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000450" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000451" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100452call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200453if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200454 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200455else
Bram Moolenaarff034192013-04-24 18:51:19 +0200456 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200457endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200458call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100459call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
460call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100461if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100462 let s:treedepthstring= "│ "
463else
464 let s:treedepthstring= "| "
465endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000466
467" BufEnter event ignored by decho when following variable is true
468" Has a side effect that doau BufReadPost doesn't work, so
469" files read by network transfer aren't appropriately highlighted.
470"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471
Bram Moolenaaradc21822011-04-01 18:03:16 +0200472" ======================
473" Netrw Initialization: {{{1
474" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200475if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100476" call Decho("installed beval events")
Bram Moolenaara6878372014-03-22 21:02:50 +0100477 let &l:bexpr = "netrw#BalloonHelp()"
478 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100479 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
480 au VimEnter * let s:initbeval= &beval
481"else " Decho
482" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700") | endif
483" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval") | endif
484" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists") | endif
485" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists") | endif
486" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting") | endif
487" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists") | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200488endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200489au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200490
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000491" ==============================
492" Netrw Utility Functions: {{{1
493" ==============================
494
Bram Moolenaaradc21822011-04-01 18:03:16 +0200495" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100496" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100497if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
498" call Decho("loading netrw#BalloonHelp()")
Bram Moolenaara6878372014-03-22 21:02:50 +0100499 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100500 if &ft != "netrw"
501 return ""
502 endif
503 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
504 let mesg= ""
505 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
506 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
507 elseif getline(v:beval_lnum) =~ '^"\s*/'
508 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
509 elseif v:beval_text == "Sorted" || v:beval_text == "by"
510 let mesg = 's: sort by name, time, or file size r: reverse sorting order mt: mark target'
511 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
512 let mesg = "S: edit sorting sequence"
513 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
514 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
515 elseif v:beval_text == "Quick" || v:beval_text == "Help"
516 let mesg = "Help: press <F1>"
517 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
518 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
519 else
520 let mesg= ""
521 endif
522 return mesg
523 endfun
524"else " Decho
525" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -")|endif
526" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval") |endif
527" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled") |endif
528" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on=".g:syntax_on) |endif
529" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists") |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200530endif
531
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200533" netrw#Explore: launch the local browser in the directory of the current file {{{2
534" indx: == -1: Nexplore
535" == -2: Pexplore
536" == +: this is overloaded:
537" * If Nexplore/Pexplore is in use, then this refers to the
538" indx'th item in the w:netrw_explore_list[] of items which
539" matched the */pattern **/pattern *//pattern **//pattern
540" * If Hexplore or Vexplore, then this will override
541" g:netrw_winsize to specify the qty of rows or columns the
542" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100543" dosplit==0: the window will be split iff the current file has been modified and hidden not set
Bram Moolenaarff034192013-04-24 18:51:19 +0200544" dosplit==1: the window will be split before running the local browser
545" style == 0: Explore style == 1: Explore!
546" == 2: Hexplore style == 3: Hexplore!
547" == 4: Vexplore style == 5: Vexplore!
548" == 6: Texplore
549fun! netrw#Explore(indx,dosplit,style,...)
550" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%"))
551 if !exists("b:netrw_curdir")
552 let b:netrw_curdir= getcwd()
Bram Moolenaara6878372014-03-22 21:02:50 +0100553" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200554 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100555
556 " record current file for Rexplore's benefit
557 if &ft != "netrw"
558 let w:netrw_rexfile= expand("%:p")
559 endif
560
561 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200562 let curdir = simplify(b:netrw_curdir)
563 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200564 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
565 let curdir= substitute(curdir,'\','/','g')
566 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100567" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">")
568
569 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
570 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
571 " try Explore again.
572 if a:0 > 0
573" call Decho('considering retry: a:1<'.a:1.'>: '.
574 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
575 \ ((filereadable(a:1))? 'is readable' : 'is not readable').', '.
576 \ ((isdirectory(a:1))? 'is a directory' : 'is not a directory'))
577 if a:1 =~ "\\\s" && !filereadable(a:1) && !isdirectory(a:1)
578" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">")
579 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
580" call Dret("netrw#Explore : returning from retry")
581 return
582" else " Decho
583" call Decho("retry not needed")
584 endif
585 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200586
587 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100588 if has("clipboard")
589 sil! let keepregstar = @*
590 sil! let keepregplus = @+
591 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200592 sil! let keepregslash= @/
593
Bram Moolenaar8d043172014-01-23 14:24:41 +0100594 " if dosplit
595 " -or- file has been modified AND file not hidden when abandoned
596 " -or- Texplore used
597 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara6878372014-03-22 21:02:50 +0100598" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified")
Bram Moolenaarff034192013-04-24 18:51:19 +0200599 call s:SaveWinVars()
600 let winsz= g:netrw_winsize
601 if a:indx > 0
602 let winsz= a:indx
603 endif
604
605 if a:style == 0 " Explore, Sexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100606" call Decho("style=0: Explore or Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200607 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200608 if winsz == 0|let winsz= ""|endif
609 exe "noswapfile ".winsz."wincmd s"
610" call Decho("exe noswapfile ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200611
612 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100613" call Decho("style=1: Explore! or Sexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200614 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200615 if winsz == 0|let winsz= ""|endif
616 exe "keepalt noswapfile ".winsz."wincmd v"
617" call Decho("exe keepalt noswapfile ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200618
619 elseif a:style == 2 " Hexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100620" call Decho("style=2: Hexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200621 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200622 if winsz == 0|let winsz= ""|endif
623 exe "keepalt noswapfile bel ".winsz."wincmd s"
624" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200625
626 elseif a:style == 3 " Hexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100627" call Decho("style=3: Hexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200628 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200629 if winsz == 0|let winsz= ""|endif
630 exe "keepalt noswapfile abo ".winsz."wincmd s"
631" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200632
633 elseif a:style == 4 " Vexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100634" call Decho("style=4: Vexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200635 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200636 if winsz == 0|let winsz= ""|endif
637 exe "keepalt noswapfile lefta ".winsz."wincmd v"
638" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200639
640 elseif a:style == 5 " Vexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100641" call Decho("style=5: Vexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200642 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200643 if winsz == 0|let winsz= ""|endif
644 exe "keepalt noswapfile rightb ".winsz."wincmd v"
645" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200646
647 elseif a:style == 6 " Texplore
648 call s:SaveBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +0100649" call Decho("style = 6: Texplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200650 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaar13600302014-05-22 18:26:40 +0200651" call Decho("exe keepalt tabnew ".fnameescape(curdir))
Bram Moolenaarff034192013-04-24 18:51:19 +0200652 call s:RestoreBufVars()
653 endif
654 call s:RestoreWinVars()
655" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +0100656" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6")
Bram Moolenaarff034192013-04-24 18:51:19 +0200657 endif
658 keepj norm! 0
659
660 if a:0 > 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100661" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200662 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara6878372014-03-22 21:02:50 +0100663" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin")
Bram Moolenaarff034192013-04-24 18:51:19 +0200664 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara6878372014-03-22 21:02:50 +0100665" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200666 elseif a:1 == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +0100667" call Decho("..case a:1<".a:1.">: matches .")
Bram Moolenaarff034192013-04-24 18:51:19 +0200668 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
669 if dirname !~ '/$'
670 let dirname= dirname."/"
671 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100672" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200673 elseif a:1 =~ '\$'
Bram Moolenaara6878372014-03-22 21:02:50 +0100674" call Decho("..case a:1<".a:1.">: matches ending $")
Bram Moolenaarff034192013-04-24 18:51:19 +0200675 let dirname= simplify(expand(a:1))
Bram Moolenaara6878372014-03-22 21:02:50 +0100676" call Decho("..using user-specified dirname<".dirname."> with $env-var")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200677 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +0100678" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200679 let dirname= simplify(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100680" call Decho("..using user-specified dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200681 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100682" call Decho("..case a:1: pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200683 let dirname= a:1
684 endif
685 else
686 " clear explore
Bram Moolenaara6878372014-03-22 21:02:50 +0100687" call Decho("case a:0=".a:0.": clearing Explore list")
Bram Moolenaarff034192013-04-24 18:51:19 +0200688 call s:NetrwClearExplore()
689" call Dret("netrw#Explore : cleared list")
690 return
691 endif
692
Bram Moolenaara6878372014-03-22 21:02:50 +0100693" call Decho("dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200694 if dirname =~ '\.\./\=$'
695 let dirname= simplify(fnamemodify(dirname,':p:h'))
696 elseif dirname =~ '\.\.' || dirname == '.'
697 let dirname= simplify(fnamemodify(dirname,':p'))
698 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100699" call Decho("dirname<".dirname."> (after simplify)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200700
701 if dirname =~ '^\*//'
702 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100703" call Decho("case starpat=1: Explore *//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200704 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
705 let starpat= 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100706" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200707 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
708
709 elseif dirname =~ '^\*\*//'
710 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100711" call Decho("case starpat=2: Explore **//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200712 let pattern= substitute(dirname,'^\*\*//','','')
713 let starpat= 2
Bram Moolenaara6878372014-03-22 21:02:50 +0100714" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200715
716 elseif dirname =~ '/\*\*/'
717 " handle .../**/.../filepat
Bram Moolenaara6878372014-03-22 21:02:50 +0100718" call Decho("case starpat=4: Explore .../**/.../filepat")
Bram Moolenaarff034192013-04-24 18:51:19 +0200719 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
720 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
721 let b:netrw_curdir = prefixdir
722 else
723 let b:netrw_curdir= getcwd().'/'.prefixdir
724 endif
725 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
726 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100727" call Decho("..pwd<".getcwd()."> dirname<".dirname.">")
728" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200729
730 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200731 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let starpat= 3
Bram Moolenaara6878372014-03-22 21:02:50 +0100733" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200734
735 elseif dirname=~ '^\*\*/'
736 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
737 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100738" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
740 else
741 let starpat= 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100742" call Decho("case starpat=0: default")
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 endif
744
745 if starpat == 0 && a:indx >= 0
746 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara6878372014-03-22 21:02:50 +0100747" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 if dirname == ""
749 let dirname= curfiledir
Bram Moolenaara6878372014-03-22 21:02:50 +0100750" call Decho("..empty dirname, using current file's directory<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200752 if dirname =~ '^scp://' || dirname =~ '^ftp://'
753 call netrw#Nread(2,dirname)
754 "call s:NetrwBrowse(0,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200756 if dirname == ""
757 let dirname= getcwd()
758 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +0100759 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
760 " depending on whether backslashes have been converted to forward slashes by earlier code).
761 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200762 let dirname= b:netrw_curdir."/".dirname
763 endif
764 elseif dirname !~ '^/'
765 let dirname= b:netrw_curdir."/".dirname
766 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100767" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +0100769" call Decho("win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 endif
771 if exists("w:netrw_bannercnt")
772 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
773 " If one wants to return the same place in the netrw window, use :Rex instead.
774 exe w:netrw_bannercnt
775 endif
776
Bram Moolenaara6878372014-03-22 21:02:50 +0100777" call Decho("curdir<".curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 " ---------------------------------------------------------------------
779 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
780" if has("win32") || has("win95") || has("win64") || has("win16")
781" keepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
782" else
783" keepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
784" endif
785 " ---------------------------------------------------------------------
786
787 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
788 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
789 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
790 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
791 elseif a:indx <= 0
792 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara6878372014-03-22 21:02:50 +0100793" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100795" call Decho("..set up <s-up> and <s-down> maps")
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let s:didstarstar= 1
797 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
798 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
799 endif
800
801 if has("path_extra")
Bram Moolenaara6878372014-03-22 21:02:50 +0100802" call Decho("..starpat=".starpat.": has +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 if !exists("w:netrw_explore_indx")
804 let w:netrw_explore_indx= 0
805 endif
806
807 let indx = a:indx
Bram Moolenaara6878372014-03-22 21:02:50 +0100808" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]")
Bram Moolenaarff034192013-04-24 18:51:19 +0200809
810 if indx == -1
811 " Nexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100812" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 if !exists("w:netrw_explore_list") " sanity check
814 keepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaara6878372014-03-22 21:02:50 +0100815 if has("clipboard")
816 sil! let @* = keepregstar
817 sil! let @+ = keepregstar
818 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 sil! let @/ = keepregslash
820" call Dret("netrw#Explore")
821 return
822 endif
823 let indx= w:netrw_explore_indx
824 if indx < 0 | let indx= 0 | endif
825 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
826 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100827" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
829 let indx= indx + 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100830" call Decho("....indx=".indx." (Nexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 endwhile
832 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100833" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200834
835 elseif indx == -2
836 " Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100837" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 if !exists("w:netrw_explore_list") " sanity check
839 keepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaara6878372014-03-22 21:02:50 +0100840 if has("clipboard")
841 sil! let @* = keepregstar
842 sil! let @+ = keepregstar
843 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 sil! let @/ = keepregslash
845" call Dret("netrw#Explore")
846 return
847 endif
848 let indx= w:netrw_explore_indx
849 if indx < 0 | let indx= 0 | endif
850 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
851 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100852" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 while indx >= 0 && curfile == w:netrw_explore_list[indx]
854 let indx= indx - 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100855" call Decho("....indx=".indx." (Pexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200856 endwhile
857 if indx < 0 | let indx= 0 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100858" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 else
861 " Explore -- initialize
862 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100863" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 keepj keepalt call s:NetrwClearExplore()
865 let w:netrw_explore_indx= 0
866 if !exists("b:netrw_curdir")
867 let b:netrw_curdir= getcwd()
868 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100869" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200870
871 " switch on starpat to build the w:netrw_explore_list of files
872 if starpat == 1
873 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100874" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls)
875" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 try
877 exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
878 catch /^Vim\%((\a\+)\)\=:E480/
879 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
880" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
881 return
882 endtry
883 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
884 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
885
886 elseif starpat == 2
887 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100888" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)")
889" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 try
891 exe "sil keepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
892 catch /^Vim\%((\a\+)\)\=:E480/
893 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
894 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100895 if has("clipboard")
896 sil! let @* = keepregstar
897 sil! let @+ = keepregstar
898 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 sil! let @/ = keepregslash
900" call Dret("netrw#Explore : no files matched pattern")
901 return
902 endtry
903 let s:netrw_curdir = b:netrw_curdir
904 let w:netrw_explore_list = getqflist()
905 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
906 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
907
908 elseif starpat == 3
909 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100910" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 let filepat= substitute(dirname,'^\*/','','')
912 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara6878372014-03-22 21:02:50 +0100913" call Decho("....b:netrw_curdir<".b:netrw_curdir.">")
914" call Decho("....filepat<".filepat.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200915 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
916 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
917
918 elseif starpat == 4
919 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100920" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
922 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
923 endif " switch on starpat to build w:netrw_explore_list
924
925 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara6878372014-03-22 21:02:50 +0100926" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">")
927" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +0200928
929 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
930 keepalt keepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +0100931 if has("clipboard")
932 sil! let @* = keepregstar
933 sil! let @+ = keepregstar
934 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 sil! let @/ = keepregslash
936" call Dret("netrw#Explore : no files matched")
937 return
938 endif
939 endif " if indx ... endif
940
941 " NetrwStatusLine support - for exploring support
942 let w:netrw_explore_indx= indx
Bram Moolenaara6878372014-03-22 21:02:50 +0100943" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +0200944
945 " wrap the indx around, but issue a note
946 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100947" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
949 let w:netrw_explore_indx= indx
950 keepalt keepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
951 endif
952
953 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara6878372014-03-22 21:02:50 +0100954" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +0100956" call Decho("....newdir<".newdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200957
Bram Moolenaara6878372014-03-22 21:02:50 +0100958" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 call netrw#LocalBrowseCheck(newdir)
960 if !exists("w:netrw_liststyle")
961 let w:netrw_liststyle= g:netrw_liststyle
962 endif
963 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
964 keepalt keepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
965 else
966 keepalt keepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
967 endif
968 let w:netrw_explore_mtchcnt = indx + 1
969 let w:netrw_explore_bufnr = bufnr("%")
970 let w:netrw_explore_line = line(".")
971 keepalt keepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara6878372014-03-22 21:02:50 +0100972" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line)
Bram Moolenaarff034192013-04-24 18:51:19 +0200973
974 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100975" call Decho("..your vim does not have +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 if !exists("g:netrw_quiet")
977 keepalt keepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
978 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100979 if has("clipboard")
980 sil! let @* = keepregstar
981 sil! let @+ = keepregstar
982 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 sil! let @/ = keepregslash
984" call Dret("netrw#Explore : missing +path_extra")
985 return
986 endif
987
988 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100989" call Decho("..default case: Explore newdir<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
991 sil! unlet w:netrw_treedict
992 sil! unlet w:netrw_treetop
993 endif
994 let newdir= dirname
995 if !exists("b:netrw_curdir")
996 keepj call netrw#LocalBrowseCheck(getcwd())
997 else
998 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
999 endif
1000 endif
1001
1002 " visual display of **/ **// */ Exploration files
Bram Moolenaara6878372014-03-22 21:02:50 +01001003" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"))
1004" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +01001006" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001008 " only update match list when current directory isn't the same as before
Bram Moolenaara6878372014-03-22 21:02:50 +01001009" call Decho("only update match list when current directory not the same as before")
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 let s:explore_prvdir = b:netrw_curdir
1011 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001012 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 if b:netrw_curdir !~ '/$'
1014 let dirlen= dirlen + 1
1015 endif
1016 let prvfname= ""
1017 for fname in w:netrw_explore_list
Bram Moolenaara6878372014-03-22 21:02:50 +01001018" call Decho("fname<".fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 if fname =~ '^'.b:netrw_curdir
1020 if s:explore_match == ""
1021 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1022 else
1023 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1024 endif
1025 elseif fname !~ '^/' && fname != prvfname
1026 if s:explore_match == ""
1027 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1028 else
1029 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1030 endif
1031 endif
1032 let prvfname= fname
1033 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +01001034" call Decho("explore_match<".s:explore_match.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 exe "2match netrwMarkFile /".s:explore_match."/"
1036 endif
1037 echo "<s-up>==Pexplore <s-down>==Nexplore"
1038 else
1039 2match none
1040 if exists("s:explore_match") | unlet s:explore_match | endif
1041 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1042 echo " "
Bram Moolenaara6878372014-03-22 21:02:50 +01001043" call Decho("cleared explore match list")
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 endif
1045
Bram Moolenaara6878372014-03-22 21:02:50 +01001046 " since Explore may be used to initialize netrw's browser,
1047 " there's no danger of a late FocusGained event on initialization.
1048 " Consequently, set s:netrw_events to 2.
1049 let s:netrw_events= 2
1050 if has("clipboard")
1051 sil! let @* = keepregstar
1052 sil! let @+ = keepregstar
1053 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 sil! let @/ = keepregslash
1055" call Dret("netrw#Explore : @/<".@/.">")
1056endfun
1057
1058" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001059" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
1060fun! netrw#Lexplore(...)
1061" call Dfunc("netrw#Lexplore() a:0=".a:0)
Bram Moolenaara6878372014-03-22 21:02:50 +01001062 if a:0 > 0 && a:1 != ""
1063 " if a netrw window is already on the left-side of the tab
1064 " and a directory has been specified, explore with that
1065 " directory.
1066 let lexwinnr= winnr()
1067 exe "1wincmd w"
1068 if &ft == "netrw"
1069 exe "Explore ".fnameescape(a:1)
1070 exe lexwinnr."wincmd w"
1071 endif
1072 exe lexwinnr."wincmd w"
1073" call Dret("netrw#Lexplore")
1074 return
1075 endif
1076
Bram Moolenaar8d043172014-01-23 14:24:41 +01001077 if exists("t:netrw_lexbufnr")
1078 " close down netrw explorer window
1079 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
1080 if lexwinnr != -1
1081 let curwin = winnr()
1082 exe lexwinnr."wincmd w"
1083 close
1084 exe curwin."wincmd w"
1085 endif
1086 unlet t:netrw_lexbufnr
1087
1088 else
1089 " open netrw explorer window
1090 exe "1wincmd w"
1091 let keep_altv = g:netrw_altv
1092 let g:netrw_altv = 0
1093 if a:0 > 0 && a:1 != ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001094 exe "Vexplore ".fnameescape(a:1)
Bram Moolenaar8d043172014-01-23 14:24:41 +01001095 else
1096 Vexplore .
1097 endif
1098 let g:netrw_altv = keep_altv
1099 let t:netrw_lexbufnr = bufnr("%")
1100 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001101 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
1102 let g:netrw_chgwin= 2
1103 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001104" call Dret("netrw#Lexplore")
1105endfun
1106
1107" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001108" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001109" supports :NetrwClean -- remove netrw from first directory on runtimepath
1110" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001111fun! netrw#Clean(sys)
1112" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001113
1114 if a:sys
1115 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1116 else
1117 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1118 endif
1119" call Decho("choice=".choice)
1120 let diddel= 0
1121 let diddir= ""
1122
1123 if choice == 1
1124 for dir in split(&rtp,',')
1125 if filereadable(dir."/plugin/netrwPlugin.vim")
1126" call Decho("removing netrw-related files from ".dir)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001127 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1128 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1129 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1130 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1131 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1132 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 +00001133 let diddir= dir
1134 let diddel= diddel + 1
1135 if !a:sys|break|endif
1136 endif
1137 endfor
1138 endif
1139
1140 echohl WarningMsg
1141 if diddel == 0
1142 echomsg "netrw is either not installed or not removable"
1143 elseif diddel == 1
1144 echomsg "removed one copy of netrw from <".diddir.">"
1145 else
1146 echomsg "removed ".diddel." copies of netrw"
1147 endif
1148 echohl None
1149
Bram Moolenaara6878372014-03-22 21:02:50 +01001150" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001151endfun
1152
Bram Moolenaar5c736222010-01-06 20:54:52 +01001153" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001154" netrw#MakeTgt: make a target out of the directory name provided {{{2
1155fun! netrw#MakeTgt(dname)
1156" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1157 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
1158 let svpos = netrw#SavePosn()
1159 let s:netrwmftgt_islocal= (a:dname !~ '^\a\+://')
1160" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal)
1161 if s:netrwmftgt_islocal
1162 let netrwmftgt= simplify(a:dname)
1163 else
1164 let netrwmftgt= a:dname
1165 endif
1166 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1167 " re-selected target, so just clear it
1168 unlet s:netrwmftgt s:netrwmftgt_islocal
1169 else
1170 let s:netrwmftgt= netrwmftgt
1171 endif
1172 if g:netrw_fastbrowse <= 1
1173 call s:NetrwRefresh((b:netrw_curdir !~ '\a\+://'),b:netrw_curdir)
1174 endif
1175 call netrw#RestorePosn(svpos)
1176" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001177endfun
1178
Bram Moolenaara6878372014-03-22 21:02:50 +01001179" ---------------------------------------------------------------------
1180" netrw#Obtain: {{{2
1181" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001182" islocal=0 obtain from remote source
1183" =1 obtain from local source
1184" fname : a filename or a list of filenames
1185" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001186fun! netrw#Obtain(islocal,fname,...)
1187" call Dfunc("netrw#Obtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
Bram Moolenaarff034192013-04-24 18:51:19 +02001188 " NetrwStatusLine support - for obtaining support
1189
1190 if type(a:fname) == 1
1191 let fnamelist= [ a:fname ]
1192 elseif type(a:fname) == 3
1193 let fnamelist= a:fname
1194 else
1195 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
Bram Moolenaara6878372014-03-22 21:02:50 +01001196" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001197 return
1198 endif
1199" call Decho("fnamelist<".string(fnamelist).">")
1200 if a:0 > 0
1201 let tgtdir= a:1
1202 else
1203 let tgtdir= getcwd()
1204 endif
1205" call Decho("tgtdir<".tgtdir.">")
1206
1207 if exists("b:netrw_islocal") && b:netrw_islocal
1208 " obtain a file from local b:netrw_curdir to (local) tgtdir
1209" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir)
1210 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1211 let topath= s:ComposePath(tgtdir,"")
1212 if (has("win32") || has("win95") || has("win64") || has("win16"))
1213 " transfer files one at time
1214" call Decho("transfer files one at a time")
1215 for fname in fnamelist
1216" call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")")
1217 call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1218 if v:shell_error != 0
1219 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1220" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1221 return
1222 endif
1223 endfor
1224 else
1225 " transfer files with one command
1226" call Decho("transfer files with one command")
1227 let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)"))
1228" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")")
1229 call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1230 if v:shell_error != 0
1231 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1232" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1233 return
1234 endif
1235 endif
1236 elseif !exists("b:netrw_curdir")
1237 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1238 else
1239 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1240 endif
1241
1242 else
1243 " obtain files from remote b:netrw_curdir to local tgtdir
1244" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir)
1245 if type(a:fname) == 1
1246 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1247 endif
1248 call s:NetrwMethod(b:netrw_curdir)
1249
1250 if b:netrw_method == 4
1251 " obtain file using scp
1252" call Decho("obtain via scp (method#4)")
1253 if exists("g:netrw_port") && g:netrw_port != ""
1254 let useport= " ".g:netrw_scpport." ".g:netrw_port
1255 else
1256 let useport= ""
1257 endif
1258 if b:netrw_fname =~ '/'
1259 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1260 else
1261 let path= ""
1262 endif
1263 let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)'))
1264" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1))
1265 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1)
1266
1267 elseif b:netrw_method == 2
1268 " obtain file using ftp + .netrc
1269" call Decho("obtain via ftp+.netrc (method #2)")
1270 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
1271 let tmpbufnr= bufnr("%")
1272 setl ff=unix
1273 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
1274 keepj put =g:netrw_ftpmode
1275" call Decho("filter input: ".getline('$'))
1276 endif
1277
1278 if exists("b:netrw_fname") && b:netrw_fname != ""
1279 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
1280" call Decho("filter input: ".getline('$'))
1281 endif
1282
1283 if exists("g:netrw_ftpextracmd")
1284 keepj put =g:netrw_ftpextracmd
1285" call Decho("filter input: ".getline('$'))
1286 endif
1287 for fname in fnamelist
1288 call setline(line("$")+1,'get "'.fname.'"')
1289" call Decho("filter input: ".getline('$'))
1290 endfor
1291 if exists("g:netrw_port") && g:netrw_port != ""
1292" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1293 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
1294 else
1295" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1296 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
1297 endif
1298 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1299 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1300 let debugkeep= &debug
1301 setl debug=msg
1302 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1303 let &debug= debugkeep
1304 endif
1305
1306 elseif b:netrw_method == 3
1307 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
1308" call Decho("obtain via ftp+mipf (method #3)")
1309 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
1310 let tmpbufnr= bufnr("%")
1311 setl ff=unix
1312
1313 if exists("g:netrw_port") && g:netrw_port != ""
1314 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
1315" call Decho("filter input: ".getline('$'))
1316 else
1317 keepj put ='open '.g:netrw_machine
1318" call Decho("filter input: ".getline('$'))
1319 endif
1320
1321 if exists("g:netrw_uid") && g:netrw_uid != ""
1322 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1323 keepj put =g:netrw_uid
1324" call Decho("filter input: ".getline('$'))
1325 if exists("s:netrw_passwd") && s:netrw_passwd != ""
1326 keepj put ='\"'.s:netrw_passwd.'\"'
1327 endif
1328" call Decho("filter input: ".getline('$'))
1329 elseif exists("s:netrw_passwd")
1330 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
1331" call Decho("filter input: ".getline('$'))
1332 endif
1333 endif
1334
1335 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
1336 keepj put =g:netrw_ftpmode
1337" call Decho("filter input: ".getline('$'))
1338 endif
1339
1340 if exists("b:netrw_fname") && b:netrw_fname != ""
1341 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
1342" call Decho("filter input: ".getline('$'))
1343 endif
1344
1345 if exists("g:netrw_ftpextracmd")
1346 keepj put =g:netrw_ftpextracmd
1347" call Decho("filter input: ".getline('$'))
1348 endif
1349
1350 if exists("g:netrw_ftpextracmd")
1351 keepj put =g:netrw_ftpextracmd
1352" call Decho("filter input: ".getline('$'))
1353 endif
1354 for fname in fnamelist
1355 keepj call setline(line("$")+1,'get "'.fname.'"')
1356 endfor
1357" call Decho("filter input: ".getline('$'))
1358
1359 " perform ftp:
1360 " -i : turns off interactive prompting from ftp
1361 " -n unix : DON'T use <.netrc>, even though it exists
1362 " -n win32: quit being obnoxious about password
1363 keepj norm! 1Gdd
1364" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
1365 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
1366 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1367 if getline(1) !~ "^$"
1368" call Decho("error<".getline(1).">")
1369 if !exists("g:netrw_quiet")
1370 keepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
1371 endif
1372 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001373
1374 elseif b:netrw_method == 9
1375 " obtain file using sftp
1376" call Decho("obtain via sftp (method #9)")
1377 if a:fname =~ '/'
1378 let localfile= substitute(a:fname,'^.*/','','')
1379 else
1380 let localfile= a:fname
1381 endif
1382" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1).shellescape(localfile)." ".shellescape(tgtdir))
1383 exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1).shellescape(localfile)." ".shellescape(tgtdir)
1384
Bram Moolenaarff034192013-04-24 18:51:19 +02001385 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001386 " probably a badly formed url; protocol not recognized
1387" call Dret("netrw#Obtain : unsupported method")
1388 return
1389
1390 else
1391 " protocol recognized but not supported for Obtain (yet?)
1392 if !exists("g:netrw_quiet")
1393 keepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
1394 endif
1395" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 return
1397 endif
1398
1399 " restore status line
1400 if type(a:fname) == 1 && exists("s:netrw_users_stl")
1401 keepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
1402 endif
1403
1404 endif
1405
1406 " cleanup
1407 if exists("tmpbufnr")
1408 if bufnr("%") != tmpbufnr
1409 exe tmpbufnr."bw!"
1410 else
1411 q!
1412 endif
1413 endif
1414
Bram Moolenaara6878372014-03-22 21:02:50 +01001415" call Dret("netrw#Obtain")
1416endfun
1417
1418" ---------------------------------------------------------------------
1419" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1420fun! netrw#Nread(mode,fname)
1421" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
1422 call netrw#SavePosn()
1423 call netrw#NetRead(a:mode,a:fname)
1424 call netrw#RestorePosn()
1425
1426 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1427 if exists("w:netrw_bannercnt")
1428 " start with cursor just after the banner
1429 exe w:netrw_bannercnt
1430 endif
1431 endif
1432" call Dret("netrw#Nread")
1433endfun
1434
1435" ------------------------------------------------------------------------
1436" s:NetrwOptionRestore: restore options (based on prior s:NetrwOptionSave) {{{2
1437fun! s:NetrwOptionRestore(vt)
1438" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1439" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
1440 if !exists("{a:vt}netrw_optionsave")
1441 if exists("s:nbcd_curpos_{bufnr('%')}")
1442" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
1443 keepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
1444" call Decho("win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1445" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1446 unlet s:nbcd_curpos_{bufnr('%')}
1447 else
1448" call Decho("no previous position")
1449 endif
1450" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
1451" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1452" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
1453 return
1454 endif
1455 unlet {a:vt}netrw_optionsave
1456
1457 if exists("+acd")
1458 if exists("{a:vt}netrw_acdkeep")
1459" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1460 let curdir = getcwd()
1461 let &l:acd = {a:vt}netrw_acdkeep
1462 unlet {a:vt}netrw_acdkeep
1463 if &l:acd
1464 call s:NetrwLcd(curdir)
1465 endif
1466 endif
1467 endif
1468 if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif
1469 if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif
1470 if g:netrw_liststyle != s:TREELIST
1471 if exists("{a:vt}netrw_bhkeep") |let &l:bh = {a:vt}netrw_bhkeep |unlet {a:vt}netrw_bhkeep |endif
1472 endif
1473 if exists("{a:vt}netrw_blkeep") |let &l:bl = {a:vt}netrw_blkeep |unlet {a:vt}netrw_blkeep |endif
1474 if exists("{a:vt}netrw_btkeep") |let &l:bt = {a:vt}netrw_btkeep |unlet {a:vt}netrw_btkeep |endif
1475 if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif
1476 if exists("{a:vt}netrw_cedit") |let &cedit = {a:vt}netrw_cedit |unlet {a:vt}netrw_cedit |endif
1477 if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif
1478 if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif
1479 if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif
1480 if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif
1481 if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif
1482 if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif
1483 if exists("{a:vt}netrw_fenkeep") |let &l:fen = {a:vt}netrw_fenkeep |unlet {a:vt}netrw_fenkeep |endif
1484 if exists("{a:vt}netrw_ffkeep") |let &l:ff = {a:vt}netrw_ffkeep |unlet {a:vt}netrw_ffkeep |endif
1485 if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif
1486 if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif
1487 if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif
1488 if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif
1489 if exists("{a:vt}netrw_iskkeep") |let &l:isk = {a:vt}netrw_iskkeep |unlet {a:vt}netrw_iskkeep |endif
1490 if exists("{a:vt}netrw_lskeep") |let &l:ls = {a:vt}netrw_lskeep |unlet {a:vt}netrw_lskeep |endif
1491 if exists("{a:vt}netrw_makeep") |let &l:ma = {a:vt}netrw_makeep |unlet {a:vt}netrw_makeep |endif
1492 if exists("{a:vt}netrw_magickeep")|let &l:magic = {a:vt}netrw_magickeep |unlet {a:vt}netrw_magickeep|endif
1493 if exists("{a:vt}netrw_modkeep") |let &l:mod = {a:vt}netrw_modkeep |unlet {a:vt}netrw_modkeep |endif
1494 if exists("{a:vt}netrw_nukeep") |let &l:nu = {a:vt}netrw_nukeep |unlet {a:vt}netrw_nukeep |endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001495 if exists("{a:vt}netrw_rnukeep") |let &l:rnu = {a:vt}netrw_rnukeep |unlet {a:vt}netrw_rnukeep |endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001496 if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif
1497 if exists("{a:vt}netrw_rokeep") |let &l:ro = {a:vt}netrw_rokeep |unlet {a:vt}netrw_rokeep |endif
1498 if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif
1499 if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif
1500 if has("clipboard")
1501 if exists("{a:vt}netrw_starkeep") |let @* = {a:vt}netrw_starkeep |unlet {a:vt}netrw_starkeep |endif
1502 endif
1503 " Problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1504" if exists("{a:vt}netrw_tskeep") |let &l:ts = {a:vt}netrw_tskeep |unlet {a:vt}netrw_tskeep |endif
1505 if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif
1506 if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif
1507 if exists("{a:vt}netrw_wrapkeep") |let &l:wrap = {a:vt}netrw_wrapkeep |unlet {a:vt}netrw_wrapkeep |endif
1508 if exists("{a:vt}netrw_writekeep")|let &l:write = {a:vt}netrw_writekeep |unlet {a:vt}netrw_writekeep|endif
1509 if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif
1510 if exists("{a:vt}netrw_swfkeep")
1511 if &directory == ""
1512 " user hasn't specified a swapfile directory;
1513 " netrw will temporarily set the swapfile directory
1514 " to the current directory as returned by getcwd().
1515 let &l:directory= getcwd()
1516 sil! let &l:swf = {a:vt}netrw_swfkeep
1517 setl directory=
1518 unlet {a:vt}netrw_swfkeep
1519 elseif &l:swf != {a:vt}netrw_swfkeep
1520 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1521 sil! let &l:swf= {a:vt}netrw_swfkeep
1522 unlet {a:vt}netrw_swfkeep
1523 endif
1524 endif
1525 if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
1526 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1527 if exists("{a:vt}netrw_dirkeep")
1528 call s:NetrwLcd(dirkeep)
1529 unlet {a:vt}netrw_dirkeep
1530 endif
1531 endif
1532 if has("clipboard")
1533 if exists("{a:vt}netrw_regstar") |sil! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif
1534 endif
1535 if exists("{a:vt}netrw_regslash")|sil! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif
1536 if exists("s:nbcd_curpos_{bufnr('%')}")
1537" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
1538 keepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
1539" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1540 if exists("s:nbcd_curpos_".bufnr('%'))
1541 unlet s:nbcd_curpos_{bufnr('%')}
1542 endif
1543 else
1544" call Decho("no previous position")
1545 endif
1546
1547" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1548" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"))
1549" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1550" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"))
1551" call Decho("ts=".&l:ts)
1552 " Moved the filetype detect here from NetrwGetFile() because remote files
1553 " were having their filetype detect-generated settings overwritten by
1554 " NetrwOptionRestore.
1555 if &ft != "netrw"
1556" call Decho("filetype detect (ft=".&ft.")")
1557 filetype detect
1558 endif
1559" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
1560" call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
1561endfun
1562
1563" ---------------------------------------------------------------------
1564" s:NetrwOptionSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1565" Options get restored by s:NetrwOptionRestore()
1566" 06/08/07 : removed call to NetrwSafeOptions(), either placed
1567" immediately after NetrwOptionSave() calls in NetRead
1568" and NetWrite, or after the s:NetrwEnew() call in
1569" NetrwBrowse.
1570" vt: normally its "w:" or "s:" (a variable type)
1571fun! s:NetrwOptionSave(vt)
1572" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1573" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"))
1574" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
1575
1576 if !exists("{a:vt}netrw_optionsave")
1577 let {a:vt}netrw_optionsave= 1
1578 else
1579" call Dret("s:NetrwOptionSave : options already saved")
1580 return
1581 endif
1582" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
1583
1584 " Save current settings and current directory
1585" call Decho("saving current settings and current directory")
1586 let s:yykeep = @@
1587 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1588 let {a:vt}netrw_aikeep = &l:ai
1589 let {a:vt}netrw_awkeep = &l:aw
1590 let {a:vt}netrw_bhkeep = &l:bh
1591 let {a:vt}netrw_blkeep = &l:bl
Bram Moolenaar13600302014-05-22 18:26:40 +02001592 let {a:vt}netrw_btkeep = &l:bt
Bram Moolenaara6878372014-03-22 21:02:50 +01001593 let {a:vt}netrw_bombkeep = &l:bomb
1594 let {a:vt}netrw_cedit = &cedit
1595 let {a:vt}netrw_cikeep = &l:ci
1596 let {a:vt}netrw_cinkeep = &l:cin
1597 let {a:vt}netrw_cinokeep = &l:cino
1598 let {a:vt}netrw_comkeep = &l:com
1599 let {a:vt}netrw_cpokeep = &l:cpo
1600 let {a:vt}netrw_diffkeep = &l:diff
1601 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar13600302014-05-22 18:26:40 +02001602 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep == 1
1603 let {a:vt}netrw_ffkeep = &l:ff
1604 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001605 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1606 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1607 let {a:vt}netrw_hidkeep = &l:hidden
1608 let {a:vt}netrw_imkeep = &l:im
1609 let {a:vt}netrw_iskkeep = &l:isk
1610 let {a:vt}netrw_lskeep = &l:ls
1611 let {a:vt}netrw_makeep = &l:ma
1612 let {a:vt}netrw_magickeep = &l:magic
1613 let {a:vt}netrw_modkeep = &l:mod
1614 let {a:vt}netrw_nukeep = &l:nu
Bram Moolenaar13600302014-05-22 18:26:40 +02001615 let {a:vt}netrw_rnukeep = &l:rnu
Bram Moolenaara6878372014-03-22 21:02:50 +01001616 let {a:vt}netrw_repkeep = &l:report
1617 let {a:vt}netrw_rokeep = &l:ro
1618 let {a:vt}netrw_selkeep = &l:sel
1619 let {a:vt}netrw_spellkeep = &l:spell
1620 if g:netrw_use_noswf
1621 let {a:vt}netrw_swfkeep = &l:swf
1622 endif
1623 if has("clipboard")
1624 let {a:vt}netrw_starkeep = @*
1625 endif
1626 let {a:vt}netrw_tskeep = &l:ts
1627 let {a:vt}netrw_twkeep = &l:tw " textwidth
1628 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1629 let {a:vt}netrw_wrapkeep = &l:wrap
1630 let {a:vt}netrw_writekeep = &l:write
1631
1632 " save a few selected netrw-related variables
1633" call Decho("saving a few selected netrw-related variables")
1634 if g:netrw_keepdir
1635 let {a:vt}netrw_dirkeep = getcwd()
1636 endif
1637 if has("clipboard")
1638 if &go =~# 'a' | sil! let {a:vt}netrw_regstar = @* | endif
1639 endif
1640 sil! let {a:vt}netrw_regslash= @/
1641
1642" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
1643" call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr())
1644endfun
1645
1646" ------------------------------------------------------------------------
1647" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
1648" Use s:NetrwSaveOptions() to save user settings
1649" Use s:NetrwOptionRestore() to restore user settings
1650fun! s:NetrwSafeOptions()
1651" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1652" call Decho("win#".winnr()."'s ft=".&ft)
1653" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
1654 if exists("+acd") | setl noacd | endif
1655 setl noai
1656 setl noaw
1657 setl nobl
1658 setl nobomb
1659 setl bt=nofile
1660 setl noci
1661 setl nocin
1662 if g:netrw_liststyle == s:TREELIST
1663 setl bh=hide
1664 endif
1665 setl cino=
1666 setl com=
1667 setl cpo-=a
1668 setl cpo-=A
1669 setl fo=nroql2
1670 setl nohid
1671 setl noim
1672 setl isk+=@ isk+=* isk+=/
1673 setl magic
1674 if g:netrw_use_noswf
1675 setl noswf
1676 endif
1677 setl report=10000
1678 setl sel=inclusive
1679 setl nospell
1680 setl tw=0
1681 setl wig=
1682 setl cedit&
1683 call s:NetrwCursor()
1684
1685 " allow the user to override safe options
1686" call Decho("ft<".&ft."> ei=".&ei)
1687 if &ft == "netrw"
1688" call Decho("do any netrw FileType autocmds (doau FileType netrw)")
1689 sil! keepalt keepj doau FileType netrw
1690 endif
1691
1692" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh)
1693" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
1694" call Dret("s:NetrwSafeOptions")
Bram Moolenaarff034192013-04-24 18:51:19 +02001695endfun
1696
1697" ---------------------------------------------------------------------
1698" NetrwStatusLine: {{{2
1699fun! NetrwStatusLine()
1700
1701" vvv NetrwStatusLine() debugging vvv
1702" let g:stlmsg=""
1703" if !exists("w:netrw_explore_bufnr")
1704" let g:stlmsg="!X<explore_bufnr>"
1705" elseif w:netrw_explore_bufnr != bufnr("%")
1706" let g:stlmsg="explore_bufnr!=".bufnr("%")
1707" endif
1708" if !exists("w:netrw_explore_line")
1709" let g:stlmsg=" !X<explore_line>"
1710" elseif w:netrw_explore_line != line(".")
1711" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1712" endif
1713" if !exists("w:netrw_explore_list")
1714" let g:stlmsg=" !X<explore_list>"
1715" endif
1716" ^^^ NetrwStatusLine() debugging ^^^
1717
1718 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")
1719 " restore user's status line
1720 let &stl = s:netrw_users_stl
1721 let &laststatus = s:netrw_users_ls
1722 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1723 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1724 return ""
1725 else
1726 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1727 endif
1728endfun
1729
1730" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001731" Netrw Transfer Functions: {{{1
1732" ===============================
1733
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001735" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001736" mode: =0 read remote file and insert before current line
1737" =1 read remote file and insert after current line
1738" =2 replace with remote file
1739" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001740fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001741" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001742
Bram Moolenaar5c736222010-01-06 20:54:52 +01001743 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001744 call s:NetrwOptionSave("w:")
1745 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001746 call s:RestoreCursorline()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001747
Bram Moolenaar5c736222010-01-06 20:54:52 +01001748 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001749 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001750 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001751 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001752 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001753 elseif a:mode == 2 " replace with remote file
1754 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001755 elseif a:mode == 3 " skip read of file (leave as temporary)
1756 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001757 else
1758 exe a:mode
1759 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001760 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001761 let ichoice = (a:0 == 0)? 0 : 1
1762" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
1763
Bram Moolenaar5c736222010-01-06 20:54:52 +01001764 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001765 let tmpfile= s:GetTempfile("")
1766 if tmpfile == ""
1767" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001768 return
1769 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001770
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001771 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001773 " attempt to repeat with previous host-file-etc
1774 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001775" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001776 let choice = b:netrw_lastfile
1777 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001778
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001779 else
1780 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001781" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001782
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001783 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001784 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001785 echomsg 'NetRead Usage:'
1786 echomsg ':Nread machine:path uses rcp'
1787 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1788 echomsg ':Nread "machine id password path" uses ftp'
1789 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1790 echomsg ':Nread fetch://machine/path uses fetch'
1791 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1792 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaara6878372014-03-22 21:02:50 +01001793 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001794 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1795 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1796 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1797 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001798 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001799 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001800
Bram Moolenaar9964e462007-05-05 17:54:07 +00001801 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001802 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001803" call Decho("reconstructing choice")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001804 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001805 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001806 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001807 else
1808 " case "... ... ..."
1809 let choice = strpart(choice,1,strlen(choice)-1)
1810 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001811
Bram Moolenaar9964e462007-05-05 17:54:07 +00001812 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001813 let wholechoice = wholechoice . " " . choice
1814 let ichoice = ichoice + 1
1815 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001816 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001817 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001818 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001819" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001820 return
1821 endif
1822 let choice= a:{ichoice}
1823 endwhile
1824 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1825 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 endif
1827 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001829" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001830 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001831
Bram Moolenaar5c736222010-01-06 20:54:52 +01001832 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001833 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001834 if !exists("b:netrw_method") || b:netrw_method < 0
1835" call Dfunc("netrw#NetRead : unsupported method")
1836 return
1837 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001838 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001839
Bram Moolenaar8d043172014-01-23 14:24:41 +01001840 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaar446cb832008-06-24 21:56:24 +00001841" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02001842 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001843" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001844 keepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001845" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001846 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001848
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001849 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01001850 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001851 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001852 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
1853 echo "(netrw) Processing your read request..."
1854 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001855
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001856 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001857 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001858 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001859" call Decho("read via rcp (method #1)")
Bram Moolenaard68071d2006-05-02 22:08:30 +00001860 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001861 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01001862 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001863 " ER: the tmpfile is full path: rcp sees C:\... as host C
1864 if s:netrw_has_nt_rcp == 1
1865 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1866 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
1867 else
1868 " Any way needed it machine contains a '.'
1869 let uid_machine = g:netrw_machine .'.'. $USERNAME
1870 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001872 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1873 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1874 else
1875 let uid_machine = g:netrw_machine
1876 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001878" 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 +01001879 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 +00001880 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001881 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001882
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001883 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001884 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001885 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001886" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +00001887 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +02001888 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001889 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02001890 setl ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001891 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001892" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001893 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001894 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001895" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001896 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001897 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
1898" call Decho("filter input: ".getline(line("$")))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001899 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02001900" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1901 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001902 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02001903" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1904 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001905 endif
1906 " 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 +00001907 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00001908 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02001909 setl debug=msg
Bram Moolenaaradc21822011-04-01 18:03:16 +02001910 keepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001911 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001912 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00001913 call s:SaveBufVars()
1914 bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01001915 if bufname("%") == "" && getline("$") == "" && line('$') == 1
1916 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00001917 q!
1918 endif
1919 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00001920 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001921 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001922
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001923 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001924 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001925 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
1926 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001927" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001928 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001929 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001930 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02001931 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001932 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001933 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00001934" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001935 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001936 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00001937" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001938 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001939
Bram Moolenaar97d62492012-11-15 21:28:22 +01001940 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001941 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1942 keepj put =g:netrw_uid
1943" call Decho("filter input: ".getline('.'))
1944 if exists("s:netrw_passwd")
1945 keepj put ='\"'.s:netrw_passwd.'\"'
1946 endif
1947" call Decho("filter input: ".getline('.'))
1948 elseif exists("s:netrw_passwd")
1949 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
1950" call Decho("filter input: ".getline('.'))
1951 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001952 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001953
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001954 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001955 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00001956" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001957 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001958 if exists("g:netrw_ftpextracmd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001959 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00001960" call Decho("filter input: ".getline('.'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001961 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001962 keepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00001963" call Decho("filter input: ".getline('.'))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001964
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001965 " perform ftp:
1966 " -i : turns off interactive prompting from ftp
1967 " -n unix : DON'T use <.netrc>, even though it exists
1968 " -n win32: quit being obnoxious about password
Bram Moolenaaradc21822011-04-01 18:03:16 +02001969 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001970" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
1971 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001972 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1973 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001974" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001975 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001976 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001977 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001979 call s:SaveBufVars()|bd!|call s:RestoreBufVars()
1980 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001981 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001982
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001983 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001984 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001985 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001986" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001987 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00001988 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001989 else
1990 let useport= ""
1991 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001992" 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 +00001993 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 +00001994 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001995 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001996
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001997 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001998 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001999 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002000" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002002 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002003 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002004 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002005" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002006 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002007 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002008
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002009 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2010 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002011" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002012 if exists("g:netrw_http_xcmd")
Bram Moolenaara6878372014-03-22 21:02:50 +01002013" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
2014 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002015 else
Bram Moolenaara6878372014-03-22 21:02:50 +01002016" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
2017 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002018 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002019 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002020
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002021 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002022 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002023" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002024 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2025 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002026" call Decho("netrw_html<".netrw_html.">")
2027" call Decho("netrw_tag <".netrw_tag.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002028" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
2029 exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002030 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002031" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002032 exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002033 endif
2034 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01002035" call Decho("setl ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02002036 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002037
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002038 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002039 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002040 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002041" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042
Bram Moolenaar5c736222010-01-06 20:54:52 +01002043 if !executable(g:netrw_dav_cmd)
2044 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2045" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2046 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 if g:netrw_dav_cmd =~ "curl"
2049" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
2050 exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
2051 else
2052 " Construct execution string (four lines) which will be passed through filter
2053 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2054 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002055 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002056 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002057 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002058 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002059 keepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002060 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002061 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
2062 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
2063 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002064 keepj put ='get '.netrw_fname.' '.tmpfile
2065 keepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066
Bram Moolenaar5c736222010-01-06 20:54:52 +01002067 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002068 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002069" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002070 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
2071 bd!
2072 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002073 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002077 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002078 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002079" call Decho("read via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002080" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
2081 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 +00002082 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002086 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002088 elseif b:netrw_method == 8
Bram Moolenaar9964e462007-05-05 17:54:07 +00002089" call Decho("read via fetch (method #8)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002091 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002092 keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002093 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002094" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002095 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002097 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 let netrw_option= "http"
2099 else
2100 let netrw_option= "ftp"
2101 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002102" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002103
Bram Moolenaar446cb832008-06-24 21:56:24 +00002104 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002105" 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))
2106 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 +00002107 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00002108" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
2109 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 +00002110 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002111
Bram Moolenaar446cb832008-06-24 21:56:24 +00002112 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01002114" call Decho("setl ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02002115 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002116
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002118 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002119 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120" call Decho("read via sftp (method #9)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002121" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
2122 exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00002123 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002125
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002126 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002127 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002128 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002129 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 endif
2131 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002132
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 if exists("b:netrw_method")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002135" call Decho("cleanup b:netrw_method and b:netrw_fname")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 unlet b:netrw_fname
2138 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002139 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 +00002140" call Decho("cleanup by deleting tmpfile<".tmpfile.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002141 keepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002142 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002143 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002144
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002146endfun
2147
2148" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002149" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002150fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002151" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002152
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002155 call s:NetrwOptionSave("w:")
2156 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002157
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002159 let tmpfile= s:GetTempfile("")
2160 if tmpfile == ""
2161" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002162 return
2163 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002164
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 if a:0 == 0
2166 let ichoice = 0
2167 else
2168 let ichoice = 1
2169 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002170
Bram Moolenaar9964e462007-05-05 17:54:07 +00002171 let curbufname= expand("%")
2172" call Decho("curbufname<".curbufname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002173 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002174 " For binary writes, always write entire file.
2175 " (line numbers don't really make sense for that).
2176 " Also supports the writing of tar and zip files.
Bram Moolenaaradc21822011-04-01 18:03:16 +02002177" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
2178 exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002179 elseif g:netrw_cygwin
2180 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002181 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002182" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002183 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002184 else
2185 " write (selected portion of) file to temporary
Bram Moolenaaradc21822011-04-01 18:03:16 +02002186" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002187 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002188 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002189
Bram Moolenaar9964e462007-05-05 17:54:07 +00002190 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002191 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002192 " on the temporary file's name. Deletion of the temporary file during
2193 " cleanup then causes an error message.
2194 0file!
2195 endif
2196
Bram Moolenaar5c736222010-01-06 20:54:52 +01002197 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002198 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002199
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 " attempt to repeat with previous host-file-etc
2202 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002203" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 let choice = b:netrw_lastfile
2205 let ichoice= ichoice + 1
2206 else
2207 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002208
Bram Moolenaar8d043172014-01-23 14:24:41 +01002209 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002211 echomsg 'NetWrite Usage:"'
2212 echomsg ':Nwrite machine:path uses rcp'
2213 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2214 echomsg ':Nwrite "machine id password path" uses ftp'
2215 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2216 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2217 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2218 echomsg ':Nwrite rcp://machine/path uses rcp'
2219 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2220 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2221 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002222 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 elseif match(choice,"^\"") != -1
2226 if match(choice,"\"$") != -1
2227 " case "..."
2228 let choice=strpart(choice,1,strlen(choice)-2)
2229 else
2230 " case "... ... ..."
2231 let choice = strpart(choice,1,strlen(choice)-1)
2232 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 while match(choice,"\"$") == -1
2235 let wholechoice= wholechoice . " " . choice
2236 let ichoice = ichoice + 1
2237 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002238 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002239 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002240 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002241" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 return
2243 endif
2244 let choice= a:{ichoice}
2245 endwhile
2246 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2247 endif
2248 endif
2249 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 let ichoice= ichoice + 1
Bram Moolenaar9964e462007-05-05 17:54:07 +00002251" call Decho("choice<" . choice . "> ichoice=".ichoice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaar9964e462007-05-05 17:54:07 +00002253 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaaradc21822011-04-01 18:03:16 +02002254 keepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002255 if !exists("b:netrw_method") || b:netrw_method < 0
2256" call Dfunc("netrw#NetWrite : unsupported method")
2257 return
2258 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002259
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002261 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002262 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002263 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2264 echo "(netrw) Processing your write request..."
Bram Moolenaar446cb832008-06-24 21:56:24 +00002265" call Decho("(netrw) Processing your write request...")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002266 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002267
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002269 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002270 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002271" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 if s:netrw_has_nt_rcp == 1
2273 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2274 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2275 else
2276 let uid_machine = g:netrw_machine .'.'. $USERNAME
2277 endif
2278 else
2279 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2280 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2281 else
2282 let uid_machine = g:netrw_machine
2283 endif
2284 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00002285" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
2286 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 +00002287 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002291 elseif b:netrw_method == 2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002292" call Decho("write via ftp+.netrc (method #2)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002293 let netrw_fname = b:netrw_fname
2294
2295 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2296 let bhkeep = &l:bh
2297 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002298 setl bh=hide
2299 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002300
Bram Moolenaar446cb832008-06-24 21:56:24 +00002301" call Decho("filter input window#".winnr())
Bram Moolenaarff034192013-04-24 18:51:19 +02002302 setl ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002303 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002304" call Decho("filter input: ".getline('$'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002305 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002306 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002307" call Decho("filter input: ".getline("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002309 keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002310" call Decho("filter input: ".getline("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02002312" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
2313 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00002315" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02002316" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
2317 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 endif
2319 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2320 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002321 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002322 keepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002323 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002326
2327 " remove enew buffer (quietly)
2328 let filtbuf= bufnr("%")
2329 exe curbuf."b!"
2330 let &l:bh = bhkeep
2331 exe filtbuf."bw!"
2332
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002334
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002336 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002337 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002338 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaar9964e462007-05-05 17:54:07 +00002339" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002340 let netrw_fname = b:netrw_fname
2341 let bhkeep = &l:bh
2342
2343 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2344 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002345 setl bh=hide
2346 keepalt enew
2347 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002349 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002350 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00002351" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002352 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002353 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00002354" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002355 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002356 if exists("g:netrw_uid") && g:netrw_uid != ""
2357 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2358 keepj put =g:netrw_uid
2359" call Decho("filter input: ".getline('.'))
2360 if exists("s:netrw_passwd") && s:netrw_passwd != ""
2361 keepj put ='\"'.s:netrw_passwd.'\"'
2362 endif
2363" call Decho("filter input: ".getline('.'))
2364 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
2365 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
2366" call Decho("filter input: ".getline('.'))
2367 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002369 keepj put =g:netrw_ftpmode
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370" call Decho("filter input: ".getline('$'))
2371 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002372 keepj put =g:netrw_ftpextracmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373" call Decho("filter input: ".getline("$"))
2374 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002375 keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002376" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 " save choice/id/password for future use
2378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 " perform ftp:
2381 " -i : turns off interactive prompting from ftp
2382 " -n unix : DON'T use <.netrc>, even though it exists
2383 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002384 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002385" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
2386 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2388 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002389 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002390 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002391 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 let mod=1
2393 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002394
2395 " remove enew buffer (quietly)
2396 let filtbuf= bufnr("%")
2397 exe curbuf."b!"
2398 let &l:bh= bhkeep
2399 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002400
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002402 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002403 elseif b:netrw_method == 4
Bram Moolenaar9964e462007-05-05 17:54:07 +00002404" call Decho("write via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002406 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002407 else
2408 let useport= ""
2409 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00002410" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
2411 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 +00002412 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002415 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 elseif b:netrw_method == 5
Bram Moolenaar9964e462007-05-05 17:54:07 +00002417" call Decho("write via http (method #5)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002418 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2419 if executable(curl)
2420 let url= g:netrw_choice
2421" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".shellescape(tmpfile,1)." ".shellescape(url,1) )
2422 exe s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".shellescape(tmpfile,1)." ".shellescape(url,1)
2423 elseif !exists("g:netrw_quiet")
2424 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd".">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002425 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002426
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002428 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002429 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002430" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002431
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2434 let bhkeep = &l:bh
2435
2436 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2437 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002438 setl bh=hide
2439 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002440
Bram Moolenaarff034192013-04-24 18:51:19 +02002441 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002443 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002445 keepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002447 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002448 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002449 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002450 keepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002451
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002453 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002454" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002455 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002456
2457 " remove enew buffer (quietly)
2458 let filtbuf= bufnr("%")
2459 exe curbuf."b!"
2460 let &l:bh = bhkeep
2461 exe filtbuf."bw!"
2462
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002466 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002467 elseif b:netrw_method == 7
Bram Moolenaar9964e462007-05-05 17:54:07 +00002468" call Decho("write via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002469" call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
2470 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 +00002471 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002473 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002474 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002475 elseif b:netrw_method == 9
Bram Moolenaar97d62492012-11-15 21:28:22 +01002476" call Decho("write via sftp (method #9)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002477 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2479 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2480 else
2481 let uid_machine = g:netrw_machine
2482 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002483
2484 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2485 let bhkeep = &l:bh
2486 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002487 setl bh=hide
2488 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002489
Bram Moolenaarff034192013-04-24 18:51:19 +02002490 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002491 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002492" call Decho("filter input: ".getline('.'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002493" call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002494 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
2495 exe s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002496 let filtbuf= bufnr("%")
2497 exe curbuf."b!"
2498 let &l:bh = bhkeep
2499 exe filtbuf."bw!"
2500 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002501
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002503 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002504 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002505 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002506 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002509
Bram Moolenaar5c736222010-01-06 20:54:52 +01002510 " NetWrite: Cleanup: {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002511" call Decho("cleanup")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002512 if s:FileReadable(tmpfile)
2513" call Decho("tmpfile<".tmpfile."> readable, will now delete it")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002514 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002515 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002516 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002517
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002519 " restore modifiability; usually equivalent to set nomod
2520 let &mod= mod
Bram Moolenaara6878372014-03-22 21:02:50 +01002521" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002522 elseif !exists("leavemod")
2523 " indicate that the buffer has not been modified since last written
Bram Moolenaara6878372014-03-22 21:02:50 +01002524" call Decho("set nomod")
2525 setl nomod
2526" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaar9964e462007-05-05 17:54:07 +00002529" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530endfun
2531
2532" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002533" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002534" uses NetRead to get a copy of the file into a temporarily file,
2535" then sources that file,
2536" then removes that file.
2537fun! netrw#NetSource(...)
2538" call Dfunc("netrw#NetSource() a:0=".a:0)
2539 if a:0 > 0 && a:1 == '?'
2540 " give help
2541 echomsg 'NetSource Usage:'
2542 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2543 echomsg ':Nsource fetch://machine/path uses fetch'
2544 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002545 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002546 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2547 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2548 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2549 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2550 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002551 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002552 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002553 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002554 call netrw#NetRead(3,a:{i})
Bram Moolenaara6878372014-03-22 21:02:50 +01002555" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002557" call Decho("exe so ".fnameescape(s:netrw_tmpfile))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002558 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002559" call Decho("delete(".s:netrw_tmpfile.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002560 call delete(s:netrw_tmpfile)
2561 unlet s:netrw_tmpfile
2562 else
2563 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2564 endif
2565 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002566 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002567 endif
2568" call Dret("netrw#NetSource")
2569endfun
2570
Bram Moolenaar8d043172014-01-23 14:24:41 +01002571" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002572" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2573" (implements the :Ntree command)
2574fun! netrw#SetTreetop(...)
2575" call Dfunc("netrw#SetTreetop(".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2576
Bram Moolenaar8d043172014-01-23 14:24:41 +01002577 " clear out the current tree
2578 if exists("w:netrw_treetop")
Bram Moolenaara6878372014-03-22 21:02:50 +01002579" call Decho("clearing out current tree")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002580 let inittreetop= w:netrw_treetop
2581 unlet w:netrw_treetop
2582 endif
2583 if exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01002584" call Decho("freeing w:netrw_treedict")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002585 unlet w:netrw_treedict
2586 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002587
2588 if a:1 == "" && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002589 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01002590" call Decho("treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002591 else
2592 if isdirectory(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01002593" call Decho("a:1<".a:1."> is a directory")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002594 let treedir= a:1
2595 elseif exists("b:netrw_curdir") && isdirectory(b:netrw_curdir."/".a:1)
2596 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01002597" call Decho("a:1<".a:1."> is NOT a directory, trying treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002598 else
2599 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara6878372014-03-22 21:02:50 +01002600 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002601 endif
2602 endif
2603" call Decho("treedir<".treedir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002604 let islocal= expand("%") !~ '^\a\+://'
2605" call Decho("islocal=".islocal)
2606 if islocal
2607 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2608 else
2609 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2610 endif
2611" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002612endfun
2613
Bram Moolenaar9964e462007-05-05 17:54:07 +00002614" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002615" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002616" readcmd == %r : replace buffer with newly read file
2617" == 0r : read file at top of buffer
2618" == r : read file after current line
2619" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002620fun! s:NetrwGetFile(readcmd, tfile, method)
2621" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002622
2623 " readcmd=='t': simply do nothing
2624 if a:readcmd == 't'
Bram Moolenaara6878372014-03-22 21:02:50 +01002625" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002626" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002627 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002628 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002629
Bram Moolenaar9964e462007-05-05 17:54:07 +00002630 " get name of remote filename (ie. url and all)
2631 let rfile= bufname("%")
2632" call Decho("rfile<".rfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002633
Bram Moolenaar9964e462007-05-05 17:54:07 +00002634 if exists("*NetReadFixup")
2635 " for the use of NetReadFixup (not otherwise used internally)
2636 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002637 endif
2638
Bram Moolenaar9964e462007-05-05 17:54:07 +00002639 if a:readcmd[0] == '%'
2640 " get file into buffer
2641" call Decho("get file into buffer")
2642
2643 " rename the current buffer to the temp file (ie. tfile)
2644 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002645 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002646 else
2647 let tfile= a:tfile
2648 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002649" call Decho("exe sil! keepalt file ".fnameescape(tfile))
2650 exe "sil! keepalt file ".fnameescape(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002651
2652 " edit temporary file (ie. read the temporary file in)
2653 if rfile =~ '\.zip$'
2654" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
2655 call zip#Browse(tfile)
2656 elseif rfile =~ '\.tar$'
2657" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
2658 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002659 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002660" call Decho("handling remote gzip-compressed tar file")
2661 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002662 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002663" call Decho("handling remote bz2-compressed tar file")
2664 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002665 elseif rfile =~ '\.tar\.xz$'
2666" call Decho("handling remote xz-compressed tar file")
2667 call tar#Browse(tfile)
2668 elseif rfile =~ '\.txz$'
2669" call Decho("handling remote xz-compressed tar file (.txz)")
2670 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002671 else
2672" call Decho("edit temporary file")
2673 e!
2674 endif
2675
2676 " rename buffer back to remote filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002677" call Decho("exe sil! keepalt file ".fnameescape(rfile))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002678 exe "sil! keepj keepalt file ".fnameescape(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002679
Bram Moolenaar97d62492012-11-15 21:28:22 +01002680 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002681 " Note that isk must not include a "/" for scripts.vim
2682 " to process this detection correctly.
2683" call Decho("detect filetype of local version of remote file")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002684 let iskkeep= &l:isk
2685 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002686 let &l:isk= iskkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00002687" call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
2688 let line1 = 1
2689 let line2 = line("$")
2690
Bram Moolenaar8d043172014-01-23 14:24:41 +01002691 elseif !&ma
2692 " attempting to read a file after the current line in the file, but the buffer is not modifiable
2693 keepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
2694" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
2695 return
2696
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 elseif s:FileReadable(a:tfile)
2698 " read file after current line
2699" call Decho("read file<".a:tfile."> after current line")
2700 let curline = line(".")
2701 let lastline= line("$")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002702" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002703 exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002704 let line1= curline + 1
2705 let line2= line("$") - lastline + 1
2706
2707 else
2708 " not readable
Bram Moolenaara6878372014-03-22 21:02:50 +01002709" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002710" call Decho("tfile<".a:tfile."> not readable")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002711 keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002712" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002713 return
2714 endif
2715
2716 " User-provided (ie. optional) fix-it-up command
2717 if exists("*NetReadFixup")
2718" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002719 keepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002720" else " Decho
2721" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
2722 endif
2723
Bram Moolenaaradc21822011-04-01 18:03:16 +02002724 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002725 " update the Buffers menu
Bram Moolenaaradc21822011-04-01 18:03:16 +02002726 keepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002727 endif
2728
2729" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
2730
2731 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002732" redraw!
2733
Bram Moolenaara6878372014-03-22 21:02:50 +01002734" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002735" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002736endfun
2737
Bram Moolenaar9964e462007-05-05 17:54:07 +00002738" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002739" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002740" Input:
2741" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2742" Output:
2743" b:netrw_method= 1: rcp
2744" 2: ftp + <.netrc>
2745" 3: ftp + machine, id, password, and [path]filename
2746" 4: scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002747" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002748" 6: dav
2749" 7: rsync
2750" 8: fetch
2751" 9: sftp
2752" g:netrw_machine= hostname
2753" b:netrw_fname = filename
2754" g:netrw_port = optional port number (for ftp)
2755" g:netrw_choice = copy of input url (choice)
2756fun! s:NetrwMethod(choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002757" call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002758
Bram Moolenaar251e1912011-06-19 05:09:16 +02002759 " sanity check: choice should have at least three slashes in it
2760 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2761 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2762 let b:netrw_method = -1
2763" call Dret("NetrwMethod : incorrect url format<".a:choice.">")
2764 return
2765 endif
2766
Bram Moolenaar5c736222010-01-06 20:54:52 +01002767 " record current g:netrw_machine, if any
2768 " curmachine used if protocol == ftp and no .netrc
2769 if exists("g:netrw_machine")
2770 let curmachine= g:netrw_machine
2771" call Decho("curmachine<".curmachine.">")
2772 else
2773 let curmachine= "N O T A HOST"
2774 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002775 if exists("g:netrw_port")
2776 let netrw_port= g:netrw_port
2777 endif
2778
2779 " insure that netrw_ftp_cmd starts off every method determination
2780 " with the current g:netrw_ftp_cmd
2781 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002783 " initialization
2784 let b:netrw_method = 0
2785 let g:netrw_machine = ""
2786 let b:netrw_fname = ""
2787 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002788 let g:netrw_choice = a:choice
2789
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002790 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002791 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002792 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2793 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002794 " rcpurm : rcp://[user@]host/filename Use rcp
2795 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002796 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002797 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002799 " rsyncurm : rsync://host[:port]/path Use rsync
2800 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2801 " sftpurm : sftp://[user@]host/filename Use scp
2802 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2803 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002804" let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2805" let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
2806" let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
2807 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2808 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002809 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002810 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002811 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002812 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002813 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002814 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002815 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002816
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002817" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002818 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002819 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002820 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002821" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002822 let b:netrw_method = 1
2823 let userid = substitute(a:choice,rcpurm,'\1',"")
2824 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2825 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002826 if userid != ""
2827 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002829
Bram Moolenaaradc21822011-04-01 18:03:16 +02002830 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002831 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002832" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002833 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002834 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2835 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2836 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002837
Bram Moolenaar15146672011-10-20 22:22:38 +02002838 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002839 elseif match(a:choice,httpurm) == 0
Bram Moolenaara6878372014-03-22 21:02:50 +01002840" call Decho("http[s]://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002841 let b:netrw_method = 5
2842 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
2843 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01002844 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002845
Bram Moolenaaradc21822011-04-01 18:03:16 +02002846 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002847 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002848" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002849 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02002850 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002851 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
2852 else
2853 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
2854 endif
2855 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002856
Bram Moolenaaradc21822011-04-01 18:03:16 +02002857 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002858 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002859" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002860 let b:netrw_method = 7
2861 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
2862 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002863
Bram Moolenaaradc21822011-04-01 18:03:16 +02002864 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002865 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002866" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002867 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002868 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
2869 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
2870 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002871" call Decho("g:netrw_machine<".g:netrw_machine.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002872 if userid != ""
2873 let g:netrw_uid= userid
2874 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002875
Bram Moolenaaradc21822011-04-01 18:03:16 +02002876 if curmachine != g:netrw_machine
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002877 if exists("s:netwr_hup[".g:netrw_machine."]")
2878 call NetUserPass("ftp:".g:netrw_machine)
2879 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002880 " if there's a change in hostname, require password re-entry
2881 unlet s:netrw_passwd
2882 endif
2883 if exists("netrw_port")
2884 unlet netrw_port
2885 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002886 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002887
Bram Moolenaar446cb832008-06-24 21:56:24 +00002888 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002889 let b:netrw_method = 3
2890 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002891 let host= substitute(g:netrw_machine,'\..*$','','')
2892 if exists("s:netrw_hup[host]")
2893 call NetUserPass("ftp:".host)
2894
2895 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
Bram Moolenaaradc21822011-04-01 18:03:16 +02002896" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
2897" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
2898 if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002899 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002900" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
2901 endif
2902 let b:netrw_method= 2
2903 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
2904" call Decho("using <".expand("$HOME/.netrc")."> (readable)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002905 let b:netrw_method= 2
2906 else
2907 if !exists("g:netrw_uid") || g:netrw_uid == ""
2908 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002909 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002910 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002911 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002912 endif
2913 let b:netrw_method= 3
2914 endif
2915 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002916
Bram Moolenaaradc21822011-04-01 18:03:16 +02002917 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002918 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002919" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002920 let b:netrw_method = 8
2921 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
2922 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
2923 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
2924 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002925
Bram Moolenaaradc21822011-04-01 18:03:16 +02002926 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002927 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002928" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002930 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
2931 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002933 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002934 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002935
Bram Moolenaaradc21822011-04-01 18:03:16 +02002936 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002937 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002938" call Decho("(ftp) host file")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002939 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002940 let b:netrw_method = 3
2941 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
2942 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002945 let b:netrw_method = 2
2946 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
2947 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
2948 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949
Bram Moolenaaradc21822011-04-01 18:03:16 +02002950 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002951 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002952" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002953 let b:netrw_method = 9
2954 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
2955 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002956
Bram Moolenaaradc21822011-04-01 18:03:16 +02002957 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002958 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002959" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002960 let b:netrw_method = 1
2961 let userid = substitute(a:choice,rcphf,'\2',"")
2962 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
2963 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002964" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
2965" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
2966" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
2967" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002968 if userid != ""
2969 let g:netrw_uid= userid
2970 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002971
Bram Moolenaaradc21822011-04-01 18:03:16 +02002972 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002973 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002974 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002975 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002976 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002977 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002979 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00002980
Bram Moolenaar81695252004-12-29 20:58:21 +00002981 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02002982 " remove any leading [:#] from port number
2983 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
2984 elseif exists("netrw_port")
2985 " retain port number as implicit for subsequent ftp operations
2986 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00002987 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002988
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002989" call Decho("a:choice <".a:choice.">")
2990" call Decho("b:netrw_method <".b:netrw_method.">")
2991" call Decho("g:netrw_machine<".g:netrw_machine.">")
2992" call Decho("g:netrw_port <".g:netrw_port.">")
2993" if exists("g:netrw_uid") "Decho
2994" call Decho("g:netrw_uid <".g:netrw_uid.">")
2995" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00002996" if exists("s:netrw_passwd") "Decho
2997" call Decho("s:netrw_passwd <".s:netrw_passwd.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002998" endif "Decho
2999" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003000" call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002
3003" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003004" NetReadFixup: this sort of function is typically written by the user {{{2
3005" to handle extra junk that their system's ftp dumps
3006" into the transfer. This function is provided as an
3007" example and as a fix for a Windows 95 problem: in my
3008" experience, win95's ftp always dumped four blank lines
3009" at the end of the transfer.
3010if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3011 fun! NetReadFixup(method, line1, line2)
3012" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003013
3014 " sanity checks -- attempt to convert inputs to integers
3015 let method = a:method + 0
3016 let line1 = a:line1 + 0
3017 let line2 = a:line2 + 0
3018 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3019" call Dret("NetReadFixup")
3020 return
3021 endif
3022
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023 if method == 3 " ftp (no <.netrc>)
3024 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003025 if fourblanklines >= line1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003026 exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003027 call histdel("/",-1)
3028 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003030
Bram Moolenaar9964e462007-05-05 17:54:07 +00003031" call Dret("NetReadFixup")
3032 endfun
3033endif
3034
3035" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003036" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003037" Usage: :call NetUserPass() -- will prompt for userid and password
3038" :call NetUserPass("uid") -- will prompt for password
3039" :call NetUserPass("uid","password") -- sets global userid and password
3040" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3041" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042fun! NetUserPass(...)
3043
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003044" call Dfunc("NetUserPass() a:0=".a:0)
3045
3046 if !exists('s:netrw_hup')
3047 let s:netrw_hup= {}
3048 endif
3049
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003051 " case: no input arguments
3052
3053 " change host and username if not previously entered; get new password
3054 if !exists("g:netrw_machine")
3055 let g:netrw_machine= input('Enter hostname: ')
3056 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003058 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 let g:netrw_uid= input('Enter username: ')
3060 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003061 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003062 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003063
3064 " set up hup database
3065 let host = substitute(g:netrw_machine,'\..*$','','')
3066 if !exists('s:netrw_hup[host]')
3067 let s:netrw_hup[host]= {}
3068 endif
3069 let s:netrw_hup[host].uid = g:netrw_uid
3070 let s:netrw_hup[host].passwd = s:netrw_passwd
3071
3072 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003073 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003074
3075 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003076 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003077 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara6878372014-03-22 21:02:50 +01003078" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003079 let host = substitute(a:1,'^ftp:','','')
3080 let host = substitute(host,'\..*','','')
3081 if exists("s:netrw_hup[host]")
3082 let g:netrw_uid = s:netrw_hup[host].uid
3083 let s:netrw_passwd = s:netrw_hup[host].passwd
3084" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3085" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
3086 else
3087 let g:netrw_uid = input("Enter UserId: ")
3088 let s:netrw_passwd = inputsecret("Enter Password: ")
3089 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003090
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003091 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003092 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara6878372014-03-22 21:02:50 +01003093" call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003094 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003095 if g:netrw_machine =~ '[0-9.]\+'
3096 let host= g:netrw_machine
3097 else
3098 let host= substitute(g:netrw_machine,'\..*$','','')
3099 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003100 else
3101 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003102 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003103 let g:netrw_uid = a:1
3104" call Decho("set g:netrw_uid= <".g:netrw_uid.">")
3105 if exists("g:netrw_passwd")
3106 " ask for password if one not previously entered
3107 let s:netrw_passwd= g:netrw_passwd
3108 else
3109 let s:netrw_passwd = inputsecret("Enter Password: ")
3110 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003111 endif
3112
3113" call Decho("host<".host.">")
3114 if exists("host")
3115 if !exists('s:netrw_hup[host]')
3116 let s:netrw_hup[host]= {}
3117 endif
3118 let s:netrw_hup[host].uid = g:netrw_uid
3119 let s:netrw_hup[host].passwd = s:netrw_passwd
3120 endif
3121
3122 elseif a:0 == 2
3123 let g:netrw_uid = a:1
3124 let s:netrw_passwd = a:2
3125
3126 elseif a:0 == 3
3127 " enter hostname, user-id, and password into the hup dictionary
3128 let host = substitute(a:1,'^\a\+:','','')
3129 let host = substitute(host,'\..*$','','')
3130 if !exists('s:netrw_hup[host]')
3131 let s:netrw_hup[host]= {}
3132 endif
3133 let s:netrw_hup[host].uid = a:2
3134 let s:netrw_hup[host].passwd = a:3
3135 let g:netrw_uid = s:netrw_hup[host].uid
3136 let s:netrw_passwd = s:netrw_hup[host].passwd
3137" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3138" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003140
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003141" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143
Bram Moolenaar9964e462007-05-05 17:54:07 +00003144" ===========================================
3145" Shared Browsing Support: {{{1
3146" ===========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003148" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003149" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3150fun! s:ExplorePatHls(pattern)
3151" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3152 let repat= substitute(a:pattern,'^**/\{1,2}','','')
3153" call Decho("repat<".repat.">")
3154 let repat= escape(repat,'][.\')
3155" call Decho("repat<".repat.">")
3156 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3157" call Dret("s:ExplorePatHls repat<".repat.">")
3158 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003159endfun
3160
3161" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003162" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003163" 0: (user: <mb>) bookmark current directory
3164" 1: (user: <gb>) change to the bookmarked directory
3165" 2: (user: <qb>) list bookmarks
3166" 3: (browsing) record current directory history
3167" 4: (user: <u>) go up (previous) bookmark
3168" 5: (user: <U>) go down (next) bookmark
3169" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003170fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003171" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003172 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3173" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3174 return
3175 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003176
Bram Moolenaar97d62492012-11-15 21:28:22 +01003177 let ykeep= @@
Bram Moolenaar9964e462007-05-05 17:54:07 +00003178 if a:chg == 0
3179 " bookmark the current directory
3180" call Decho("(user: <b>) bookmark the current directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003181 if !exists("g:netrw_bookmarklist")
3182 let g:netrw_bookmarklist= []
3183 endif
3184 if index(g:netrw_bookmarklist,a:curdir) == -1
3185 " curdir not currently in g:netrw_bookmarklist, so include it
3186 call add(g:netrw_bookmarklist,a:curdir)
3187 call sort(g:netrw_bookmarklist)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003188 endif
3189 echo "bookmarked the current directory"
3190
3191 elseif a:chg == 1
3192 " change to the bookmarked directory
Bram Moolenaarff034192013-04-24 18:51:19 +02003193" call Decho("(user: <".v:count."gb>) change to the bookmarked directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003194 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaarff034192013-04-24 18:51:19 +02003195" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003197 else
3198 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3199 endif
3200
3201 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003202" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003203 let didwork= 0
3204 " list user's bookmarks
3205" call Decho("(user: <q>) list user's bookmarks")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003206 if exists("g:netrw_bookmarklist")
3207" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
3208 let cnt= 1
3209 for bmd in g:netrw_bookmarklist
3210" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
Bram Moolenaarff034192013-04-24 18:51:19 +02003211 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003212 let didwork = 1
3213 let cnt = cnt + 1
3214 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003215 endif
3216
3217 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003218 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003219 let first = 1
3220 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003221 if g:netrw_dirhistmax > 0
3222 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaar5c736222010-01-06 20:54:52 +01003223" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003224 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003225" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt})
Bram Moolenaarff034192013-04-24 18:51:19 +02003226 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003227 let didwork= 1
3228 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003229 let histcnt = histcnt + 1
3230 let first = 0
3231 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003232 if cnt < 0
3233 let cnt= cnt + g:netrw_dirhistmax
3234 endif
3235 endwhile
3236 else
3237 let g:netrw_dirhist_cnt= 0
3238 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003239 if didwork
3240 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3241 endif
3242
3243 elseif a:chg == 3
3244 " saves most recently visited directories (when they differ)
3245" call Decho("(browsing) record curdir history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003246 if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003247 if g:netrw_dirhistmax > 0
3248 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3249 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
3250 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003251" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003252 endif
3253
3254 elseif a:chg == 4
3255 " u: change to the previous directory stored on the history list
3256" call Decho("(user: <u>) chg to prev dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003257 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003258 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003259 if g:netrw_dirhist_cnt < 0
3260 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3261 endif
3262 else
3263 let g:netrw_dirhist_cnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003264 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003265 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
3266" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003267 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003268 setl ma noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003269" call Decho("setl ma noro")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003270 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003271 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01003272" call Decho("setl nomod")
3273" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003274 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003275" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003276 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003277 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003278 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003279 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003280 else
3281 let g:netrw_dirhist_cnt= 0
3282 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003283 echo "Sorry, no predecessor directory exists yet"
3284 endif
3285
3286 elseif a:chg == 5
3287 " U: change to the subsequent directory stored on the history list
3288" call Decho("(user: <U>) chg to next dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003289 if g:netrw_dirhistmax > 0
3290 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3291 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003292" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003293 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +01003294" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003295 setl ma noro
Bram Moolenaaradc21822011-04-01 18:03:16 +02003296 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003297" call Decho("removed all lines from buffer (%d)")
Bram Moolenaara6878372014-03-22 21:02:50 +01003298" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003299 setl nomod
3300" call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003302" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003303 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
3304 else
3305 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
3306 if g:netrw_dirhist_cnt < 0
3307 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3308 endif
3309 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003310 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 else
3312 let g:netrw_dirhist_cnt= 0
3313 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003314 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003315
3316 elseif a:chg == 6
Bram Moolenaar5c736222010-01-06 20:54:52 +01003317 " delete the v:count'th bookmark
3318" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
3319 let savefile= s:NetrwHome()."/.netrwbook"
3320 if filereadable(savefile)
Bram Moolenaarff034192013-04-24 18:51:19 +02003321" call Decho("merge bookmarks (active and file)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003322 keepj call s:NetrwBookHistSave() " done here to merge bookmarks first
Bram Moolenaarff034192013-04-24 18:51:19 +02003323" call Decho("bookmark delete savefile<".savefile.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003324 keepj call delete(savefile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003326" call Decho("remove g:netrw_bookmarklist[".(v:count-1)."]")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003327 keepj call remove(g:netrw_bookmarklist,v:count-1)
Bram Moolenaarff034192013-04-24 18:51:19 +02003328" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003329 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003330 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003331 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003332 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003333" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003334endfun
3335
3336" ---------------------------------------------------------------------
3337" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
3338" Sister function: s:NetrwBookHistSave()
3339fun! s:NetrwBookHistRead()
3340" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003341 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3342" " call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
3343 return
3344 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003346 if !exists("s:netrw_initbookhist")
3347 let home = s:NetrwHome()
3348 let savefile= home."/.netrwbook"
3349 if filereadable(savefile)
3350" call Decho("sourcing .netrwbook")
Bram Moolenaarff034192013-04-24 18:51:19 +02003351 exe "keepalt keepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003352 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003353 if g:netrw_dirhistmax > 0
3354 let savefile= home."/.netrwhist"
3355 if filereadable(savefile)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003356" call Decho("sourcing .netrwhist")
Bram Moolenaarff034192013-04-24 18:51:19 +02003357 exe "keepalt keepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003358 endif
3359 let s:netrw_initbookhist= 1
3360 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003361 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003362 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003363 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003364" call Dret("s:NetrwBookHistRead")
3365endfun
3366
3367" ---------------------------------------------------------------------
3368" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
3369" Sister function: s:NetrwBookHistRead()
3370" I used to do this via viminfo but that appears to
3371" be unreliable for long-term storage
Bram Moolenaar5c736222010-01-06 20:54:52 +01003372fun! s:NetrwBookHistSave()
3373" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003374 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003375" call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
3376 return
3377 endif
3378
Bram Moolenaar5c736222010-01-06 20:54:52 +01003379 let savefile= s:NetrwHome()."/.netrwhist"
3380 1split
3381 call s:NetrwEnew()
Bram Moolenaarff034192013-04-24 18:51:19 +02003382 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3383 setl nocin noai noci magic nospell nohid wig= noaw
3384 setl ma noro write
3385 if exists("+acd") | setl noacd | endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003386 sil! keepj keepalt %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003387
3388 " save .netrwhist -- no attempt to merge
Bram Moolenaarff034192013-04-24 18:51:19 +02003389 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003390 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
3391 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
3392 let lastline = line("$")
3393 let cnt = 1
3394 while cnt <= g:netrw_dirhist_cnt
3395 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3396 let cnt= cnt + 1
3397 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003398 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003399
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003400 sil keepj %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003401 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
3402 " merge and write .netrwbook
3403 let savefile= s:NetrwHome()."/.netrwbook"
3404
3405 if filereadable(savefile)
3406 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaarff034192013-04-24 18:51:19 +02003407 exe "sil keepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003408 for bdm in booklist
3409 if index(g:netrw_bookmarklist,bdm) == -1
3410 call add(g:netrw_bookmarklist,bdm)
3411 endif
3412 endfor
3413 call sort(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003414 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003415 endif
3416
3417 " construct and save .netrwbook
3418 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003419 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003420 endif
3421 let bgone= bufnr("%")
3422 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003423 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003424
3425" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003426endfun
3427
3428" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003429" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3430" list of the contents of a local or remote directory. It is assumed that the
3431" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3432" with the requested remote hostname first.
3433fun! s:NetrwBrowse(islocal,dirname)
3434 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003435" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01003436" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003437" call Dredir("ls!")
Bram Moolenaara6878372014-03-22 21:02:50 +01003438
Bram Moolenaar97d62492012-11-15 21:28:22 +01003439 " s:NetrwBrowse: initialize history {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003440 if !exists("s:netrw_initbookhist")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003441 keepj call s:NetrwBookHistRead()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003442 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003443
Bram Moolenaar97d62492012-11-15 21:28:22 +01003444 " s:NetrwBrowse: simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003445 if a:dirname !~ '^\a\+://'
3446 let dirname= simplify(a:dirname)
3447 else
3448 let dirname= a:dirname
3449 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003450
3451 if exists("s:netrw_skipbrowse")
3452 unlet s:netrw_skipbrowse
Bram Moolenaara6878372014-03-22 21:02:50 +01003453" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">")
3454" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003455 return
3456 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003457
3458 " s:NetrwBrowse: sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003459 if !exists("*shellescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003460 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003461" call Dret("s:NetrwBrowse : missing shellescape()")
3462 return
3463 endif
3464 if !exists("*fnameescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003465 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003466" call Dret("s:NetrwBrowse : missing fnameescape()")
3467 return
3468 endif
3469
Bram Moolenaar97d62492012-11-15 21:28:22 +01003470 " s:NetrwBrowse: save options: {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003471 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003472
Bram Moolenaar97d62492012-11-15 21:28:22 +01003473 " s:NetrwBrowse: re-instate any marked files {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003474 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01003475" call Decho("clearing marked files")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003476 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3477 endif
3478
3479 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar97d62492012-11-15 21:28:22 +01003480 " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003481" call Decho("handle w:netrw_acdkeep:")
3482" call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
3483 call s:NetrwLcd(dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003484 call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01003485" call Decho("getcwd<".getcwd().">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003486
Bram Moolenaar5c736222010-01-06 20:54:52 +01003487 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003488 " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003489" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003490
Bram Moolenaar97d62492012-11-15 21:28:22 +01003491 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003492 " "this is a directory" indicator (/).
3493 " There shouldn't be one of those here, anyway.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003494 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01003495" call Decho("new path<".path.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003496 call s:RemotePathAnalysis(dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003497
Bram Moolenaar97d62492012-11-15 21:28:22 +01003498 " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003499 keepj mark '
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500 call s:NetrwEnew(dirname)
3501 call s:NetrwSafeOptions()
Bram Moolenaarff034192013-04-24 18:51:19 +02003502 setl ma noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003503" call Decho("setl ma noro")
Bram Moolenaar15146672011-10-20 22:22:38 +02003504 let b:netrw_curdir = dirname
3505 let url = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaara6878372014-03-22 21:02:50 +01003506" call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
Bram Moolenaar15146672011-10-20 22:22:38 +02003507 exe "sil! keepj keepalt file ".fnameescape(url)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003508 exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02003509 sil call netrw#NetRead(2,url)
Bram Moolenaara6878372014-03-22 21:02:50 +01003510 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
3511" call Decho("url<".url.">")
3512" call Decho("s:path<".s:path.">")
3513" call Decho("s:fname<".s:fname.">")
3514 if s:path =~ '.bz2'
3515 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3516 elseif s:path =~ '.gz'
3517 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3518 elseif s:path =~ '.gz'
3519 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3520 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003522 endif
3523
Bram Moolenaar97d62492012-11-15 21:28:22 +01003524 " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003525 call s:SetBufWinVars()
3526 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003527" call Decho("setl ma nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003528 setl ma nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01003529" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003530
Bram Moolenaar446cb832008-06-24 21:56:24 +00003531" call Dret("s:NetrwBrowse : file<".s:fname.">")
3532 return
3533 endif
3534
Bram Moolenaaradc21822011-04-01 18:03:16 +02003535 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003536 call s:UseBufWinVars()
3537
3538 " set up some variables {{{3
3539 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003541 let s:last_sort_by = g:netrw_sort_by
3542
3543 " set up menu {{{3
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 keepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003545
Bram Moolenaar97d62492012-11-15 21:28:22 +01003546 " get/set-up buffer {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003547 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
3548 " maintain markfile highlighting
3549 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaara6878372014-03-22 21:02:50 +01003550" call Decho("bufnr(%)=".bufnr('%'))
3551" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003552 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3553 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003554" call Decho("2match none")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003555 2match none
3556 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003557 if reusing && line("$") > 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003558 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003559" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003560 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003561" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003562" call Dret("s:NetrwBrowse : re-using buffer")
3563 return
3564 endif
3565
3566 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003567" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003568 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003569 if b:netrw_curdir =~ '[/\\]$'
3570 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3571 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003572 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3573 let b:netrw_curdir= b:netrw_curdir."/"
3574 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003575 if b:netrw_curdir == ''
3576 if has("amiga")
3577 " On the Amiga, the empty string connotes the current directory
3578 let b:netrw_curdir= getcwd()
3579 else
3580 " under unix, when the root directory is encountered, the result
3581 " from the preceding substitute is an empty string.
3582 let b:netrw_curdir= '/'
3583 endif
3584 endif
3585 if !a:islocal && b:netrw_curdir !~ '/$'
3586 let b:netrw_curdir= b:netrw_curdir.'/'
3587 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003588" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003589
3590 " ------------
3591 " (local only) {{{3
3592 " ------------
3593 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01003594" call Decho("local only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003595
3596 " Set up ShellCmdPost handling. Append current buffer to browselist
3597 call s:LocalFastBrowser()
3598
3599 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3600 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003601" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
3602" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003603 if !exists("&l:acd") || !&l:acd
Bram Moolenaara6878372014-03-22 21:02:50 +01003604 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003605 endif
3606 endif
3607
3608 " --------------------------------
3609 " remote handling: {{{3
3610 " --------------------------------
3611 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003612" call Decho("remote only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003613
Bram Moolenaar97d62492012-11-15 21:28:22 +01003614 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003615" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003616 if dirname =~ "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003617 let dirname= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003618" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003619 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3620 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3621 if dirname !~ '/$'
3622 let dirname= dirname.'/'
3623 endif
3624 let b:netrw_curdir = dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003625" call Decho("(liststyle is TREELIST) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003626 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003627 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara6878372014-03-22 21:02:50 +01003628" call Decho("(normal) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003629 endif
3630
3631 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3632 if dirname !~ dirpat
3633 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003634 keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003635 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003636 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003637" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003638 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003639" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003640" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3641 return
3642 endif
3643 let b:netrw_curdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003644" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003645 endif " (additional remote handling)
3646
3647 " -----------------------
3648 " Directory Listing: {{{3
3649 " -----------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02003650 keepj call s:NetrwMaps(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003651 keepj call s:NetrwCommands(a:islocal)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003652 keepj call s:PerformListing(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02003653 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003654 let &l:bexpr= "netrw#BalloonHelp()"
3655" call Decho("set up balloon help: l:bexpr=".&l:bexpr)
3656 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003657 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003658 call s:NetrwOptionRestore("w:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003659
Bram Moolenaara6878372014-03-22 21:02:50 +01003660 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003661 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
Bram Moolenaara6878372014-03-22 21:02:50 +01003662 " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003663
Bram Moolenaara6878372014-03-22 21:02:50 +01003664" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003665" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003666 return
3667endfun
3668
3669" ---------------------------------------------------------------------
3670" s:NetrwFileInfo: supports qf (query for file information) {{{2
3671fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003672" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003673 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003674 if a:islocal
3675 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003676
3677 if getline(".") == "../"
3678 echo system("/bin/ls -lsad ".shellescape(".."))
3679" call Decho("#1: echo system(/bin/ls -lsad ".shellescape(..).")")
3680
Bram Moolenaara6878372014-03-22 21:02:50 +01003681 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaar8d043172014-01-23 14:24:41 +01003682 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir))
3683" call Decho("#2: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir).")")
3684
3685 elseif exists("b:netrw_curdir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003686 if b:netrw_curdir =~ '/$'
3687 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003688" call Decho("#3: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname).")")
3689
Bram Moolenaar446cb832008-06-24 21:56:24 +00003690 else
3691 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003692" call Decho("#4: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003693 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003694
Bram Moolenaar446cb832008-06-24 21:56:24 +00003695 else
3696" call Decho('using ls '.a:fname." using cwd<".getcwd().">")
3697 echo system("/bin/ls -lsad ".shellescape(a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003698" call Decho("#5: echo system(/bin/ls -lsad ".shellescape(a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003699 endif
3700 else
3701 " use vim functions to return information about file below cursor
3702" call Decho("using vim functions to query for file info")
3703 if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
3704 let fname= substitute(a:fname,".$","","")
3705 else
3706 let fname= a:fname
3707 endif
3708 let t = getftime(fname)
3709 let sz = getfsize(fname)
3710 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))
Bram Moolenaara6878372014-03-22 21:02:50 +01003711" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003712 endif
3713 else
3714 echo "sorry, \"qf\" not supported yet for remote files"
3715 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003716 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003717" call Dret("s:NetrwFileInfo")
3718endfun
3719
3720" ---------------------------------------------------------------------
3721" s:NetrwGetBuffer: {{{2
3722" returns 0=cleared buffer
3723" 1=re-used buffer
3724fun! s:NetrwGetBuffer(islocal,dirname)
3725" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara6878372014-03-22 21:02:50 +01003726" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003727 let dirname= a:dirname
3728
3729 " re-use buffer if possible {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003730" call Decho("--re-use a buffer if possible--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003731 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3732 " find NetrwTreeList buffer if there is one
Bram Moolenaara6878372014-03-22 21:02:50 +01003733" call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003734 if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01003735" call Decho(" re-using w:netrw_treebufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003736 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003737 setl ei=all
Bram Moolenaar13600302014-05-22 18:26:40 +02003738 exe "sil! noswapfile keepalt b ".w:netrw_treebufnr
Bram Moolenaar446cb832008-06-24 21:56:24 +00003739 let &ei= eikeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01003740 setl ma
3741 sil! keepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01003742" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaarff034192013-04-24 18:51:19 +02003743" call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
3744 return 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003745 endif
3746 let bufnum= -1
Bram Moolenaara6878372014-03-22 21:02:50 +01003747" call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003748
3749 else
3750 " find buffer number of buffer named precisely the same as dirname {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003751" call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003752" call Dredir("(NetrwGetBuffer) ls!","ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003753
3754 " get dirname and associated buffer number
3755 let bufnum = bufnr(escape(dirname,'\'))
Bram Moolenaara6878372014-03-22 21:02:50 +01003756" call Decho(" find buffer<".dirname.">'s number ")
3757" call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003758
3759 if bufnum < 0 && dirname !~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 " try appending a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003761" call Decho(" try appending a trailing / to dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003762 let bufnum= bufnr(escape(dirname.'/','\'))
3763 if bufnum > 0
3764 let dirname= dirname.'/'
3765 endif
3766 endif
3767
3768 if bufnum < 0 && dirname =~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003769 " try removing a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003770" call Decho(" try removing a trailing / from dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771 let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
3772 if bufnum > 0
3773 let dirname= substitute(dirname,'/$','','')
3774 endif
3775 endif
3776
Bram Moolenaara6878372014-03-22 21:02:50 +01003777" call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches)
3779 if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
3780 " handle approximate matches
Bram Moolenaara6878372014-03-22 21:02:50 +01003781" call Decho(" handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782 let ibuf = 1
3783 let buflast = bufnr("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01003784" call Decho(" findbuf2: buflast=bufnr($)=".buflast)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785 while ibuf <= buflast
3786 let bname= substitute(bufname(ibuf),'\\','/','g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00003787 let bname= substitute(bname,'.\zs/$','','')
Bram Moolenaara6878372014-03-22 21:02:50 +01003788" call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003789 if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
3790 " bname is not empty
3791 " dirname ends with bname,
3792 " dirname doesn't start with /, so its not a absolute path
Bram Moolenaara6878372014-03-22 21:02:50 +01003793" call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794 break
3795 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003796 if bname =~ '^'.dirname.'/\=$'
3797 " bname begins with dirname
3798" call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799 break
3800 endif
3801 if dirname =~ '^'.bname.'/$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003802" call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
3803 break
3804 endif
3805 if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
3806" call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 break
3808 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003809 let ibuf= ibuf + 1
3810 endwhile
3811 if ibuf > buflast
3812 let bufnum= -1
3813 else
3814 let bufnum= ibuf
3815 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003816" call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 endif
3818 endif
3819
3820 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003821" call Decho(" get enew buffer and name it OR re-use buffer")
Bram Moolenaarff034192013-04-24 18:51:19 +02003822 sil! keepj keepalt mark '
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003824" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825 call s:NetrwEnew(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003826" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827 " name the buffer
3828 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3829 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +01003830" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831 if !exists("s:netrw_treelistnum")
3832 let s:netrw_treelistnum= 1
3833 else
3834 let s:netrw_treelistnum= s:netrw_treelistnum + 1
3835 endif
3836 let w:netrw_treebufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01003837" call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003838 exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003839 setl bt=nofile noswf
Bram Moolenaaradc21822011-04-01 18:03:16 +02003840 nnoremap <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
3841 nnoremap <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
3842 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[')<cr>
3843 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01003844" call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 else
3846" let v:errmsg= "" " Decho
3847 let escdirname= fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003848" call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003849" call Decho(' exe sil! keepalt file '.escdirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003850" let v:errmsg= "" " Decho
3851 exe 'sil! keepalt file '.escdirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003852" call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003854" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855
3856 else " Re-use the buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01003857" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003859 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860 if getline(2) =~ '^" Netrw Directory Listing'
Bram Moolenaara6878372014-03-22 21:02:50 +01003861" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
Bram Moolenaar13600302014-05-22 18:26:40 +02003862 exe "sil! noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003863 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003864" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
Bram Moolenaar13600302014-05-22 18:26:40 +02003865 exe "sil! noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866 endif
3867 if bufname("%") == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +01003868" call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003869 exe "sil! keepalt file ".fnameescape(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870 endif
3871 let &ei= eikeep
3872 if line("$") <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02003873 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003874" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003875" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
3876 return 0
3877 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
3878 keepj call s:NetrwListSettings(a:islocal)
3879 sil keepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01003880" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003881" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003882 return 0
3883 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01003884" call Decho("--re-use tree listing--")
3885" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003886 sil keepj %d
Bram Moolenaaradc21822011-04-01 18:03:16 +02003887 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003888" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003889" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003890 return 0
3891 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003892" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003893" call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 return 1
3895 endif
3896 endif
3897
3898 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
3899 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
3900 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
3901 " med 1 D H
3902 " fast 2 H H
Bram Moolenaara6878372014-03-22 21:02:50 +01003903" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 let fname= expand("%")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003905 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003906" call Decho("exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003907 exe "sil! keepj keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003908
3909 " delete all lines from buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003910" call Decho("--delete all lines from buffer--")
3911" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003912 sil! keepalt keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913
Bram Moolenaara6878372014-03-22 21:02:50 +01003914" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003915" call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916 return 0
3917endfun
3918
3919" ---------------------------------------------------------------------
3920" s:NetrwGetcwd: get the current directory. {{{2
3921" Change backslashes to forward slashes, if any.
3922" If doesc is true, escape certain troublesome characters
3923fun! s:NetrwGetcwd(doesc)
3924" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
3925 let curdir= substitute(getcwd(),'\\','/','ge')
3926 if curdir !~ '[\/]$'
3927 let curdir= curdir.'/'
3928 endif
3929 if a:doesc
3930 let curdir= fnameescape(curdir)
3931 endif
3932" call Dret("NetrwGetcwd <".curdir.">")
3933 return curdir
3934endfun
3935
3936" ---------------------------------------------------------------------
3937" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
3938fun! s:NetrwGetWord()
3939" call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol("."))
3940 call s:UseBufWinVars()
3941
3942 " insure that w:netrw_liststyle is set up
3943 if !exists("w:netrw_liststyle")
3944 if exists("g:netrw_liststyle")
3945 let w:netrw_liststyle= g:netrw_liststyle
3946 else
3947 let w:netrw_liststyle= s:THINLIST
3948 endif
3949" call Decho("w:netrw_liststyle=".w:netrw_liststyle)
3950 endif
3951
3952 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3953 " Active Banner support
3954" call Decho("active banner handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003955 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 let dirname= "./"
3957 let curline= getline('.')
3958
3959 if curline =~ '"\s*Sorted by\s'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003960 keepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961 let s:netrw_skipbrowse= 1
3962 echo 'Pressing "s" also works'
3963
3964 elseif curline =~ '"\s*Sort sequence:'
3965 let s:netrw_skipbrowse= 1
3966 echo 'Press "S" to edit sorting sequence'
3967
3968 elseif curline =~ '"\s*Quick Help:'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003969 keepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970 let s:netrw_skipbrowse= 1
3971 echo 'Pressing "?" also works'
3972
3973 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003974 keepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975 let s:netrw_skipbrowse= 1
3976 echo 'Pressing "a" also works'
3977
3978 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003979 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980 endif
3981
3982 elseif w:netrw_liststyle == s:THINLIST
3983" call Decho("thin column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003984 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 let dirname= getline('.')
3986
3987 elseif w:netrw_liststyle == s:LONGLIST
3988" call Decho("long column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003989 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
3991
3992 elseif w:netrw_liststyle == s:TREELIST
3993" call Decho("treelist handling")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003994 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995
3996 else
3997" call Decho("obtain word from wide listing")
3998 let dirname= getline('.')
3999
4000 if !exists("b:netrw_cpf")
4001 let b:netrw_cpf= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02004002 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 +01004003 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004" call Decho("computed cpf=".b:netrw_cpf)
4005 endif
4006
4007" call Decho("buf#".bufnr("%")."<".bufname("%").">")
4008 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
4009" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
4010" call Decho("1: dirname<".dirname.">")
4011 if filestart == 0
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004012 keepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013 else
4014 call cursor(line("."),filestart+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004015 keepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004016 endif
4017 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004018 let eofname= filestart + b:netrw_cpf + 1
4019 if eofname <= col("$")
4020 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004021 keepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004022 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004023 keepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004024 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 let dirname = @a
4026 let @a = rega
4027" call Decho("2: dirname<".dirname.">")
4028 let dirname= substitute(dirname,'\s\+$','','e')
4029" call Decho("3: dirname<".dirname.">")
4030 endif
4031
4032 " symlinks are indicated by a trailing "@". Remove it before further processing.
4033 let dirname= substitute(dirname,"@$","","")
4034
4035 " executables are indicated by a trailing "*". Remove it before further processing.
4036 let dirname= substitute(dirname,"\*$","","")
4037
4038" call Dret("s:NetrwGetWord <".dirname.">")
4039 return dirname
4040endfun
4041
4042" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004043" s:NetrwListSettings: make standard settings for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004044fun! s:NetrwListSettings(islocal)
4045" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01004046" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004047 let fname= bufname("%")
Bram Moolenaar13600302014-05-22 18:26:40 +02004048" " call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro nornu")
4049 setl bt=nofile nobl ma nonu nowrap noro nornu
Bram Moolenaarff034192013-04-24 18:51:19 +02004050" call Decho("(NetrwListSettings) exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004051 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004052 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004053 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004054 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004055" call Dredir("ls!")
Bram Moolenaarff034192013-04-24 18:51:19 +02004056" call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004057 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004058 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004059 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004060 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004061 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004062 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004063 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004064" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004065" call Dret("s:NetrwListSettings")
4066endfun
4067
4068" ---------------------------------------------------------------------
4069" s:NetrwListStyle: {{{2
4070" islocal=0: remote browsing
4071" =1: local browsing
4072fun! s:NetrwListStyle(islocal)
4073" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004074
Bram Moolenaar97d62492012-11-15 21:28:22 +01004075 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076 let fname = s:NetrwGetWord()
4077 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004078 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004079 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
4080" call Decho("fname<".fname.">")
4081" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
4082" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
4083
4084 if w:netrw_liststyle == s:THINLIST
4085 " use one column listing
4086" call Decho("use one column list")
4087 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4088
4089 elseif w:netrw_liststyle == s:LONGLIST
4090 " use long list
4091" call Decho("use long list")
4092 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4093
4094 elseif w:netrw_liststyle == s:WIDELIST
4095 " give wide list
4096" call Decho("use wide list")
4097 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4098
4099 elseif w:netrw_liststyle == s:TREELIST
4100" call Decho("use tree list")
4101 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4102
4103 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02004104 keepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004105 let g:netrw_liststyle = s:THINLIST
4106 let w:netrw_liststyle = g:netrw_liststyle
4107 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4108 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004109 setl ma noro
4110" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111
4112 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
4113" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004114 sil! keepj %d
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004115 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara6878372014-03-22 21:02:50 +01004116" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004117 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004118" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004119
4120 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004121" call Decho("refresh the listing")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004122 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004123 keepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004124
Bram Moolenaar13600302014-05-22 18:26:40 +02004125 " restore position; keep cursor on the filename
4126 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004127 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004128
4129" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4130endfun
4131
4132" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004133" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4134fun! s:NetrwBannerCtrl(islocal)
4135" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4136
Bram Moolenaar97d62492012-11-15 21:28:22 +01004137 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004138 " toggle the banner (enable/suppress)
4139 let g:netrw_banner= !g:netrw_banner
4140
4141 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004142 let svpos= netrw#SavePosn()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004143 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4144
4145 " keep cursor on the filename
4146 let fname= s:NetrwGetWord()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004147 sil keepj $
Bram Moolenaar5c736222010-01-06 20:54:52 +01004148 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4149" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
4150 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004151 exe "keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01004152 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004153 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004154" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4155endfun
4156
4157" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004158" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4159" .2.[cnt] for bookmarks, and
4160" .3.[cnt] for history
4161" (see s:NetrwMenu())
4162fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004163 if !exists("s:netrw_menucnt")
4164 return
4165 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004166" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167
4168 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004169 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004170 if exists("g:NetrwTopLvlMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004172 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4173 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004174 endif
4175 if !exists("s:netrw_initbookhist")
4176 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004177 endif
4178
4179 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004180 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004181 let cnt= 1
4182 for bmd in g:netrw_bookmarklist
Bram Moolenaar8d043172014-01-23 14:24:41 +01004183" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd)
4184 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004185
4186 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004187 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004188
4189 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004190 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 +01004191 let cnt= cnt + 1
4192 endfor
4193
4194 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004195
4196 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004197 if g:netrw_dirhistmax > 0
4198 let cnt = g:netrw_dirhist_cnt
4199 let first = 1
4200 let histcnt = 0
4201 while ( first || cnt != g:netrw_dirhist_cnt )
4202 let histcnt = histcnt + 1
4203 let priority = g:netrw_dirhist_cnt + histcnt
4204 if exists("g:netrw_dirhist_{cnt}")
4205 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
4206" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir)
4207 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4208 endif
4209 let first = 0
4210 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4211 if cnt < 0
4212 let cnt= cnt + g:netrw_dirhistmax
4213 endif
4214 endwhile
4215 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004216
Bram Moolenaar9964e462007-05-05 17:54:07 +00004217 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004218" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004219endfun
4220
4221" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004222" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4223" directory and a new directory name. Also, if the
4224" "new directory name" is actually a file,
4225" NetrwBrowseChgDir() edits the file.
4226fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4227" 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 Moolenaara6878372014-03-22 21:02:50 +01004228" call Decho("win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00004229
Bram Moolenaar97d62492012-11-15 21:28:22 +01004230 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231 if !exists("b:netrw_curdir")
4232 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4233 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004234 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01004235" call Decho("b:netrw_curdir doesn't exist!")
4236" call Decho("getcwd<".getcwd().">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004237" call Dredir("ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004238" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004239 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004240 endif
4241
Bram Moolenaar97d62492012-11-15 21:28:22 +01004242 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01004243" call Decho("saving options")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004244 keepj call s:NetrwOptionSave("s:")
4245 keepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01004246 let nbcd_curpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004247 let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
Bram Moolenaara6878372014-03-22 21:02:50 +01004248" call Decho("setting s:nbcd_curpos_".bufnr('%')." to SavePosn")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004249 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004250 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004251 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004252 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004253 endif
4254 let newdir = a:newdir
4255 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004256 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004257" call Decho("dirname<".dirname.">")
4258
4259 " ignore <cr>s when done in the banner
4260 if g:netrw_banner
4261" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"))
4262 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
4263 if getline(".") =~ 'Quick Help'
4264" call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
4265 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
4266" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar13600302014-05-22 18:26:40 +02004267 setl ma noro nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01004268 keepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
4269 setl noma nomod nowrap
4270 keepj call netrw#RestorePosn(nbcd_curpos)
4271 keepj call s:NetrwOptionRestore("s:")
4272" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
4273 endif
4274 endif
4275" else " Decho
4276" call Decho("(s:NetrwBrowseChgdir) g:netrw_banner=".g:netrw_banner." (no banner)")
4277 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004278
Bram Moolenaar446cb832008-06-24 21:56:24 +00004279 " set up o/s-dependent directory recognition pattern
Bram Moolenaara6878372014-03-22 21:02:50 +01004280" call Decho("set up o/s-dependent directory recognition pattern")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004281 if has("amiga")
4282 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004283 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004284 let dirpat= '[\/]$'
4285 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004286" call Decho("dirname<".dirname."> dirpat<".dirpat.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287
4288 if dirname !~ dirpat
4289 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004290 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 let dirname= dirname.'/'
Bram Moolenaara6878372014-03-22 21:02:50 +01004292" call Decho("adjusting dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 endif
4294
4295 if newdir !~ dirpat
Bram Moolenaar97d62492012-11-15 21:28:22 +01004296 " ------------------------------
4297 " NetrwBrowseChgDir: edit a file {{{3
4298 " ------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004299" call Decho('edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004300
Bram Moolenaar97d62492012-11-15 21:28:22 +01004301 " save position for benefit of Rexplore
Bram Moolenaara6878372014-03-22 21:02:50 +01004302 let s:rexposn_{bufnr("%")}= netrw#SavePosn()
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004303
Bram Moolenaara6878372014-03-22 21:02:50 +01004304" call Decho("edit-a-file: setting s:rexposn_".bufnr("%")." to SavePosn")
4305" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
4306" call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">")
4307
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara6878372014-03-22 21:02:50 +01004309" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">")
4310" call Decho("edit-a-file: newdir<".newdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 let dirname= s:NetrwTreeDir()
4312 if dirname =~ '/$'
4313 let dirname= dirname.newdir
4314 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004315 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004317" call Decho("edit-a-file: dirname<".dirname.">")
4318" call Decho("edit-a-file: tree listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 elseif newdir =~ '^\(/\|\a:\)'
4320 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004321 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004323 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004324" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 " this lets NetrwBrowseX avoid the edit
4326 if a:0 < 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004327" call Decho("edit-a-file: set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004328 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 if !exists("s:didsplit")
Bram Moolenaara6878372014-03-22 21:02:50 +01004330" call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".g:netrw_browse_split." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 if g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004332 " horizontally splitting the window first
Bram Moolenaarff034192013-04-24 18:51:19 +02004333 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004334 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004335 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004336 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004338 " vertically splitting the window first
Bram Moolenaarff034192013-04-24 18:51:19 +02004339 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004340 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004341 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004342 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004343 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004344 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004345 keepalt tabnew
Bram Moolenaar446cb832008-06-24 21:56:24 +00004346 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004347 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004348 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004349 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004351 return
4352 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004353 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 " handling a file, didn't split, so remove menu
Bram Moolenaara6878372014-03-22 21:02:50 +01004355" call Decho("edit-a-file: handling a file+didn't split, so remove menu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 call s:NetrwMenu(0)
4357 " optional change to window
4358 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004359 if winnr("$")+1 == g:netrw_chgwin
4360 " if g:netrw_chgwin is set to one more than the last window, then
4361 " vertically split the last window to make that window available.
4362 let curwin= winnr()
4363 exe "keepj keepalt ".g:netrw_chgwin."wincmd ".winnr("$")
4364 vs
4365 exe "keepj keepalt ".g:netrw_chgwin."wincmd ".curwin
4366 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004367 exe "keepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004368 endif
4369 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004370 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004371
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 " the point where netrw actually edits the (local) file
4373 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004374 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01004376" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004377 " some like c-^ to return to the last edited file
4378 " others like c-^ to return to the netrw buffer
4379 if exists("g:netrw_altfile") && g:netrw_altfile
4380 exe "keepj keepalt e! ".fnameescape(dirname)
4381 else
4382 exe "keepj e! ".fnameescape(dirname)
4383 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004384" call Decho("after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004385 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004386" call Decho("COMBAK#1: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
4387 if &hidden || &bufhidden == "hide"
4388 " file came from vim's hidden storage. Don't "restore" options with it.
4389 let dorestore= 0
4390 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004391 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004392" call Decho("edit-a-file: remote file: NetrwBrowse will edit it")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004393 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 let dolockout= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004395" call Decho("COMBAK#2: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004396
4397 " handle g:Netrw_funcref -- call external-to-netrw functions
4398 " This code will handle g:Netrw_funcref as an individual function reference
4399 " or as a list of function references. It will ignore anything that's not
4400 " a function reference. See :help Funcref for information about function references.
4401 if exists("g:Netrw_funcref")
Bram Moolenaara6878372014-03-22 21:02:50 +01004402" call Decho("edit-a-file: handle optional Funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004403 if type(g:Netrw_funcref) == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01004404" call Decho("edit-a-file: handling a g:Netrw_funcref")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004405 keepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004406 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01004407" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004408 for Fncref in g:Netrw_funcref
4409 if type(FncRef) == 2
Bram Moolenaaradc21822011-04-01 18:03:16 +02004410 keepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004411 endif
4412 endfor
4413 endif
4414 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 endif
4416
4417 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004418 " ----------------------------------------------------
4419 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4420 " ----------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004421" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004422 let dirname = newdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02004423 keepj call s:SetRexDir(a:islocal,dirname)
4424 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425
4426 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004427 " ---------------------------------------------
4428 " NetrwBrowseChgDir: refresh the directory list {{{3
4429 " ---------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004430" call Decho('refresh-dirlist: case "refresh directory listing": newdir == "./"')
Bram Moolenaaradc21822011-04-01 18:03:16 +02004431 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432
4433 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004434 " --------------------------------------
4435 " NetrwBrowseChgDir: go up one directory {{{3
4436 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004437" call Decho('go-up: case "go up one directory": newdir == "../"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438
4439 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4440 " force a refresh
Bram Moolenaara6878372014-03-22 21:02:50 +01004441" call Decho("go-up: clear buffer<".expand("%")."> with :%d")
4442" call Decho("go-up: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004443 setl noro ma
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004444 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 endif
4446
4447 if has("amiga")
4448 " amiga
Bram Moolenaara6878372014-03-22 21:02:50 +01004449" call Decho('go-up: case "go up one directory": newdir == "../" and amiga')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 if a:islocal
4451 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4452 let dirname= substitute(dirname,'/$','','')
4453 else
4454 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4455 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004456" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457
Bram Moolenaar8d043172014-01-23 14:24:41 +01004458 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4459 " windows
4460 if a:islocal
4461 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4462 if dirname == ""
4463 let dirname= '/'
4464 endif
4465 else
4466 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4467 endif
4468 if dirname =~ '^\a:$'
4469 let dirname= dirname.'/'
4470 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004471" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004472
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473 else
4474 " unix or cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +01004475" call Decho('go-up: case "go up one directory": newdir == "../" and unix or cygwin')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476 if a:islocal
4477 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4478 if dirname == ""
4479 let dirname= '/'
4480 endif
4481 else
4482 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4483 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004484" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004486 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487
4488 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004489 " --------------------------------------
4490 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4491 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004492" call Decho('tree-list: case liststyle is TREELIST and w:netrw_treedict exists')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh)
Bram Moolenaara6878372014-03-22 21:02:50 +01004494" call Decho("tree-list: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004495 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004497" call Decho("tree-list: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004498 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 endif
4500 let treedir = s:NetrwTreeDir()
4501 let s:treecurpos = nbcd_curpos
4502 let haskey= 0
Bram Moolenaara6878372014-03-22 21:02:50 +01004503" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504
4505 " search treedict for tree dir as-is
4506 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004507" call Decho('tree-list: ....searched for treedir<'.treedir.'> : found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let haskey= 1
4509 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004510" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 endif
4512
4513 " search treedict for treedir with a / appended
4514 if !haskey && treedir !~ '/$'
4515 if has_key(w:netrw_treedict,treedir."/")
4516 let treedir= treedir."/"
Bram Moolenaara6878372014-03-22 21:02:50 +01004517" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let haskey = 1
4519 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004520" call Decho('tree-list: ....searched for treedir<'.treedir.'/> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 endif
4522 endif
4523
4524 " search treedict for treedir with any trailing / elided
4525 if !haskey && treedir =~ '/$'
4526 let treedir= substitute(treedir,'/$','','')
4527 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004528" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 let haskey = 1
4530 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004531" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 endif
4533 endif
4534
4535 if haskey
4536 " close tree listing for selected subdirectory
Bram Moolenaara6878372014-03-22 21:02:50 +01004537" call Decho("tree-list: closing selected subdirectory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 call remove(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004539" call Decho("tree-list: removed entry<".treedir."> from treedict")
4540" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004541 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 else
4543 " go down one directory
4544 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara6878372014-03-22 21:02:50 +01004545" call Decho("tree-list: go down one dir: treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004547 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004548 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549
4550 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004551 " ----------------------------------------
4552 " NetrwBrowseChgDir: Go down one directory {{{3
4553 " ----------------------------------------
4554 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004555" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004556 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004557 endif
4558
Bram Moolenaar97d62492012-11-15 21:28:22 +01004559 " --------------------------------------
4560 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4561 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004562" call Decho("COMBAK#3: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
4563 if dorestore
4564 " dorestore is zero'd when a local file was hidden or bufhidden;
4565 " in such a case, we want to keep whatever settings it may have.
4566" call Decho("doing option restore (dorestore=".dorestore.")")
4567 keepj call s:NetrwOptionRestore("s:")
4568" else " Decho
4569" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod)
4570 endif
4571" call Decho("COMBAK#4: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
4572 if dolockout && dorestore
Bram Moolenaara6878372014-03-22 21:02:50 +01004573" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004574 if filewritable(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01004575" call Decho("restore: doing modification lockout settings: ma nomod noro")
4576" call Decho("restore: setl ma nomod noro")
Bram Moolenaar13600302014-05-22 18:26:40 +02004577 setl ma noro nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004578" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004579 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004580" call Decho("restore: doing modification lockout settings: ma nomod ro")
4581" call Decho("restore: setl ma nomod noro")
Bram Moolenaar13600302014-05-22 18:26:40 +02004582 setl ma ro nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004583" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004584 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004585 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004586" call Decho("COMBAK#5: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004587 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004588
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
4590 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004591endfun
4592
4593" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004594" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4595" for thin, long, and wide: cursor placed just after banner
4596" for tree, keeps cursor on current filename
4597fun! s:NetrwBrowseUpDir(islocal)
4598" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
4599 norm! 0
4600 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4601" call Decho("ftp + treestyle")
4602 let curline= getline(".")
4603 let swwline= winline() - 1
4604 if exists("w:netrw_treetop")
4605 let b:netrw_curdir= w:netrw_treetop
4606 endif
4607 if a:islocal
4608 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4609 else
4610 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4611 endif
4612 if !search('\c^'.s:treedepthstring.curline,'cw')
4613 if !search('\c^'.curline,'cw')
4614 sil! keepj 1
4615 endif
4616 endif
4617 exe "sil! keepj norm! z\<cr>"
4618 while winline() < swwline
4619 let curwinline= winline()
4620 exe "sil! keepj norm! \<c-y>"
4621 if curwinline == winline()
4622 break
4623 endif
4624 endwhile
4625 else
4626" call Decho("ftp + not treestyle")
4627 if a:islocal
4628 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4629 else
4630 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4631 endif
4632 if exists("w:netrw_bannercnt")
4633" call Decho("moving to line#".w:netrw_bannercnt)
4634 exe w:netrw_bannercnt
4635 else
4636 1
4637 endif
4638 endif
4639" call Dret("s:NetrwBrowseUpDir")
4640endfun
4641
4642" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004643" s:NetrwBrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
4644" given filename; typically this means given their extension.
4645" 0=local, 1=remote
Bram Moolenaar446cb832008-06-24 21:56:24 +00004646fun! netrw#NetrwBrowseX(fname,remote)
4647" call Dfunc("NetrwBrowseX(fname<".a:fname."> remote=".a:remote.")")
4648
Bram Moolenaar97d62492012-11-15 21:28:22 +01004649 let ykeep = @@
Bram Moolenaara6878372014-03-22 21:02:50 +01004650 let screenposn = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01004651
Bram Moolenaar5c736222010-01-06 20:54:52 +01004652 " special core dump handler
4653 if a:fname =~ '/core\(\.\d\+\)\=$'
4654 if exists("g:Netrw_corehandler")
4655 if type(g:Netrw_corehandler) == 2
4656 " g:Netrw_corehandler is a function reference (see :help Funcref)
4657" call Decho("g:Netrw_corehandler is a funcref")
4658 call g:Netrw_corehandler(a:fname)
Bram Moolenaarff034192013-04-24 18:51:19 +02004659 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01004660 " g:Netrw_corehandler is a List of function references (see :help Funcref)
4661" call Decho("g:Netrw_corehandler is a List")
4662 for Fncref in g:Netrw_corehandler
4663 if type(FncRef) == 2
4664 call FncRef(a:fname)
4665 endif
4666 endfor
4667 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004668 call netrw#RestorePosn(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004669 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004670" call Dret("NetrwBrowseX : coredump handler invoked")
4671 return
4672 endif
4673 endif
4674
Bram Moolenaar446cb832008-06-24 21:56:24 +00004675 " set up the filename
4676 " (lower case the extension, make a local copy of a remote file)
4677 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
4678 if has("win32") || has("win95") || has("win64") || has("win16")
4679 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00004680 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004681" call Decho("exten<".exten.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004682
4683 " seems kde systems often have gnome-open due to dependencies, even though
4684 " gnome-open's subsidiary display tools are largely absent. Kde systems
4685 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
4686 if !exists("s:haskdeinit")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004687 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004688 let s:haskdeinit= system("ps -e") =~ 'kdeinit'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689 if v:shell_error
4690 let s:haskdeinit = 0
4691 endif
4692 else
4693 let s:haskdeinit= 0
4694 endif
4695" call Decho("setting s:haskdeinit=".s:haskdeinit)
4696 endif
4697
4698 if a:remote == 1
4699 " create a local copy
Bram Moolenaara6878372014-03-22 21:02:50 +01004700" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02004701 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01004702 call netrw#NetRead(3,a:fname)
4703 " attempt to rename tempfile
4704 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004705 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004706" call Decho("basename<".basename.">")
4707" call Decho("newname <".newname.">")
4708 if rename(s:netrw_tmpfile,newname) == 0
4709 " renaming succeeded
4710 let fname= newname
4711 else
4712 " renaming failed
4713 let fname= s:netrw_tmpfile
4714 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00004715 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004716" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004717 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004718 " special ~ handler for local
4719 if fname =~ '^\~' && expand("$HOME") != ""
4720" call Decho('invoking special ~ handler')
4721 let fname= substitute(fname,'^\~',expand("$HOME"),'')
4722 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004723 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004724" call Decho("fname<".fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004725" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
4726
4727 " set up redirection
4728 if &srr =~ "%s"
4729 if (has("win32") || has("win95") || has("win64") || has("win16"))
4730 let redir= substitute(&srr,"%s","nul","")
4731 else
4732 let redir= substitute(&srr,"%s","/dev/null","")
4733 endif
4734 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
4735 let redir= &srr . "nul"
4736 else
4737 let redir= &srr . "/dev/null"
4738 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004739" call Decho("set up redirection: redir{".redir."} srr{".&srr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740
4741 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004742" call Decho("extract any viewing options")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004743 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004744" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004745 if g:netrw_browsex_viewer =~ '\s'
4746 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
4747 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
4748 let oviewer = ''
4749 let cnt = 1
4750 while !executable(viewer) && viewer != oviewer
4751 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
4752 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
4753 let cnt = cnt + 1
4754 let oviewer = viewer
4755" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">")
4756 endwhile
4757 else
4758 let viewer = g:netrw_browsex_viewer
4759 let viewopt = ""
4760 endif
4761" call Decho("viewer<".viewer."> viewopt<".viewopt.">")
4762 endif
4763
4764 " execute the file handler
Bram Moolenaar97d62492012-11-15 21:28:22 +01004765" call Decho("execute the file handler (if any)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004766 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
4767" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
4768 let ret= netrwFileHandlers#Invoke(exten,fname)
4769
4770 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
4771" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004772" call Decho("exe sil !".viewer." ".viewopt.shellescape(fname,1).redir)
4773 exe "sil !".viewer." ".viewopt.shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004774 let ret= v:shell_error
4775
4776 elseif has("win32") || has("win64")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004777" call Decho("windows")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004778 if executable("start")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
4780 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004781 elseif executable("rundll32")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
4783 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004784 else
4785 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
4786 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004787 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
4788 let ret= v:shell_error
4789
Bram Moolenaar97d62492012-11-15 21:28:22 +01004790 elseif has("win32unix")
4791 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
4792" call Decho("cygwin: winfname<".shellescape(winfname,1).">")
4793 if executable("start")
4794" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
4795 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
4796 elseif executable("rundll32")
4797" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
4798 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
4799 else
4800 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
4801 endif
4802 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
4803 let ret= v:shell_error
4804
4805 elseif has("unix") && executable("xdg-open") && !s:haskdeinit
4806" call Decho("unix and xdg-open")
4807" call Decho("exe sil !xdg-open ".shellescape(fname,1)." ".redir)
4808 exe "sil !xdg-open ".shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004809 let ret= v:shell_error
4810
4811 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812" call Decho("unix and kfmclient")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004813" call Decho("exe sil !kfmclient exec ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004814 exe "sil !kfmclient exec ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815 let ret= v:shell_error
4816
4817 elseif has("macunix") && executable("open")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004818" call Decho("macunix and open")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004819" call Decho("exe sil !open ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004820 exe "sil !open ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 let ret= v:shell_error
4822
4823 else
4824 " netrwFileHandlers#Invoke() always returns 0
4825 let ret= netrwFileHandlers#Invoke(exten,fname)
4826 endif
4827
4828 " if unsuccessful, attempt netrwFileHandlers#Invoke()
4829 if ret
4830 let ret= netrwFileHandlers#Invoke(exten,fname)
4831 endif
4832
Bram Moolenaarc236c162008-07-13 17:41:49 +00004833 " restoring redraw! after external file handlers
4834 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00004835
4836 " cleanup: remove temporary file,
4837 " delete current buffer if success with handler,
4838 " return to prior buffer (directory listing)
4839 " Feb 12, 2008: had to de-activiate removal of
4840 " temporary file because it wasn't getting seen.
4841" if a:remote == 1 && fname != a:fname
Bram Moolenaar97d62492012-11-15 21:28:22 +01004842"" call Decho("deleting temporary file<".fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004843" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004844" endif
4845
4846 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02004847 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004849 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004851 exe "sil! keepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004852" redraw!
4853 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004854 call netrw#RestorePosn(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004855 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856
4857" call Dret("NetrwBrowseX")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004858endfun
4859
4860" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004861" s:NetrwChgPerm: (implements "gp") change file permission {{{2
4862fun! s:NetrwChgPerm(islocal,curdir)
4863" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004864 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004865 call inputsave()
4866 let newperm= input("Enter new permission: ")
4867 call inputrestore()
4868 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'')
4869 let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'')
4870" call Decho("chgperm<".chgperm.">")
4871 call system(chgperm)
4872 if v:shell_error != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02004873 keepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004874 endif
4875 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02004876 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004877 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004878 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004879" call Dret("s:NetrwChgPerm")
4880endfun
4881
4882" ---------------------------------------------------------------------
4883" s:NetrwClearExplore: clear explore variables (if any) {{{2
4884fun! s:NetrwClearExplore()
4885" call Dfunc("s:NetrwClearExplore()")
4886 2match none
4887 if exists("s:explore_match") |unlet s:explore_match |endif
4888 if exists("s:explore_indx") |unlet s:explore_indx |endif
4889 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
4890 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
4891 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
4892 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
4893 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
4894 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
4895 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
4896" redraw!
4897 echo " "
4898 echo " "
4899" call Dret("s:NetrwClearExplore")
4900endfun
4901
4902" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004903" s:NetrwExploreListUniq: {{{2
4904fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02004905" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004906
4907 " this assumes that the list is already sorted
4908 let newexplist= []
4909 for member in a:explist
4910 if !exists("uniqmember") || member != uniqmember
4911 let uniqmember = member
4912 let newexplist = newexplist + [ member ]
4913 endif
4914 endfor
4915
Bram Moolenaar15146672011-10-20 22:22:38 +02004916" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004917 return newexplist
4918endfun
4919
4920" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02004921" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
4922fun! s:NetrwForceChgDir(islocal,newdir)
4923" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004924 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02004925 if a:newdir !~ '/$'
4926 " ok, looks like force is needed to get directory-style treatment
4927 if a:newdir =~ '@$'
4928 let newdir= substitute(a:newdir,'@$','/','')
4929 elseif a:newdir =~ '[*=|\\]$'
4930 let newdir= substitute(a:newdir,'.$','/','')
4931 else
4932 let newdir= a:newdir.'/'
4933 endif
4934" call Decho("adjusting newdir<".newdir."> due to gd")
4935 else
4936 " should already be getting treatment as a directory
4937 let newdir= a:newdir
4938 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004939 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02004940 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004941 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02004942" call Dret("s:NetrwForceChgDir")
4943endfun
4944
4945" ---------------------------------------------------------------------
4946" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
4947fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02004948" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004949 if a:newfile =~ '[/@*=|\\]$'
4950 let newfile= substitute(a:newfile,'.$','','')
4951 else
4952 let newfile= a:newfile
4953 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004954 if a:islocal
4955 call s:NetrwBrowseChgDir(a:islocal,newfile)
4956 else
4957 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
4958 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004959" call Dret("s:NetrwForceFile")
4960endfun
4961
4962" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
4964" and switches the hiding mode. The actual hiding is done by
4965" s:NetrwListHide().
4966" g:netrw_hide= 0: show all
4967" 1: show not-hidden files
4968" 2: show hidden files only
4969fun! s:NetrwHide(islocal)
4970" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004971 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01004972 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004973
4974 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01004975" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004976" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">")
4977
4978 " hide the files in the markfile list
4979 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02004980" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
4982 " remove fname from hiding list
4983 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
4984 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
4985 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
4986" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">")
4987 else
4988 " append fname to hiding list
4989 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
4990 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
4991 else
4992 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
4993 endif
4994" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">")
4995 endif
4996 endfor
Bram Moolenaaradc21822011-04-01 18:03:16 +02004997 keepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 let g:netrw_hide= 1
4999
5000 else
5001
5002 " switch between show-all/show-not-hidden/show-hidden
5003 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005004 exe "keepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02005006 keepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005007 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005008" call Dret("NetrwHide")
5009 return
5010 endif
5011 endif
5012
Bram Moolenaaradc21822011-04-01 18:03:16 +02005013 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005014 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005015 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005016" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005017endfun
5018
5019" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005020" s:NetrwHidden: invoked by "gh" {{{2
5021fun! s:NetrwHidden(islocal)
5022" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005023 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005024 " save current position
Bram Moolenaara6878372014-03-22 21:02:50 +01005025 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005026
5027 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
5028 " remove pattern from hiding list
5029 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005030 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005031 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5032 else
5033 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5034 endif
5035
5036 " refresh screen and return to saved position
Bram Moolenaaradc21822011-04-01 18:03:16 +02005037 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005038 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005039 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040" call Dret("s:NetrwHidden")
5041endfun
5042
5043" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005044" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5045fun! s:NetrwHome()
5046 if exists("g:netrw_home")
5047 let home= g:netrw_home
5048 else
5049 " go to vim plugin home
5050 for home in split(&rtp,',') + ['']
5051 if isdirectory(home) && filewritable(home) | break | endif
5052 let basehome= substitute(home,'[/\\]\.vim$','','')
5053 if isdirectory(basehome) && filewritable(basehome)
5054 let home= basehome."/.vim"
5055 break
5056 endif
5057 endfor
5058 if home == ""
5059 " just pick the first directory
5060 let home= substitute(&rtp,',.*$','','')
5061 endif
5062 if (has("win32") || has("win95") || has("win64") || has("win16"))
5063 let home= substitute(home,'/','\\','g')
5064 endif
5065 endif
5066 " insure that the home directory exists
Bram Moolenaarff034192013-04-24 18:51:19 +02005067 if g:netrw_dirhistmax > 0 && !isdirectory(home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005068 if exists("g:netrw_mkdir")
5069 call system(g:netrw_mkdir." ".shellescape(home))
5070 else
5071 call mkdir(home)
5072 endif
5073 endif
5074 let g:netrw_home= home
5075 return home
5076endfun
5077
5078" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5080fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005081 if exists("s:netrwdrag")
5082 return
5083 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005085
Bram Moolenaar97d62492012-11-15 21:28:22 +01005086 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005087 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005088 while getchar(0) != 0
5089 "clear the input stream
5090 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005091 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005092 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005093 let mouse_lnum = v:mouse_lnum
5094 let wlastline = line('w$')
5095 let lastline = line('$')
5096" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr())
5097" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0))
5098 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5099 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005100 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005101" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5102 return
5103 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005104 " NOTE: following test is preventing leftmouse selection/deselection of directories and files in treelist mode (Dec 04, 2013)
5105 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
5106 " without this test.
5107" if v:mouse_col != col('.')
5108" let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005109" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005110" return
5111" endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005112
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 if a:islocal
5114 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005115 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 endif
5117 else
5118 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005119 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 endif
5121 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005122 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123" call Dret("s:NetrwLeftmouse")
5124endfun
5125
5126" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005127" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5128fun! s:NetrwSLeftmouse(islocal)
5129" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
5130
5131 let s:ngw= s:NetrwGetWord()
5132 call s:NetrwMarkFile(a:islocal,s:ngw)
5133
5134" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005135endfun
5136
5137" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005138" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5139" Used to mark multiple files.
5140fun! s:NetrwSLeftdrag(islocal)
5141" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5142 if !exists("s:netrwdrag")
5143 let s:netrwdrag = winnr()
5144 if a:islocal
5145 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005146 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005147 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005148 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005149 endif
5150 let ngw = s:NetrwGetWord()
5151 if !exists("s:ngw") || s:ngw != ngw
5152 call s:NetrwMarkFile(a:islocal,ngw)
5153 endif
5154 let s:ngw= ngw
5155" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5156endfun
5157
5158" ---------------------------------------------------------------------
5159" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5160fun! s:NetrwSLeftrelease(islocal)
5161" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5162 if exists("s:netrwdrag")
5163 nunmap <s-leftrelease>
5164 let ngw = s:NetrwGetWord()
5165 if !exists("s:ngw") || s:ngw != ngw
5166 call s:NetrwMarkFile(a:islocal,ngw)
5167 endif
5168 if exists("s:ngw")
5169 unlet s:ngw
5170 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005171 unlet s:netrwdrag
5172 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005173" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005174endfun
5175
5176" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005177" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
5178" separated patterns given in g:netrw_list_hide
5179fun! s:NetrwListHide()
Bram Moolenaaradc21822011-04-01 18:03:16 +02005180" call Dfunc("NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005181 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005182
5183 " find a character not in the "hide" string to use as a separator for :g and :v commands
5184 " How-it-works: take the hiding command, convert it into a range. Duplicate
5185 " characters don't matter. Remove all such characters from the '/~...90'
5186 " string. Use the first character left as a separator character.
5187 let listhide= g:netrw_list_hide
5188 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
5189" call Decho("sep=".sep)
5190
5191 while listhide != ""
5192 if listhide =~ ','
5193 let hide = substitute(listhide,',.*$','','e')
5194 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5195 else
5196 let hide = listhide
5197 let listhide = ""
5198 endif
5199
5200 " Prune the list by hiding any files which match
5201 if g:netrw_hide == 1
5202" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005203 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204 elseif g:netrw_hide == 2
5205" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005206 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207 endif
5208 endwhile
5209 if g:netrw_hide == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01005210 exe 'sil! keepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
5211 exe 'sil! keepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005212 endif
5213
Bram Moolenaaradc21822011-04-01 18:03:16 +02005214 " remove any blank lines that have somehow remained.
5215 " This seems to happen under Windows.
5216 exe 'sil! keepj 1,$g@^\s*$@d'
5217
Bram Moolenaar97d62492012-11-15 21:28:22 +01005218 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005219" call Dret("NetrwListHide")
5220endfun
5221
5222" ---------------------------------------------------------------------
5223" NetrwHideEdit: allows user to edit the file/directory hiding list
5224fun! s:NetrwHideEdit(islocal)
5225" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5226
Bram Moolenaar97d62492012-11-15 21:28:22 +01005227 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005228 " save current cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005229 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005230
5231 " get new hiding list from user
5232 call inputsave()
5233 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5234 call inputrestore()
5235 let g:netrw_list_hide= newhide
5236" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
5237
5238 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02005239 sil keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005240
5241 " restore cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005242 call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005243 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005244
5245" call Dret("NetrwHideEdit")
5246endfun
5247
5248" ---------------------------------------------------------------------
5249" NetSortSequence: allows user to edit the sorting sequence
5250fun! s:NetSortSequence(islocal)
5251" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
5252
Bram Moolenaar97d62492012-11-15 21:28:22 +01005253 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01005254 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005255 call inputsave()
5256 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
5257 call inputrestore()
5258
5259 " refresh the listing
5260 let g:netrw_sort_sequence= newsortseq
Bram Moolenaaradc21822011-04-01 18:03:16 +02005261 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005262 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005263 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005264
5265" call Dret("NetSortSequence")
5266endfun
5267
5268" ---------------------------------------------------------------------
5269" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
5270fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01005271" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005272
Bram Moolenaar97d62492012-11-15 21:28:22 +01005273 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005274 " get name of new directory from user. A bare <CR> will skip.
5275 " if its currently a directory, also request will be skipped, but with
5276 " a message.
5277 call inputsave()
5278 let newdirname= input("Please give directory name: ")
5279 call inputrestore()
5280" call Decho("newdirname<".newdirname.">")
5281
5282 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005283 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005284" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005285 return
5286 endif
5287
5288 if a:usrhost == ""
5289" call Decho("local mkdir")
5290
5291 " Local mkdir:
5292 " sanity checks
5293 let fullnewdir= b:netrw_curdir.'/'.newdirname
5294" call Decho("fullnewdir<".fullnewdir.">")
5295 if isdirectory(fullnewdir)
5296 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005297 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005298 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005299 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005300" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005301 return
5302 endif
5303 if s:FileReadable(fullnewdir)
5304 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005305 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005306 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005307 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005308" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005309 return
5310 endif
5311
5312 " requested new local directory is neither a pre-existing file or
5313 " directory, so make it!
5314 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005315 if has("unix")
5316 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5317 else
5318 call mkdir(fullnewdir,"p")
5319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005320 else
5321 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaara6878372014-03-22 21:02:50 +01005322 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005323" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005324" call Decho("exe sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
5325 exe "sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005326 if v:shell_error != 0
5327 let @@= ykeep
5328 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara6878372014-03-22 21:02:50 +01005329" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330 return
5331 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005332 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01005333" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir)
5334 call s:NetrwLcd(netrw_origdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005335 endif
5336 endif
5337
5338 if v:shell_error == 0
5339 " refresh listing
5340" call Decho("refresh listing")
Bram Moolenaara6878372014-03-22 21:02:50 +01005341 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005342 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005343 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005344 elseif !exists("g:netrw_quiet")
5345 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5346 endif
5347" redraw!
5348
5349 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005350 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005351" call Decho("remote mkdir")
5352 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5353 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaaradc21822011-04-01 18:03:16 +02005354" call Decho("exe sil! !".mkdircmd." ".shellescape(newdirname,1))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005355 exe "sil! !".mkdircmd." ".shellescape(newdirname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356 if v:shell_error == 0
5357 " refresh listing
Bram Moolenaara6878372014-03-22 21:02:50 +01005358 let svpos= netrw#SavePosn()
Bram Moolenaaradc21822011-04-01 18:03:16 +02005359 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005360 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005362 keepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 endif
5364" redraw!
5365
5366 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005367 " Remote mkdir: using ftp+.netrc
5368 let svpos= netrw#SavePosn()
5369" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5370 if exists("b:netrw_fname")
5371" call Decho("b:netrw_fname<".b:netrw_fname.">")
5372 let remotepath= b:netrw_fname
5373 else
5374 let remotepath= ""
5375 endif
5376 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar15146672011-10-20 22:22:38 +02005377 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005378 keepj call netrw#RestorePosn(svpos)
5379
Bram Moolenaar446cb832008-06-24 21:56:24 +00005380 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005381 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
5382 let svpos= netrw#SavePosn()
5383" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5384 if exists("b:netrw_fname")
5385" call Decho("b:netrw_fname<".b:netrw_fname.">")
5386 let remotepath= b:netrw_fname
5387 else
5388 let remotepath= ""
5389 endif
5390 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar15146672011-10-20 22:22:38 +02005391 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005392 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005393 endif
5394
Bram Moolenaar97d62492012-11-15 21:28:22 +01005395 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005396" call Dret("s:NetrwMakeDir")
5397endfun
5398
5399" ---------------------------------------------------------------------
5400" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
5401fun! s:TreeSqueezeDir(islocal)
5402" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
5403 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5404 " its a tree-listing style
5405 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5406 let iline = line(".") - 1
5407 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
5408" call Decho("curdepth=".curdepth)
5409" call Decho("stopline#".stopline)
5410" call Decho("starting with line#".line(".").": ".getline('.'))
5411 while iline > stopline
5412 " find a line that has less depth
5413 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5414" call Decho("considering line#".line(".").": ".getline('.'))
5415 if depth < curdepth
5416 break
5417 endif
5418 norm! k
5419 endwhile
5420" call Decho("squeezing at line#".line(".").": ".getline('.'))
5421 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
5422 endif
5423" call Dret("s:TreeSqueezeDir")
5424endfun
5425
5426" ---------------------------------------------------------------------
5427" s:NetrwMaps: {{{2
5428fun! s:NetrwMaps(islocal)
5429" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
5430
5431 if g:netrw_mousemaps && g:netrw_retmap
5432" call Decho("set up Rexplore 2-leftmouse")
5433 if !hasmapto("<Plug>NetrwReturn")
5434 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
5435" call Decho("making map for 2-leftmouse")
5436 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
5437 elseif maparg("<c-leftmouse>","n") == ""
5438" call Decho("making map for c-leftmouse")
5439 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
5440 endif
5441 endif
5442 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
5443" call Decho("made <Plug>NetrwReturn map")
5444 endif
5445
5446 if a:islocal
5447" call Decho("make local maps")
5448 " local normal-mode maps
5449 nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr>
5450 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr>
5451 nnoremap <buffer> <silent> c :call <SID>NetrwLcd(b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005452 nnoremap <buffer> <silent> C :<c-u>call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005453 nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5454 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(1)<cr>
5455 nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>
5456 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(1)<cr>
5457 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5458 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
5459 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
5460 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr>
5461 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5462 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
5463 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr>
5464 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5465 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5466 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5467 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5468 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5469 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5470 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
5471 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5472 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5473 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5474 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5475 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5476 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5477 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5478 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5479 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
5480 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1)<cr>
5481 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5482 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5483 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr>
5484 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr>
5485 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5486 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr>
5487 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5488 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5489 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5490 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>
5491 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr>
5492 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
5493 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr>
5494 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5495 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5496 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5497 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5498 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr>
5499 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
5500 nnoremap <buffer> <silent> X :call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
5501 " local insert-mode maps
5502 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr>
5503 inoremap <buffer> <silent> c <c-o>:exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
5504 inoremap <buffer> <silent> c <c-o>:call <SID>NetrwLcd(b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005505 inoremap <buffer> <silent> C <c-o>:call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005506 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr>
5507 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(1)<cr>
5508 inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5509 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(1)<cr>
5510 inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>
5511 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5512 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr>
5513 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5514 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
5515 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr>
5516 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5517 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5518 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5519 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5520 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5521 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5522 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5523 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5524 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5525 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5526 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5527 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5528 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5529 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5530 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr>
5531 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1)<cr>
5532 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5533 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5534 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr>
5535 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr>
5536 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5537 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5538 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5539 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5540 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5541 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>
5542 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr>
5543 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr>
5544 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr>
5545 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5546 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5547 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5548 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5549 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr>
5550 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
5551 if !hasmapto('<Plug>NetrwHideEdit')
5552 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5553 imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5554 endif
5555 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
5556 if !hasmapto('<Plug>NetrwRefresh')
5557 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5558 imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5559 endif
5560 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
5561 if s:didstarstar || !mapcheck("<s-down>","n")
5562 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
5563 inoremap <buffer> <silent> <s-down> :Nexplore<cr>
5564 endif
5565 if s:didstarstar || !mapcheck("<s-up>","n")
5566 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
5567 inoremap <buffer> <silent> <s-up> :Pexplore<cr>
5568 endif
5569 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
5570 if g:netrw_mousemaps == 1
5571 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
5572 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
5573 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
5574 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
5575 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
5576 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
5577 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
5578 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
5579 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
5580 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
5581 imap <buffer> <leftmouse> <Plug>ILeftmouse
5582 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr>
5583 imap <buffer> <middlemouse> <Plug>IMiddlemouse
5584 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5585 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
5586 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5587 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5588 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5589 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5590 endif
5591 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5592 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5593 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5594 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>'
5595 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5596 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5597 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5598 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5599 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5600 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5601 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>'
5602 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
5603
5604 else " remote
5605" call Decho("make remote maps")
5606 call s:RemotePathAnalysis(b:netrw_curdir)
5607 " remote normal-mode maps
5608 nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
5609 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(0)<cr>
5610 nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5611 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(0)<cr>
5612 nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr>
5613 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5614 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
5615 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
5616 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
5617 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5618 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
5619 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
5620 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
5621 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
5622 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
5623 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
5624 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
5625 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
5626 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
5627 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
5628 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0)<cr>
5629 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
5630 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
5631 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5632 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
5633 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
5634 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr>
5635 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005636 nnoremap <buffer> <silent> C :<c-u>call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005637 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr>
5638 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
5639 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr>
5640 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr>
5641 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5642 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr>
5643 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5644 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5645 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
5646 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
5647 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>
5648 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr>
5649 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
5650 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr>
5651 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5652 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5653 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
5654 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
5655 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr>
5656 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
5657 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr>
5658 " remote insert-mode maps
5659 inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
5660 inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5661 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(0)<cr>
5662 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(0)<cr>
5663 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr>
5664 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5665 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
5666 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
5667 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
5668 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5669 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
5670 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
5671 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr>
5672 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
5673 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
5674 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr>
5675 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
5676 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr>
5677 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr>
5678 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0)<cr>
5679 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
5680 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
5681 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5682 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr>
5683 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005684 inoremap <buffer> <silent> C <c-o>:call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005685 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr>
5686 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
5687 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr>
5688 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr>
5689 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5690 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
5691 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5692 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5693 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
5694 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
5695 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>
5696 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr>
5697 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr>
5698 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr>
5699 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5700 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5701 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
5702 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
5703 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr>
5704 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
5705 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr>
5706 if !hasmapto('<Plug>NetrwHideEdit')
5707 nmap <buffer> <c-h> <Plug>NetrwHideEdit
5708 imap <buffer> <c-h> <Plug>NetrwHideEdit
5709 endif
5710 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
5711 if !hasmapto('<Plug>NetrwRefresh')
5712 nmap <buffer> <c-l> <Plug>NetrwRefresh
5713 imap <buffer> <c-l> <Plug>NetrwRefresh
5714 endif
5715
5716 let mapsafepath = escape(s:path, s:netrw_map_escape)
5717 let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape)
5718
5719 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5720 if g:netrw_mousemaps == 1
5721 nmap <leftmouse> <Plug>NetrwLeftmouse
5722 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
5723 nmap <buffer> <leftdrag> <Plug>NetrwLeftdrag
5724 nno <buffer> <silent> <Plug>NetrwLeftdrag :call <SID>NetrwLeftdrag(0)<cr>
5725 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
5726 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
5727 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
5728 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
5729 nmap <middlemouse> <Plug>NetrwMiddlemouse
5730 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
5731 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
5732 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
5733 imap <buffer> <leftmouse> <Plug>ILeftmouse
5734 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr>
5735 imap <buffer> <middlemouse> <Plug>IMiddlemouse
5736 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
5737 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
5738 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5739 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5740 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5741 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5742 endif
5743 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5744 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
5745 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5746 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5747 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5748 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5749 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5750 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5751 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
5752 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5753 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5754 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
5755 inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr>
5756 endif
5757
5758 keepj call s:SetRexDir(a:islocal,b:netrw_curdir)
5759
5760" call Dret("s:NetrwMaps")
5761endfun
5762
5763" ---------------------------------------------------------------------
5764" s:NetrwCommands: sets up commands available only in the netrw buffer windows {{{2
5765fun! s:NetrwCommands(islocal)
5766" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
5767
5768 com! Rexplore if exists("w:netrw_rexlocal")|call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".")|else|call netrw#ErrorMsg(s:WARNING,"not a former netrw window",79)|endif
5769 if a:islocal
5770 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
5771 else
5772 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
5773 endif
5774 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
5775
5776" call Dret("s:NetrwCommands")
5777endfun
5778
5779" ---------------------------------------------------------------------
5780" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
5781" glob()ing only works with local files
5782fun! s:NetrwMarkFiles(islocal,...)
5783" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
5784 let i = 1
5785 while i <= a:0
5786 if a:islocal
5787 let mffiles= glob(a:{i},0,1)
5788 else
5789 let mffiles= [a:{i}]
5790 endif
5791" call Decho("mffiles".string(mffiles))
5792 for mffile in mffiles
5793" call Decho("mffile<".mffile.">")
5794 call s:NetrwMarkFile(a:islocal,mffile)
5795 endfor
5796 let i= i + 1
5797 endwhile
5798" call Dret("s:NetrwMarkFiles")
5799endfun
5800
5801" ---------------------------------------------------------------------
5802" s:NetrwMarkTarget: {{{2
5803fun! s:NetrwMarkTarget(...)
5804" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
5805 if a:0 == 0 || (a:0 == 1 && a:1 == "")
5806 let tgt= b:netrw_curdir
5807 else
5808 let tgt= a:1
5809 endif
5810" call Decho("tgt<".tgt.">")
5811 let s:netrwmftgt = tgt
5812 let s:netrwmftgt_islocal = tgt !~ '^\a\+://'
5813 let curislocal = b:netrw_curdir !~ '^\a\+://'
5814 let svpos = netrw#SavePosn()
5815 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
5816 call netrw#RestorePosn(svpos)
5817" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005818endfun
5819
5820" ---------------------------------------------------------------------
5821" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
5822" mark and unmark files. If a markfile list exists,
5823" then the rename and delete functions will use it instead
5824" of whatever may happen to be under the cursor at that
5825" moment. When the mouse and gui are available,
5826" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005827"
5828" Creates two lists
5829" s:netrwmarkfilelist -- holds complete paths to all marked files
5830" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
5831"
5832" Creates a marked file match string
5833" s:netrwmarfilemtch_# -- used with 2match to display marked files
5834"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005835" Creates a buffer version of islocal
5836" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00005837fun! s:NetrwMarkFile(islocal,fname)
5838" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +02005839
5840 " sanity check
5841 if empty(a:fname)
5842" call Dret("s:NetrwMarkFile : emtpy fname")
5843 return
5844 endif
5845
Bram Moolenaar97d62492012-11-15 21:28:22 +01005846 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005847 let curbufnr= bufnr("%")
5848 let curdir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01005849 if a:fname =~ '^\a'
5850 let leader= '\<'
5851 else
5852 let leader= ''
5853 endif
5854 if a:fname =~ '\a$'
5855 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
5856 else
5857 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
5858 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005859
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005861 " markfile list pre-exists
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862" call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
5863" call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">")
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005864 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00005865
5866 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005867 " append filename to buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
5869 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01005870 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871
5872 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005873 " remove filename from buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00005874" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
5875 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
5876 if s:netrwmarkfilelist_{curbufnr} == []
5877 " local markfilelist is empty; remove it entirely
Bram Moolenaar5c736222010-01-06 20:54:52 +01005878" call Decho("markfile list now empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879 call s:NetrwUnmarkList(curbufnr,curdir)
5880 else
5881 " rebuild match list to display markings correctly
5882" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr)
5883 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01005884 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885 for fname in s:netrwmarkfilelist_{curbufnr}
5886 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01005887 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005888 else
Bram Moolenaara6878372014-03-22 21:02:50 +01005889 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005890 endif
5891 let first= 0
5892 endfor
Bram Moolenaar15146672011-10-20 22:22:38 +02005893" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894 endif
5895 endif
5896
5897 else
5898 " initialize new markfilelist
5899
5900" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr)
5901 let s:netrwmarkfilelist_{curbufnr}= []
5902 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
5903" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
5904
5905 " build initial markfile matching pattern
5906 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01005907 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005908 else
Bram Moolenaara6878372014-03-22 21:02:50 +01005909 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910 endif
5911" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
5912 endif
5913
5914 " handle global markfilelist
5915 if exists("s:netrwmarkfilelist")
5916 let dname= s:ComposePath(b:netrw_curdir,a:fname)
5917 if index(s:netrwmarkfilelist,dname) == -1
5918 " append new filename to global markfilelist
5919 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
5920" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">")
5921 else
5922 " remove new filename from global markfilelist
5923" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")")
5924 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
5925" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">")
5926 if s:netrwmarkfilelist == []
5927 unlet s:netrwmarkfilelist
5928 endif
5929 endif
5930 else
5931 " initialize new global-directory markfilelist
5932 let s:netrwmarkfilelist= []
5933 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
5934" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">")
5935 endif
5936
5937 " set up 2match'ing to netrwmarkfilemtch list
5938 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
5939" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005940 if exists("g:did_drchip_netrwlist_syntax")
5941 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
5942 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 else
5944" call Decho("2match none")
5945 2match none
5946 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005947 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005948" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949endfun
5950
5951" ---------------------------------------------------------------------
5952" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
5953" compress/decompress files using the programs
5954" in g:netrw_compress and g:netrw_uncompress,
5955" using g:netrw_compress_suffix to know which to
5956" do. By default:
5957" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005958" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959fun! s:NetrwMarkFileCompress(islocal)
5960" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01005961 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005962 let curdir = b:netrw_curdir
5963 let curbufnr = bufnr("%")
5964
Bram Moolenaarff034192013-04-24 18:51:19 +02005965 " sanity check
5966 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
5967 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
5968" call Dret("s:NetrwMarkFileCompress")
5969 return
5970 endif
5971" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
5972
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02005974
5975 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005976 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02005977 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
5978" call Decho("extracted sfx<".sfx.">")
5979 if exists("g:netrw_decompress['".sfx."']")
5980 " fname has a suffix indicating that its compressed; apply associated decompression routine
5981 let exe= g:netrw_decompress[sfx]
5982" call Decho("fname<".fname."> is compressed so decompress with <".exe.">")
5983 let exe= netrw#WinPath(exe)
5984 if a:islocal
5985 if g:netrw_keepdir
5986 let fname= shellescape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005987 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005988 else
5989 let fname= shellescape(b:netrw_curdir.fname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005990 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005991 if executable(exe)
5992 if a:islocal
5993 call system(exe." ".fname)
5994 else
5995 keepj call s:RemoteSystem(exe." ".fname)
5996 endif
5997 else
5998 keepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
5999 endif
6000 endif
6001 unlet sfx
6002
Bram Moolenaar446cb832008-06-24 21:56:24 +00006003 if exists("exe")
6004 unlet exe
6005 elseif a:islocal
6006 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01006007 call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006008 else
6009 " fname not a compressed file, so compress it
Bram Moolenaaradc21822011-04-01 18:03:16 +02006010 keepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006011 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006012 endfor " for every file in the marked list
6013
Bram Moolenaar446cb832008-06-24 21:56:24 +00006014 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006015 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006016 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006017 endif
6018" call Dret("s:NetrwMarkFileCompress")
6019endfun
6020
6021" ---------------------------------------------------------------------
6022" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6023" If no marked files, then set up directory as the
6024" target. Currently does not support copying entire
6025" directories. Uses the local-buffer marked file list.
6026" Returns 1=success (used by NetrwMarkFileMove())
6027" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006028fun! s:NetrwMarkFileCopy(islocal,...)
6029" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6030
6031 if !exists("b:netrw_curdir")
6032 let b:netrw_curdir= getcwd()
6033" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
6034 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006035 let curdir = b:netrw_curdir
6036 let curbufnr = bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006037
Bram Moolenaarff034192013-04-24 18:51:19 +02006038 " sanity check
6039 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6040 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6041" call Dret("s:NetrwMarkFileCopy")
6042 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006043 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006044" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6045
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046 if !exists("s:netrwmftgt")
Bram Moolenaar251e1912011-06-19 05:09:16 +02006047 keepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048" call Dret("s:NetrwMarkFileCopy 0")
6049 return 0
6050 endif
6051" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006052
6053 if a:islocal && s:netrwmftgt_islocal
6054 " Copy marked files, local directory to local directory
6055" call Decho("copy from local to local")
Bram Moolenaar13600302014-05-22 18:26:40 +02006056 if !executable(g:netrw_localcopycmd) && g:netrw_localcopycmd !~ '^'.expand("$COMSPEC").'\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01006057 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6058" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6059 return
6060 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006061
6062 " copy marked files while within the same directory (ie. allow renaming)
6063 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
6064 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6065 " only one marked file
6066 let args = shellescape(b:netrw_curdir."/".s:netrwmarkfilelist_{bufnr('%')}[0])
6067 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6068 elseif a:0 == 1
6069 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
6070 let args = shellescape(b:netrw_curdir."/".a:1)
6071 let oldname = a:1
6072 else
6073 " copy multiple marked files inside the same directory
6074 let s:recursive= 1
6075 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6076 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6077 if ret == 0
6078 break
6079 endif
6080 endfor
6081 unlet s:recursive
6082 call s:NetrwUnmarkList(curbufnr,curdir)
6083" call Dret("s:NetrwMarkFileCopy ".ret)
6084 return ret
6085 endif
6086
6087 call inputsave()
6088 let newname= input("Copy ".oldname." to : ",oldname,"file")
6089 call inputrestore()
6090 if newname == ""
6091" call Dret("s:NetrwMarkFileCopy 0")
6092 return 0
6093 endif
6094 let args= shellescape(oldname)
6095 let tgt = shellescape(s:netrwmftgt.'/'.newname)
6096 else
6097 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)"))
6098 let tgt = shellescape(s:netrwmftgt)
6099 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006100 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6101 let args= substitute(args,'/','\\','g')
6102 let tgt = substitute(tgt, '/','\\','g')
6103 endif
6104 if g:netrw_localcopycmd =~ '\s'
6105 let copycmd = substitute(g:netrw_localcopycmd,'\s.*$','','')
6106 let copycmdargs = substitute(g:netrw_localcopycmd,'^.\{-}\(\s.*\)$','\1','')
6107 let copycmd = netrw#WinPath(copycmd).copycmdargs
6108 else
6109 let copycmd = netrw#WinPath(g:netrw_localcopycmd)
6110 endif
6111" call Decho("args <".args.">")
6112" call Decho("tgt <".tgt.">")
6113" call Decho("copycmd<".copycmd.">")
6114" call Decho("system(".copycmd." ".args." ".tgt.")")
6115 call system(copycmd." ".args." ".tgt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006116 if v:shell_error != 0
Bram Moolenaarff034192013-04-24 18:51:19 +02006117 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006118" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt))
6119 return 0
6120 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006121
6122 elseif a:islocal && !s:netrwmftgt_islocal
6123 " Copy marked files, local directory to remote directory
6124" call Decho("copy from local to remote")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006125 keepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006126
6127 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006128 " Copy marked files, remote directory to local directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006129" call Decho("copy from remote to local")
Bram Moolenaara6878372014-03-22 21:02:50 +01006130 keepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006131
6132 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006133 " Copy marked files, remote directory to remote directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006134" call Decho("copy from remote to remote")
6135 let curdir = getcwd()
6136 let tmpdir = s:GetTempfile("")
6137 if tmpdir !~ '/'
6138 let tmpdir= curdir."/".tmpdir
6139 endif
6140 if exists("*mkdir")
6141 call mkdir(tmpdir)
6142 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006143 exe "sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006144 if v:shell_error != 0
6145 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
6146" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1) )
6147 return
6148 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006149 endif
6150 if isdirectory(tmpdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01006151 call s:NetrwLcd(tmpdir)
6152 keepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006153 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaaradc21822011-04-01 18:03:16 +02006154 keepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006155 if getcwd() == tmpdir
6156 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006157 keepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006158 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +01006159 call s:NetrwLcd(curdir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006160 exe "sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006161 if v:shell_error != 0
6162 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
6163" call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1) )
6164 return
6165 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006166 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006167 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006168 endif
6169 endif
6170 endif
6171
6172 " -------
6173 " cleanup
6174 " -------
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006175" call Decho("cleanup")
6176 if !exists("s:recursive")
6177 " remove markings from local buffer
6178 call s:NetrwUnmarkList(curbufnr,curdir)
6179 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006180
6181 " refresh buffers
6182 if !s:netrwmftgt_islocal
6183 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6184 endif
6185 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006186 keepj call s:NetrwRefreshDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006187 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006188 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006189 keepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006190 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006191
6192" call Dret("s:NetrwMarkFileCopy 1")
6193 return 1
6194endfun
6195
6196" ---------------------------------------------------------------------
6197" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6198" invoke vim's diff mode on the marked files.
6199" Either two or three files can be so handled.
6200" Uses the global marked file list.
6201fun! s:NetrwMarkFileDiff(islocal)
6202" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6203 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006204
Bram Moolenaarff034192013-04-24 18:51:19 +02006205 " sanity check
6206 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6207 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6208" call Dret("s:NetrwMarkFileDiff")
6209 return
6210 endif
6211" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6212
Bram Moolenaara6878372014-03-22 21:02:50 +01006213 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214 let cnt = 0
6215 let curdir = b:netrw_curdir
6216 for fname in s:netrwmarkfilelist
6217 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006218 if cnt == 1
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006219" call Decho("diffthis: fname<".fname.">")
6220 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221 diffthis
6222 elseif cnt == 2 || cnt == 3
6223 vsplit
6224 wincmd l
6225" call Decho("diffthis: ".fname)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006226 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006227 diffthis
6228 else
6229 break
6230 endif
6231 endfor
6232 call s:NetrwUnmarkList(curbufnr,curdir)
6233 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006234
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235" call Dret("s:NetrwMarkFileDiff")
6236endfun
6237
6238" ---------------------------------------------------------------------
6239" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6240" Uses global markfilelist
6241fun! s:NetrwMarkFileEdit(islocal)
6242" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6243
6244 let curdir = b:netrw_curdir
6245 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006246
6247 " sanity check
6248 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6249 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6250" call Dret("s:NetrwMarkFileEdit")
6251 return
6252 endif
6253" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6254
Bram Moolenaar446cb832008-06-24 21:56:24 +00006255 if exists("s:netrwmarkfilelist_{curbufnr}")
6256 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006257 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006258 " unmark markedfile list
6259" call s:NetrwUnmarkList(curbufnr,curdir)
6260 call s:NetrwUnmarkAll()
Bram Moolenaaradc21822011-04-01 18:03:16 +02006261" call Decho("exe sil args ".flist)
6262 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006264 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265
6266" call Dret("s:NetrwMarkFileEdit")
6267endfun
6268
6269" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02006270" s:NetrwMarkFileQFEL: convert a quickfix-error list into a marked file list {{{2
6271fun! s:NetrwMarkFileQFEL(islocal,qfel)
6272" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6273 call s:NetrwUnmarkAll()
6274 let curbufnr= bufnr("%")
6275
6276 if !empty(a:qfel)
6277 for entry in a:qfel
6278 let bufnmbr= entry["bufnr"]
6279" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"])
6280 if !exists("s:netrwmarkfilelist_{curbufnr}")
6281" call Decho("case: no marked file list")
6282 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6283 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6284 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6285 " So, this test lets two or more hits on the same pattern to be ignored.
6286" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list")
6287 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6288 else
6289" call Decho("case: ".bufname(bufnmbr)." already in marked file list")
6290 endif
6291 endfor
6292 echo "(use me to edit marked files)"
6293 else
6294 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6295 endif
6296
6297" call Dret("s:NetrwMarkFileQFEL")
6298endfun
6299
6300" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02006301" s:NetrwMarkFileExe: (invoked by mx) execute arbitrary system command on marked files, one at a time {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302" Uses the local marked-file list.
6303fun! s:NetrwMarkFileExe(islocal)
6304" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006305 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 let curdir = b:netrw_curdir
6307 let curbufnr = bufnr("%")
6308
Bram Moolenaarff034192013-04-24 18:51:19 +02006309 " sanity check
6310 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6311 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6312" call Dret("s:NetrwMarkFileExe")
6313 return
6314 endif
6315" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6316
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317 if exists("s:netrwmarkfilelist_{curbufnr}")
6318 " get the command
6319 call inputsave()
6320 let cmd= input("Enter command: ","","file")
6321 call inputrestore()
6322" call Decho("cmd<".cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02006323 if cmd == ""
6324" " call Dret("s:NetrwMarkFileExe : early exit, empty command")
6325 return
6326 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327
6328 " apply command to marked files. Substitute: filename -> %
6329 " If no %, then append a space and the filename to the command
6330 for fname in s:netrwmarkfilelist_{curbufnr}
6331 if a:islocal
6332 if g:netrw_keepdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01006333 let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 endif
6335 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01006336 let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
6338 if cmd =~ '%'
6339 let xcmd= substitute(cmd,'%',fname,'g')
6340 else
6341 let xcmd= cmd.' '.fname
6342 endif
6343 if a:islocal
6344" call Decho("local: xcmd<".xcmd.">")
6345 let ret= system(xcmd)
6346 else
6347" call Decho("remote: xcmd<".xcmd.">")
6348 let ret= s:RemoteSystem(xcmd)
6349 endif
6350 if v:shell_error < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02006351 keepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006352 break
6353 else
6354 echo ret
6355 endif
6356 endfor
6357
6358 " unmark marked file list
6359 call s:NetrwUnmarkList(curbufnr,curdir)
6360
6361 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02006362 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006363 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006364 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006365 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006366 endif
6367
6368" call Dret("s:NetrwMarkFileExe")
6369endfun
6370
6371" ---------------------------------------------------------------------
6372" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6373" as the marked file(s) (toggles suffix presence)
6374" Uses the local marked file list.
6375fun! s:NetrwMarkHideSfx(islocal)
6376" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006377 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006378 let curbufnr = bufnr("%")
6379
6380 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6381 if exists("s:netrwmarkfilelist_{curbufnr}")
6382
6383 for fname in s:netrwmarkfilelist_{curbufnr}
6384" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6385 " construct suffix pattern
6386 if fname =~ '\.'
6387 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6388 else
6389 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6390 endif
6391 " determine if its in the hiding list or not
6392 let inhidelist= 0
6393 if g:netrw_list_hide != ""
6394 let itemnum = 0
6395 let hidelist= split(g:netrw_list_hide,',')
6396 for hidepat in hidelist
6397 if sfxpat == hidepat
6398 let inhidelist= 1
6399 break
6400 endif
6401 let itemnum= itemnum + 1
6402 endfor
6403 endif
6404" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6405 if inhidelist
6406 " remove sfxpat from list
6407 call remove(hidelist,itemnum)
6408 let g:netrw_list_hide= join(hidelist,",")
6409 elseif g:netrw_list_hide != ""
6410 " append sfxpat to non-empty list
6411 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6412 else
6413 " set hiding list to sfxpat
6414 let g:netrw_list_hide= sfxpat
6415 endif
6416 endfor
6417
6418 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02006419 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006422 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006423 endif
6424
6425" call Dret("s:NetrwMarkHideSfx")
6426endfun
6427
6428" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02006429" s:NetrwMarkFileVimCmd: (invoked by mX) execute arbitrary vim command on marked files, one at a time {{{2
6430" Uses the local marked-file list.
6431fun! s:NetrwMarkFileVimCmd(islocal)
6432" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006433 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006434 let curdir = b:netrw_curdir
6435 let curbufnr = bufnr("%")
6436
Bram Moolenaarff034192013-04-24 18:51:19 +02006437 " sanity check
6438 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6439 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6440" call Dret("s:NetrwMarkFileVimCmd")
6441 return
6442 endif
6443" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6444
Bram Moolenaar15146672011-10-20 22:22:38 +02006445 if exists("s:netrwmarkfilelist_{curbufnr}")
6446 " get the command
6447 call inputsave()
6448 let cmd= input("Enter vim command: ","","file")
6449 call inputrestore()
6450" call Decho("cmd<".cmd.">")
6451 if cmd == ""
6452" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
6453 return
6454 endif
6455
6456 " apply command to marked files. Substitute: filename -> %
6457 " If no %, then append a space and the filename to the command
6458 for fname in s:netrwmarkfilelist_{curbufnr}
6459" call Decho("fname<".fname.">")
6460 if a:islocal
6461 1split
6462 exe "sil! keepalt e ".fnameescape(fname)
6463" call Decho("local<".fname.">: exe ".cmd)
6464 exe cmd
6465 exe "sil! keepalt wq!"
6466 else
Bram Moolenaar15146672011-10-20 22:22:38 +02006467" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET")
6468 echo "sorry, \"mX\" not supported yet for remote files"
6469 endif
6470 endfor
6471
6472 " unmark marked file list
6473 call s:NetrwUnmarkList(curbufnr,curdir)
6474
6475 " refresh the listing
6476 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006477 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02006478 else
6479 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
6480 endif
6481
6482" call Dret("s:NetrwMarkFileVimCmd")
6483endfun
6484
6485" ---------------------------------------------------------------------
6486" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6487" as the marked file(s) (toggles suffix presence)
6488" Uses the local marked file list.
6489fun! s:NetrwMarkHideSfx(islocal)
6490" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006492 let curbufnr = bufnr("%")
6493
6494 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6495 if exists("s:netrwmarkfilelist_{curbufnr}")
6496
6497 for fname in s:netrwmarkfilelist_{curbufnr}
6498" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6499 " construct suffix pattern
6500 if fname =~ '\.'
6501 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6502 else
6503 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6504 endif
6505 " determine if its in the hiding list or not
6506 let inhidelist= 0
6507 if g:netrw_list_hide != ""
6508 let itemnum = 0
6509 let hidelist= split(g:netrw_list_hide,',')
6510 for hidepat in hidelist
6511 if sfxpat == hidepat
6512 let inhidelist= 1
6513 break
6514 endif
6515 let itemnum= itemnum + 1
6516 endfor
6517 endif
6518" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6519 if inhidelist
6520 " remove sfxpat from list
6521 call remove(hidelist,itemnum)
6522 let g:netrw_list_hide= join(hidelist,",")
6523 elseif g:netrw_list_hide != ""
6524 " append sfxpat to non-empty list
6525 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6526 else
6527 " set hiding list to sfxpat
6528 let g:netrw_list_hide= sfxpat
6529 endif
6530 endfor
6531
6532 " refresh the listing
6533 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006534 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02006535 else
6536 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
6537 endif
6538
6539" call Dret("s:NetrwMarkHideSfx")
6540endfun
6541
6542" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006543" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
6544" Uses the global markfilelist
6545fun! s:NetrwMarkFileGrep(islocal)
6546" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006547 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006548 let curbufnr = bufnr("%")
6549
6550 if exists("s:netrwmarkfilelist")
6551" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006552 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006553 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02006554 else
6555" call Decho('no marked files, using "*"')
6556 let netrwmarkfilelist= "*"
6557 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006558
Bram Moolenaarff034192013-04-24 18:51:19 +02006559 " ask user for pattern
6560 call inputsave()
6561 let pat= input("Enter pattern: ","")
6562 call inputrestore()
6563 let patbang = ""
6564 if pat =~ '^!'
6565 let patbang = "!"
6566 let pat= strpart(pat,2)
6567 endif
6568 if pat =~ '^\i'
6569 let pat = escape(pat,'/')
6570 let pat = '/'.pat.'/'
6571 else
6572 let nonisi = pat[0]
6573 endif
6574
6575 " use vimgrep for both local and remote
6576" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist)
6577 try
6578 exe "keepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
6579 catch /^Vim\%((\a\+)\)\=:E480/
6580 keepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
6581" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
6582 return
6583 endtry
6584 echo "(use :cn, :cp to navigate, :Rex to return)"
6585
6586 2match none
Bram Moolenaara6878372014-03-22 21:02:50 +01006587 keepj call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02006588
6589 if exists("nonisi")
6590 " original, user-supplied pattern did not begin with a character from isident
6591" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg")
6592 if pat =~ nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
6593 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00006594 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006595 endif
6596
6597" call Dret("s:NetrwMarkFileGrep")
6598endfun
6599
6600" ---------------------------------------------------------------------
6601" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
6602" uses the global marked file list
6603" s:netrwmfloc= 0: target directory is remote
6604" = 1: target directory is local
6605fun! s:NetrwMarkFileMove(islocal)
6606" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
6607 let curdir = b:netrw_curdir
6608 let curbufnr = bufnr("%")
6609
6610 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02006611 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaaradc21822011-04-01 18:03:16 +02006612 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006613" call Dret("s:NetrwMarkFileMove")
6614 return
6615 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006616" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6617
Bram Moolenaar446cb832008-06-24 21:56:24 +00006618 if !exists("s:netrwmftgt")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006619 keepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006620" call Dret("s:NetrwMarkFileCopy 0")
6621 return 0
6622 endif
6623" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
6624
6625 if a:islocal && s:netrwmftgt_islocal
6626 " move: local -> local
6627" call Decho("move from local to local")
Bram Moolenaara6878372014-03-22 21:02:50 +01006628" call Decho("local to local move")
Bram Moolenaar13600302014-05-22 18:26:40 +02006629 if !executable(g:netrw_localmovecmd) && g:netrw_localmovecmd !~ '^'.expand("$COMSPEC").'\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01006630 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
6631" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
6632 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006633 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006634 let tgt = shellescape(s:netrwmftgt)
6635" call Decho("tgt<".tgt.">")
6636 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6637 let tgt = substitute(tgt, '/','\\','g')
6638" call Decho("windows exception: tgt<".tgt.">")
6639 if g:netrw_localmovecmd =~ '\s'
6640 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
6641 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
6642 let movecmd = netrw#WinPath(movecmd).movecmdargs
6643" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)")
6644 else
6645 let movecmd = netrw#WinPath(movecmd)
6646" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)")
6647 endif
6648 else
6649 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
6650" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)")
6651 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006652 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02006653" call Decho("system(".movecmd." ".shellescape(fname)." ".tgt.")")
6654 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6655 let fname= substitute(fname,'/','\\','g')
6656 endif
6657 let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".tgt)
6658 if v:shell_error != 0
6659 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006660 break
6661 endif
6662 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006663
6664 elseif a:islocal && !s:netrwmftgt_islocal
6665 " move: local -> remote
6666" call Decho("move from local to remote")
6667" call Decho("copy")
6668 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006669 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006670" call Decho("remove")
6671 for fname in mflist
6672 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6673 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
6674 endfor
6675 unlet mflist
6676
6677 elseif !a:islocal && s:netrwmftgt_islocal
6678 " move: remote -> local
6679" call Decho("move from remote to local")
6680" call Decho("copy")
6681 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006682 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006683" call Decho("remove")
6684 for fname in mflist
6685 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6686 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
6687 endfor
6688 unlet mflist
6689
6690 elseif !a:islocal && !s:netrwmftgt_islocal
6691 " move: remote -> remote
6692" call Decho("move from remote to remote")
6693" call Decho("copy")
6694 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006695 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006696" call Decho("remove")
6697 for fname in mflist
6698 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6699 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
6700 endfor
6701 unlet mflist
6702 endif
6703
6704 " -------
6705 " cleanup
6706 " -------
6707" call Decho("cleanup")
6708
6709 " remove markings from local buffer
6710 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
6711
6712 " refresh buffers
6713 if !s:netrwmftgt_islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006714" call Decho("refresh netrwmftgt<".s:netrwmftgt.">")
6715 keepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006716 endif
6717 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006718" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">")
6719 keepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006720 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006721 if g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006722" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh")
Bram Moolenaara6878372014-03-22 21:02:50 +01006723 keepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006724 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006725
6726" call Dret("s:NetrwMarkFileMove")
6727endfun
6728
6729" ---------------------------------------------------------------------
6730" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
6731" using the hardcopy command. Local marked-file list only.
6732fun! s:NetrwMarkFilePrint(islocal)
6733" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
6734 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006735
6736 " sanity check
6737 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6738 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6739" call Dret("s:NetrwMarkFilePrint")
6740 return
6741 endif
6742" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006743 if exists("s:netrwmarkfilelist_{curbufnr}")
6744 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
6745 let curdir = b:netrw_curdir
6746 call s:NetrwUnmarkList(curbufnr,curdir)
6747 for fname in netrwmarkfilelist
6748 if a:islocal
6749 if g:netrw_keepdir
6750 let fname= s:ComposePath(curdir,fname)
6751 endif
6752 else
6753 let fname= curdir.fname
6754 endif
6755 1split
6756 " the autocmds will handle both local and remote files
Bram Moolenaaradc21822011-04-01 18:03:16 +02006757" call Decho("exe sil e ".escape(fname,' '))
6758 exe "sil e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006759" call Decho("hardcopy")
6760 hardcopy
6761 q
6762 endfor
6763 2match none
6764 endif
6765" call Dret("s:NetrwMarkFilePrint")
6766endfun
6767
6768" ---------------------------------------------------------------------
6769" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
6770" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02006771" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00006772fun! s:NetrwMarkFileRegexp(islocal)
6773" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
6774
6775 " get the regular expression
6776 call inputsave()
6777 let regexp= input("Enter regexp: ","","file")
6778 call inputrestore()
6779
6780 if a:islocal
6781 " get the matching list of files using local glob()
6782" call Decho("handle local regexp")
Bram Moolenaarff034192013-04-24 18:51:19 +02006783 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
6784 let files = glob(s:ComposePath(dirname,regexp))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006785" call Decho("files<".files.">")
6786 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787
6788 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01006789 for fname in filelist
6790" call Decho("fname<".fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006791 keepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006792 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006793
6794 else
6795" call Decho("handle remote regexp")
6796
6797 " convert displayed listing into a filelist
6798 let eikeep = &ei
6799 let areg = @a
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006800 sil keepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01006801 setl ei=all ma
6802" call Decho("setl ei=all ma")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006803 1split
Bram Moolenaaradc21822011-04-01 18:03:16 +02006804 keepj call s:NetrwEnew()
6805 keepj call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006806 sil keepj norm! "ap
6807 keepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006808 let bannercnt= search('^" =====','W')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006809 exe "sil keepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01006810 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00006811 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006812 sil keepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006813 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006814 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006815 sil keepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01006816 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006817 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8d043172014-01-23 14:24:41 +01006818 exe 'sil keepj %s/^'.s:treedepthstring.' //e'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006819 sil! keepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01006820 call histdel("/",-1)
6821 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822 endif
6823 " convert regexp into the more usual glob-style format
6824 let regexp= substitute(regexp,'\*','.*','g')
6825" call Decho("regexp<".regexp.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006826 exe "sil! keepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01006827 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006828 let filelist= getline(1,line("$"))
6829 q!
6830 for filename in filelist
Bram Moolenaaradc21822011-04-01 18:03:16 +02006831 keepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006832 endfor
6833 unlet filelist
6834 let @a = areg
6835 let &ei = eikeep
6836 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006837 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006838
6839" call Dret("s:NetrwMarkFileRegexp")
6840endfun
6841
6842" ---------------------------------------------------------------------
6843" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
6844" Uses the local marked file list.
6845fun! s:NetrwMarkFileSource(islocal)
6846" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
6847 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006848
6849 " sanity check
6850 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6851 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6852" call Dret("s:NetrwMarkFileSource")
6853 return
6854 endif
6855" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006856 if exists("s:netrwmarkfilelist_{curbufnr}")
6857 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
6858 let curdir = b:netrw_curdir
6859 call s:NetrwUnmarkList(curbufnr,curdir)
6860 for fname in netrwmarkfilelist
6861 if a:islocal
6862 if g:netrw_keepdir
6863 let fname= s:ComposePath(curdir,fname)
6864 endif
6865 else
6866 let fname= curdir.fname
6867 endif
6868 " the autocmds will handle sourcing both local and remote files
Bram Moolenaarc236c162008-07-13 17:41:49 +00006869" call Decho("exe so ".fnameescape(fname))
6870 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006871 endfor
6872 2match none
6873 endif
6874" call Dret("s:NetrwMarkFileSource")
6875endfun
6876
6877" ---------------------------------------------------------------------
6878" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
6879" Uses the global markfilelist
6880fun! s:NetrwMarkFileTag(islocal)
6881" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006882 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883 let curdir = b:netrw_curdir
6884 let curbufnr = bufnr("%")
6885
Bram Moolenaarff034192013-04-24 18:51:19 +02006886 " sanity check
6887 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6888 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6889" call Dret("s:NetrwMarkFileTag")
6890 return
6891 endif
6892" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6893
Bram Moolenaar446cb832008-06-24 21:56:24 +00006894 if exists("s:netrwmarkfilelist")
6895" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006896 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006897 call s:NetrwUnmarkAll()
6898
6899 if a:islocal
6900 if executable(g:netrw_ctags)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")")
6902 call system(g:netrw_ctags." ".netrwmarkfilelist)
6903 else
6904 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
6905 endif
6906 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00006907 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01006908 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 let curdir= b:netrw_curdir
6910 1split
6911 e tags
6912 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
6913" call Decho("curdir<".curdir."> path<".path.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006914 exe 'keepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006915 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 wq!
6917 endif
6918 2match none
6919 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 endif
6922
6923" call Dret("s:NetrwMarkFileTag")
6924endfun
6925
6926" ---------------------------------------------------------------------
6927" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
6928" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02006929" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02006931" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932fun! s:NetrwMarkFileTgt(islocal)
6933" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006934 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935 let curdir = b:netrw_curdir
6936 let hadtgt = exists("s:netrwmftgt")
6937 if !exists("w:netrw_bannercnt")
6938 let w:netrw_bannercnt= b:netrw_bannercnt
6939 endif
6940
6941 " set up target
6942 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02006943 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
6944 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
6945" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target")
6946 unlet s:netrwmftgt s:netrwmftgt_islocal
6947 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006948 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02006949 endif
6950 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006951 call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02006952" call Dret("s:NetrwMarkFileTgt : removed target")
6953 return
6954 else
6955 let s:netrwmftgt= b:netrw_curdir
6956" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">")
6957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958
6959 else
6960 " get word under cursor.
6961 " * If directory, use it for the target.
6962 " * If file, use b:netrw_curdir for the target
6963 let curword= s:NetrwGetWord()
6964 let tgtdir = s:ComposePath(curdir,curword)
6965 if a:islocal && isdirectory(tgtdir)
6966 let s:netrwmftgt = tgtdir
6967" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">")
6968 elseif !a:islocal && tgtdir =~ '/$'
6969 let s:netrwmftgt = tgtdir
6970" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">")
6971 else
6972 let s:netrwmftgt = curdir
6973" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">")
6974 endif
6975 endif
6976 if a:islocal
6977 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
6978 let s:netrwmftgt= simplify(s:netrwmftgt)
6979" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">")
6980 endif
6981 if g:netrw_cygwin
6982 let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','')
6983 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
6984 endif
6985 let s:netrwmftgt_islocal= a:islocal
6986
Bram Moolenaar5c736222010-01-06 20:54:52 +01006987 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006988 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006989 endif
6990 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006991 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006992 if !hadtgt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006993 sil! keepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994 endif
6995
6996" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
6997endfun
6998
6999" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007000" s:NetrwOpenFile: query user for a filename and open it {{{2
7001fun! s:NetrwOpenFile(islocal)
7002" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007003 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007004 call inputsave()
7005 let fname= input("Enter filename: ")
7006 call inputrestore()
7007 if fname !~ '[/\\]'
7008 if exists("b:netrw_curdir")
7009 if exists("g:netrw_quiet")
7010 let netrw_quiet_keep = g:netrw_quiet
7011 endif
7012 let g:netrw_quiet = 1
7013 if b:netrw_curdir =~ '/$'
7014 exe "e ".fnameescape(b:netrw_curdir.fname)
7015 else
7016 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7017 endif
7018 if exists("netrw_quiet_keep")
7019 let g:netrw_quiet= netrw_quiet_keep
7020 else
7021 unlet g:netrw_quiet
7022 endif
7023 endif
7024 else
7025 exe "e ".fnameescape(fname)
7026 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007027 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007028" call Dret("s:NetrwOpenFile")
7029endfun
7030
7031" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007032" s:NetrwUnmarkList: delete local marked file lists and remove their contents from the global marked-file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007033" User access provided by the <mu> mapping. (see :help netrw-mu)
7034" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007035fun! s:NetrwUnmarkList(curbufnr,curdir)
7036" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7037
7038 " remove all files in local marked-file list from global list
7039 if exists("s:netrwmarkfilelist_{a:curbufnr}")
7040 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7041 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7042 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7043 call remove(s:netrwmarkfilelist,idx) " remove from global list
7044 endfor
7045 if s:netrwmarkfilelist == []
7046 unlet s:netrwmarkfilelist
7047 endif
7048
7049 " getting rid of the local marked-file lists is easy
7050 unlet s:netrwmarkfilelist_{a:curbufnr}
7051 endif
7052 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7053 unlet s:netrwmarkfilemtch_{a:curbufnr}
7054 endif
7055 2match none
7056" call Dret("s:NetrwUnmarkList")
7057endfun
7058
7059" ---------------------------------------------------------------------
7060" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7061fun! s:NetrwUnmarkAll()
7062" call Dfunc("s:NetrwUnmarkAll()")
7063 if exists("s:netrwmarkfilelist")
7064 unlet s:netrwmarkfilelist
7065 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007066 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 2match none
7068" call Dret("s:NetrwUnmarkAll")
7069endfun
7070
7071" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007072" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007073fun! s:NetrwUnmarkAll2()
7074" call Dfunc("s:NetrwUnmarkAll2()")
7075 redir => netrwmarkfilelist_let
7076 let
7077 redir END
7078 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
7079 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
7080 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7081 for flist in netrwmarkfilelist_list
7082 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7083 unlet s:netrwmarkfilelist_{curbufnr}
7084 unlet s:netrwmarkfilemtch_{curbufnr}
7085 endfor
7086" call Dret("s:NetrwUnmarkAll2")
7087endfun
7088
7089" ---------------------------------------------------------------------
7090" s:NetrwUnMarkFile: {{{2
7091fun! s:NetrwUnMarkFile(islocal)
7092" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007093 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 let curbufnr = bufnr("%")
7095
7096 " unmark marked file list (although I expect s:NetrwUpload()
7097 " to do it, I'm just making sure)
7098 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7099" call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%"))
7100 unlet s:netrwmarkfilelist
7101 unlet s:netrwmarkfilelist_{curbufnr}
7102 unlet s:netrwmarkfilemtch_{curbufnr}
7103 2match none
7104 endif
7105
7106" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007107 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007108" call Dret("s:NetrwUnMarkFile")
7109endfun
7110
7111" ---------------------------------------------------------------------
7112" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7113fun! s:NetrwMenu(domenu)
7114
7115 if !exists("g:NetrwMenuPriority")
7116 let g:NetrwMenuPriority= 80
7117 endif
7118
Bram Moolenaaradc21822011-04-01 18:03:16 +02007119 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007120" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7121
7122 if !exists("s:netrw_menu_enabled") && a:domenu
7123" call Decho("initialize menu")
7124 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007125 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7126 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7127 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7128 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7129 if g:netrw_dirhistmax > 0
7130 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7131 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7132 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7133 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7134 else
7135 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7136 endif
7137 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7138 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7139 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7140 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7141 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7142 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7143 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7144 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7145 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7146 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7147 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7148 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7149 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7150 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7151 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
7152 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7153 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7154 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7155 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7156 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7157 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7158 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7159 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7160 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7161 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7162 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7163 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7164 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7165 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7166 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7167 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7168 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7169 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7170 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7171 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7172 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7173 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7174 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7175 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7176 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7177 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7178 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7179 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7180 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7181 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
7182 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
7183 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
7184 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7185 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
7186 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
7187 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
7188 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7189 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007190 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007191 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7192 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007193
7194 elseif !a:domenu
7195 let s:netrwcnt = 0
7196 let curwin = winnr()
7197 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
7198 exe curwin."wincmd w"
7199
7200 if s:netrwcnt <= 1
7201" call Decho("clear menus")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007202 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaaradc21822011-04-01 18:03:16 +02007203" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007204 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007205 endif
7206 endif
7207" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007208 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007209 endif
7210
7211endfun
7212
7213" ---------------------------------------------------------------------
7214" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7215" Used by the O maps (as <SID>NetrwObtain())
7216fun! s:NetrwObtain(islocal)
7217" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7218
Bram Moolenaar97d62492012-11-15 21:28:22 +01007219 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007220 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007221 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007222 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007223 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7224 else
Bram Moolenaara6878372014-03-22 21:02:50 +01007225 call netrw#Obtain(a:islocal,expand("<cWORD>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007226 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007227 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007228
7229" call Dret("NetrwObtain")
7230endfun
7231
7232" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7234" If there's only one window, then the window will first be split.
7235" Returns:
7236" choice = 0 : didn't have to choose
7237" choice = 1 : saved modified file in window first
7238" choice = 2 : didn't save modified file, opened window
7239" choice = 3 : cancel open
7240fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007241" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
Bram Moolenaar97d62492012-11-15 21:28:22 +01007243 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01007245 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246
7247 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01007248 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249 let lastwinnr = winnr("$")
7250 let curword = s:NetrwGetWord()
7251 let choice = 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01007252 let s:treedir = s:NetrwTreeDir()
Bram Moolenaara6878372014-03-22 21:02:50 +01007253 let curdir = s:treedir
7254" call Decho("winnr($)#".lastwinnr." curword<".curword.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255
Bram Moolenaar8d043172014-01-23 14:24:41 +01007256 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007257 if lastwinnr == 1
7258 " if only one window, open a new one first
Bram Moolenaara6878372014-03-22 21:02:50 +01007259" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007260 if g:netrw_preview
Bram Moolenaar15146672011-10-20 22:22:38 +02007261 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007262" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007263 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007264 else
Bram Moolenaar15146672011-10-20 22:22:38 +02007265 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007266" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007267 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007269 let didsplit = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007270" call Decho("did split")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271
7272 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007273 keepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007274 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01007275 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 wincmd p
Bram Moolenaara6878372014-03-22 21:02:50 +01007277" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007278
7279 " prevwinnr: the window number of the "prev" window
7280 " prevbufnr: the buffer number of the buffer in the "prev" window
7281 " bnrcnt : the qty of windows open on the "prev" buffer
7282 let prevwinnr = winnr()
7283 let prevbufnr = bufnr("%")
7284 let prevbufname = bufname("%")
7285 let prevmod = &mod
7286 let bnrcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02007287 keepj call s:RestoreBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01007288" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007289
7290 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 " and it doesn't appear in any other extant window, then ask the
7292 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01007293 if prevmod
Bram Moolenaara6878372014-03-22 21:02:50 +01007294" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01007295 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01007296" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007297 exe prevwinnr."wincmd w"
7298
7299 if bnrcnt == 1 && &hidden == 0
7300 " only one copy of the modified buffer in a window, and
7301 " hidden not set, so overwriting will lose the modified file. Ask first...
7302 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
7303" call Decho("(NetrwPrevWinOpen) prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr())
7304 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007305
7306 if choice == 1
7307 " Yes -- write file & then browse
7308 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007309 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00007310 if v:errmsg != ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01007311 call netrw#ErrorMsg(s:ERROR,"unable to write <".prevbufname.">!",30)
7312 exe origwin."wincmd w"
7313 let &ei = eikeep
7314 let @@ = ykeep
7315" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007316 return choice
7317 endif
7318
7319 elseif choice == 2
7320 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara6878372014-03-22 21:02:50 +01007321" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007322 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007323
7324 else
7325 " Cancel -- don't do this
Bram Moolenaara6878372014-03-22 21:02:50 +01007326" call Decho("cancel, don't browse, switch to win#".origwin)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007327 exe origwin."wincmd w"
7328 let &ei= eikeep
7329 let @@ = ykeep
7330" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007331 return choice
7332 endif
7333 endif
7334 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007335 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007336 endif
7337
7338 " restore b:netrw_curdir (window split/enew may have lost it)
7339 let b:netrw_curdir= curdir
7340 if a:islocal < 2
7341 if a:islocal
7342 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
7343 else
7344 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
7345 endif
7346 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007347 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01007348" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349 return choice
7350endfun
7351
7352" ---------------------------------------------------------------------
7353" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
7354" Always assumed to be local -> remote
7355" call s:NetrwUpload(filename, target)
7356" call s:NetrwUpload(filename, target, fromdirectory)
7357fun! s:NetrwUpload(fname,tgt,...)
7358" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
7359
7360 if a:tgt =~ '^\a\+://'
7361 let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','')
7362 else
7363 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
7364 endif
7365" call Decho("tgtdir<".tgtdir.">")
7366
7367 if a:0 > 0
7368 let fromdir= a:1
7369 else
7370 let fromdir= getcwd()
7371 endif
7372" call Decho("fromdir<".fromdir.">")
7373
7374 if type(a:fname) == 1
7375 " handle uploading a single file using NetWrite
7376" call Decho("handle uploading a single file via NetWrite")
7377 1split
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007378" call Decho("exe e ".fnameescape(a:fname))
7379 exe "e ".fnameescape(a:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines")
7381 if a:tgt =~ '/$'
7382 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00007383" call Decho("exe w! ".fnameescape(wfname))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007384 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007385 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007386" call Decho("writing local->remote: exe w ".fnameescape(a:tgt))
7387 exe "w ".fnameescape(a:tgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388" call Decho("done writing local->remote")
7389 endif
7390 q!
7391
7392 elseif type(a:fname) == 3
7393 " handle uploading a list of files via scp
7394" call Decho("handle uploading a list of files via scp")
7395 let curdir= getcwd()
7396 if a:tgt =~ '^scp:'
Bram Moolenaara6878372014-03-22 21:02:50 +01007397 call s:NetrwLcd(fromdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007398 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
7399 let args = join(map(filelist,"shellescape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 if exists("g:netrw_port") && g:netrw_port != ""
7401 let useport= " ".g:netrw_scpport." ".g:netrw_port
7402 else
7403 let useport= ""
7404 endif
7405 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
7406 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00007407" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1))
7408 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1)
Bram Moolenaara6878372014-03-22 21:02:50 +01007409 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007410
7411 elseif a:tgt =~ '^ftp:'
7412 call s:NetrwMethod(a:tgt)
7413
7414 if b:netrw_method == 2
7415 " handle uploading a list of files via ftp+.netrc
7416 let netrw_fname = b:netrw_fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007417 sil keepj new
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418" call Decho("filter input window#".winnr())
7419
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007420 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00007421" call Decho("filter input: ".getline('$'))
7422
7423 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007424 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007425" call Decho("filter input: ".getline('$'))
7426 endif
7427
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007428 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007429" call Decho("filter input: ".getline('$'))
7430
Bram Moolenaaradc21822011-04-01 18:03:16 +02007431 if tgtdir == ""
7432 let tgtdir= '/'
7433 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007434 keepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007435" call Decho("filter input: ".getline('$'))
7436
7437 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007438 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007439" call Decho("filter input: ".getline('$'))
7440 endfor
7441
7442 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007443" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
7444 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445 else
7446" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02007447" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
7448 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 endif
7450 " 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 +02007451 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007452 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007453 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7454 call netrw#ErrorMsg(s:ERROR,getline(1),14)
7455 else
7456 bw!|q
7457 endif
7458
7459 elseif b:netrw_method == 3
7460 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
7461 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +02007462 keepj call s:SaveBufVars()|sil keepj new|keepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007463 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007464 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00007465
7466 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007467 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00007468" call Decho("filter input: ".getline('$'))
7469 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007470 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00007471" call Decho("filter input: ".getline('$'))
7472 endif
7473
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007474 if exists("g:netrw_uid") && g:netrw_uid != ""
7475 if exists("g:netrw_ftp") && g:netrw_ftp == 1
7476 keepj put =g:netrw_uid
7477" call Decho("filter input: ".getline('$'))
7478 if exists("s:netrw_passwd")
7479 keepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
7480 endif
7481" call Decho("filter input: ".getline('$'))
7482 elseif exists("s:netrw_passwd")
7483 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
7484" call Decho("filter input: ".getline('$'))
7485 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486 endif
7487
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007488 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007489" call Decho("filter input: ".getline('$'))
7490
7491 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007492 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007493" call Decho("filter input: ".getline('$'))
7494 endif
7495
7496 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007497 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007498" call Decho("filter input: ".getline('$'))
7499 endif
7500
7501 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007502 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503" call Decho("filter input: ".getline('$'))
7504 endfor
7505
7506 " perform ftp:
7507 " -i : turns off interactive prompting from ftp
7508 " -n unix : DON'T use <.netrc>, even though it exists
7509 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007510 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007511" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
7512 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 " 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 +02007514 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007515 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7517 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02007518 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00007519 call netrw#ErrorMsg(s:ERROR,getline(1),15)
7520 let &debug = debugkeep
7521 let mod = 1
7522 else
7523 bw!|q
7524 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007525 elseif !exists("b:netrw_method") || b:netrw_method < 0
7526" call Dfunc("netrw#NetrwUpload : unsupported method")
7527 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007528 endif
7529 else
7530 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
7531 endif
7532 endif
7533
7534" call Dret("s:NetrwUpload")
7535endfun
7536
7537" ---------------------------------------------------------------------
7538" s:NetrwPreview: {{{2
7539fun! s:NetrwPreview(path) range
7540" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007541 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02007542 keepj call s:NetrwOptionSave("s:")
7543 keepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544 if has("quickfix")
7545 if !isdirectory(a:path)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007546 if g:netrw_preview && !g:netrw_alto
Bram Moolenaar15146672011-10-20 22:22:38 +02007547 let pvhkeep = &pvh
7548 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
7549 let &pvh = winwidth(0) - winsz
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007550 endif
7551 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
7552 if exists("pvhkeep")
7553 let &pvh= pvhkeep
7554 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007556 keepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007557 endif
7558 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007559 keepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007560 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007561 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007562 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007563" call Dret("NetrwPreview")
7564endfun
7565
7566" ---------------------------------------------------------------------
7567" s:NetrwRefresh: {{{2
7568fun! s:NetrwRefresh(islocal,dirname)
7569" call Dfunc("NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
7570 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02007571 setl ma noro
7572" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007573" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007574 let ykeep = @@
Bram Moolenaar13600302014-05-22 18:26:40 +02007575
7576 " save the cursor position before refresh.
Bram Moolenaara6878372014-03-22 21:02:50 +01007577 let screenposn = netrw#SavePosn()
Bram Moolenaar13600302014-05-22 18:26:40 +02007578" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">")
Bram Moolenaarff034192013-04-24 18:51:19 +02007579" call Decho("clearing buffer prior to refresh")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007580 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00007581 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02007582 keepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007584 keepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02007586
7587 " restore position
Bram Moolenaara6878372014-03-22 21:02:50 +01007588 keepj call netrw#RestorePosn(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007589
7590 " restore file marks
7591 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
7592" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
7593 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
7594 else
7595" call Decho("2match none")
7596 2match none
7597 endif
7598
Bram Moolenaar97d62492012-11-15 21:28:22 +01007599" restore
7600 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601" call Dret("NetrwRefresh")
7602endfun
7603
7604" ---------------------------------------------------------------------
7605" s:NetrwRefreshDir: refreshes a directory by name {{{2
7606" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01007607" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007608fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007609" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007610 if g:netrw_fastbrowse == 0
7611 " slowest mode (keep buffers refreshed, local or remote)
7612" call Decho("slowest mode: keep buffers refreshed, local or remote")
7613 let tgtwin= bufwinnr(a:dirname)
7614" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin)
7615
7616 if tgtwin > 0
7617 " tgtwin is being displayed, so refresh it
7618 let curwin= winnr()
7619" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")")
7620 exe tgtwin."wincmd w"
Bram Moolenaaradc21822011-04-01 18:03:16 +02007621 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007622 exe curwin."wincmd w"
7623
7624 elseif bufnr(a:dirname) > 0
7625 let bn= bufnr(a:dirname)
7626" call Decho("bd bufnr(".a:dirname.")=".bn)
Bram Moolenaaradc21822011-04-01 18:03:16 +02007627 exe "sil bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00007628 endif
7629
7630 elseif g:netrw_fastbrowse <= 1
7631" call Decho("medium-speed mode: refresh local buffers only")
Bram Moolenaara6878372014-03-22 21:02:50 +01007632 keepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007633 endif
7634" call Dret("s:NetrwRefreshDir")
7635endfun
7636
7637" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02007638" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
7639" window number to do its editing in.
7640" Supports [count]C where the count, if present, is used to specify
7641" a window to use for editing via the <cr> mapping.
7642fun! s:NetrwSetChgwin()
7643" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
7644 if v:count > 0
7645 let g:netrw_chgwin= v:count
7646 else
7647 let g:netrw_chgwin= winnr()
7648 endif
7649" call Dret("s:NetrwSetChgwin")
7650endfun
7651
7652" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007653" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
7654" What this function does is to compute a priority for the patterns
7655" in the g:netrw_sort_sequence. It applies a substitute to any
7656" "files" that satisfy each pattern, putting the priority / in
7657" front. An "*" pattern handles the default priority.
7658fun! s:NetrwSetSort()
7659" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007660 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007661 if w:netrw_liststyle == s:LONGLIST
7662 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
7663 else
7664 let seqlist = g:netrw_sort_sequence
7665 endif
7666 " sanity check -- insure that * appears somewhere
7667 if seqlist == ""
7668 let seqlist= '*'
7669 elseif seqlist !~ '\*'
7670 let seqlist= seqlist.',*'
7671 endif
7672 let priority = 1
7673 while seqlist != ""
7674 if seqlist =~ ','
7675 let seq = substitute(seqlist,',.*$','','e')
7676 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
7677 else
7678 let seq = seqlist
7679 let seqlist = ""
7680 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007681 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01007682 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007683 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01007684 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007685 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01007686 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007687 endif
7688" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
7689
7690 " sanity check
7691 if w:netrw_bannercnt > line("$")
7692 " apparently no files were left after a Hiding pattern was used
7693" call Dret("SetSort : no files left after hiding")
7694 return
7695 endif
7696 if seq == '*'
7697 let starpriority= spriority
7698 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007699 exe 'sil keepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007700 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007701 " sometimes multiple sorting patterns will match the same file or directory.
7702 " The following substitute is intended to remove the excess matches.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007703 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 Moolenaaradc21822011-04-01 18:03:16 +02007704 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007705 endif
7706 let priority = priority + 1
7707 endwhile
7708 if exists("starpriority")
Bram Moolenaara6878372014-03-22 21:02:50 +01007709 exe 'sil keepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007710 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007711 endif
7712
7713 " Following line associated with priority -- items that satisfy a priority
7714 " pattern get prefixed by ###/ which permits easy sorting by priority.
7715 " Sometimes files can satisfy multiple priority patterns -- only the latest
7716 " priority pattern needs to be retained. So, at this point, these excess
7717 " priority prefixes need to be removed, but not directories that happen to
7718 " be just digits themselves.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007719 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007720 keepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007721 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722
7723" call Dret("SetSort")
7724endfun
7725
Bram Moolenaarff034192013-04-24 18:51:19 +02007726" ---------------------------------------------------------------------
7727" s:NetrwSetTgt: sets the target to the specified choice index {{{2
7728" Implements [count]Tb (bookhist<b>)
7729" [count]Th (bookhist<h>)
7730" See :help netrw-qb for how to make the choice.
7731fun! s:NetrwSetTgt(bookhist,choice)
7732" call Dfunc("s:NetrwSetTgt(bookhist<".a:bookhist."> choice#".a:choice.")")
7733
7734 if a:bookhist == 'b'
7735 " supports choosing a bookmark as a target using a qb-generated list
7736 let choice= a:choice - 1
7737 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01007738 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02007739 else
7740 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
7741 endif
7742
7743 elseif a:bookhist == 'h'
7744 " supports choosing a history stack entry as a target using a qb-generated list
7745 let choice= (a:choice % g:netrw_dirhistmax) + 1
7746 if exists("g:netrw_dirhist_".choice)
7747 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01007748 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02007749 else
7750 echomsg "Sorry, history#".a:choice." not available!"
7751 endif
7752 endif
7753
7754" call Dret("s:NetrwSetTgt")
7755endfun
7756
Bram Moolenaar446cb832008-06-24 21:56:24 +00007757" =====================================================================
7758" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
7759fun! s:NetrwSortStyle(islocal)
7760" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007761 keepj call s:NetrwSaveWordPosn()
Bram Moolenaara6878372014-03-22 21:02:50 +01007762 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007763
7764 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 +02007765 keepj norm! 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02007766 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007767 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007768
7769" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
7770endfun
7771
7772" ---------------------------------------------------------------------
7773" s:NetrwSplit: mode {{{2
7774" =0 : net and o
7775" =1 : net and t
7776" =2 : net and v
7777" =3 : local and o
7778" =4 : local and t
7779" =5 : local and v
7780fun! s:NetrwSplit(mode)
7781" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
7782
Bram Moolenaar97d62492012-11-15 21:28:22 +01007783 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 call s:SaveWinVars()
7785
7786 if a:mode == 0
7787 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02007788 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02007789 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007790" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007791 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007792 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007793 keepj call s:RestoreWinVars()
7794 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007795 unlet s:didsplit
7796
7797 elseif a:mode == 1
7798 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01007799 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800" call Decho("tabnew")
7801 tabnew
7802 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007803 keepj call s:RestoreWinVars()
7804 keepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805 unlet s:didsplit
7806
7807 elseif a:mode == 2
7808 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02007809 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02007810 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007811" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007812 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007814 keepj call s:RestoreWinVars()
7815 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 unlet s:didsplit
7817
7818 elseif a:mode == 3
7819 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02007820 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02007821 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007822" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007823 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007825 keepj call s:RestoreWinVars()
7826 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827 unlet s:didsplit
7828
7829 elseif a:mode == 4
7830 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007832 let eikeep = &ei
7833 let netrw_winnr = winnr()
7834 let netrw_line = line(".")
7835 let netrw_col = virtcol(".")
7836 keepj norm! H0
7837 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01007838 setl ei=all
Bram Moolenaar8d043172014-01-23 14:24:41 +01007839 exe "keepj norm! ".netrw_hline."G0z\<CR>"
7840 exe "keepj norm! ".netrw_line."G0".netrw_col."\<bar>"
7841 let &ei= eikeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01007842 let netrw_curdir= s:NetrwTreeDir()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843" call Decho("tabnew")
7844 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01007845 let b:netrw_curdir = netrw_curdir
7846 let s:didsplit = 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007847 keepj call s:RestoreWinVars()
7848 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01007849 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01007850 setl ei=all
Bram Moolenaar8d043172014-01-23 14:24:41 +01007851 exe "keepj norm! ".netrw_hline."G0z\<CR>"
7852 exe "keepj norm! ".netrw_line."G0".netrw_col."\<bar>"
7853 let &ei= eikeep
7854 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855 unlet s:didsplit
7856
7857 elseif a:mode == 5
7858 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02007859 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02007860 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007861" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007862 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007864 keepj call s:RestoreWinVars()
7865 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 unlet s:didsplit
7867
7868 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007869 keepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007870 endif
7871
Bram Moolenaar97d62492012-11-15 21:28:22 +01007872 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007873" call Dret("s:NetrwSplit")
7874endfun
7875
7876" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007877" s:NetrwTgtMenu: {{{2
7878fun! s:NetrwTgtMenu()
7879 if !exists("s:netrw_menucnt")
7880 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007882" call Dfunc("s:NetrwTgtMenu()")
7883
7884 " the following test assures that gvim is running, has menus available, and has menus enabled.
7885 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
7886 if exists("g:NetrwTopLvlMenu")
7887" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
7888 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
7889 endif
7890 if !exists("s:netrw_initbookhist")
7891 call s:NetrwBookHistRead()
7892 endif
7893
7894 " target bookmarked places
7895 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
7896" call Decho("installing bookmarks as easy targets")
7897 let cnt= 1
7898 for bmd in g:netrw_bookmarklist
7899 let ebmd= escape(bmd,g:netrw_menu_escape)
7900 " show bookmarks for goto menu
7901" call Decho("menu: Targets: ".bmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01007902 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02007903 let cnt= cnt + 1
7904 endfor
7905 endif
7906
7907 " target directory browsing history
7908 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
7909" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")")
7910 let histcnt = 1
7911 while histcnt <= g:netrw_dirhistmax
7912 let priority = g:netrw_dirhist_cnt + histcnt
7913 if exists("g:netrw_dirhist_{histcnt}")
7914 let histentry = g:netrw_dirhist_{histcnt}
7915 let ehistentry = escape(histentry,g:netrw_menu_escape)
7916" call Decho("menu: Targets: ".histentry)
Bram Moolenaara6878372014-03-22 21:02:50 +01007917 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02007918 endif
7919 let histcnt = histcnt + 1
7920 endwhile
7921 endif
7922 endif
7923" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924endfun
7925
7926" ---------------------------------------------------------------------
7927" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
7928" (full path directory with trailing slash returned)
7929fun! s:NetrwTreeDir()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007930" call Dfunc("s:NetrwTreeDir() getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931
Bram Moolenaar8d043172014-01-23 14:24:41 +01007932 if exists("s:treedir")
7933 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
7934 let treedir= s:treedir
7935 unlet s:treedir
7936" call Dret("s:NetrwTreeDir ".treedir)
7937 return treedir
7938 endif
7939 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
7940 let b:netrw_curdir= getcwd()
7941 endif
7942 let treedir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01007943" call Decho("set initial treedir<".treedir.">")
7944 let s:treecurpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007945
7946 if w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01007947" call Decho("w:netrw_liststyle is TREELIST:")
7948" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007949
7950 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 if getline('.') =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01007952" call Decho("extract tree subdirectory from current line")
7953 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01007954" call Decho("treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007955 else
Bram Moolenaara6878372014-03-22 21:02:50 +01007956" call Decho("do not extract tree subdirectory from current line and set treedir to empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957 let treedir= ""
7958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959
7960 " detect user attempting to close treeroot
Bram Moolenaara6878372014-03-22 21:02:50 +01007961" call Decho("win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
7962" call Decho("getline(".line(".").")<".getline('.').'> '.((getline('.') =~ '^'.s:treedepthstring)? '=~' : '!~').' ^'.s:treedepthstring)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007963 if getline('.') !~ '^'.s:treedepthstring && getline('.') != '..'
7964" call Decho("user may have attempted to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965 " now force a refresh
Bram Moolenaara6878372014-03-22 21:02:50 +01007966" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007967 sil! keepj %d
Bram Moolenaar8d043172014-01-23 14:24:41 +01007968" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01007970" else " Decho
7971" call Decho("user did not attempt to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007972 endif
7973
Bram Moolenaara6878372014-03-22 21:02:50 +01007974 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007976
7977 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978 let treedir= substitute(treedir,'//$','/','')
7979
Bram Moolenaar8d043172014-01-23 14:24:41 +01007980" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981 return treedir
7982endfun
7983
7984" ---------------------------------------------------------------------
7985" s:NetrwTreeDisplay: recursive tree display {{{2
7986fun! s:NetrwTreeDisplay(dir,depth)
7987" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
7988
7989 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02007990 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991
7992 " install ../ and shortdir
7993 if a:depth == ""
7994 call setline(line("$")+1,'../')
7995" call Decho("setline#".line("$")." ../ (depth is zero)")
7996 endif
7997 if a:dir =~ '^\a\+://'
7998 if a:dir == w:netrw_treetop
7999 let shortdir= a:dir
8000 else
8001 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8002 endif
8003 call setline(line("$")+1,a:depth.shortdir)
8004 else
8005 let shortdir= substitute(a:dir,'^.*/','','e')
8006 call setline(line("$")+1,a:depth.shortdir.'/')
8007 endif
8008" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">")
8009
8010 " append a / to dir if its missing one
8011 let dir= a:dir
8012 if dir !~ '/$'
8013 let dir= dir.'/'
8014 endif
8015
8016 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008017 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018
8019" call Decho("display subtrees with depth<".depth."> and current leaves")
8020 for entry in w:netrw_treedict[a:dir]
8021 let direntry= substitute(dir.entry,'/$','','e')
8022" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">")
8023 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
8024" call Decho("<".direntry."> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008025 keepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
8027" call Decho("<".direntry."/> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008028 keepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029 else
8030" call Decho("<".entry."> is not a key in treedict (no subtree)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008031 sil! keepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 endif
8033 endfor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008034
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035" call Dret("NetrwTreeDisplay")
8036endfun
8037
8038" ---------------------------------------------------------------------
8039" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
8040fun! s:NetrwTreeListing(dirname)
8041 if w:netrw_liststyle == s:TREELIST
8042" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01008043" call Decho("curdir<".a:dirname.">")
8044" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"))
8045" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046
8047 " update the treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01008048" call Decho("update the treetop")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049 if !exists("w:netrw_treetop")
8050 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01008051" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
8053 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01008054" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 endif
8056
8057 " insure that we have at least an empty treedict
8058 if !exists("w:netrw_treedict")
8059 let w:netrw_treedict= {}
8060 endif
8061
8062 " update the directory listing for the current directory
Bram Moolenaara6878372014-03-22 21:02:50 +01008063" call Decho("updating dictionary with ".a:dirname.":[..directory listing..]")
8064" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008065 exe "sil! keepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008067" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008068 exe "sil! keepj ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069
8070 " if past banner, record word
8071 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8072 let fname= expand("<cword>")
8073 else
8074 let fname= ""
8075 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008076" call Decho("fname<".fname.">")
8077" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078
8079 " display from treetop on down
Bram Moolenaaradc21822011-04-01 18:03:16 +02008080 keepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008081" call Decho("s:NetrwTreeDisplay) setl noma nomod ro")
8082
8083 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8084 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01008085" call Decho("deleting blank line")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008086 1d
8087 endwhile
8088
Bram Moolenaar13600302014-05-22 18:26:40 +02008089 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090
8091" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008092 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008093 endif
8094endfun
8095
8096" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01008097" s:NetrwTreePath: returns path to current file in tree listing {{{2
8098" Normally, treetop is w:netrw_treetop, but a
8099" user of the function ( netrw#SetTreetop() )
8100" wipes that out prior to calling this function
8101fun! s:NetrwTreePath(treetop)
8102" call Dfunc("s:NetrwTreePath() line#".line(".")."<".getline(".").">")
8103 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
8104" call Decho("(s:NetrwTreePath) depth<".depth."> 1st subst")
8105 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8106" call Decho("(s:NetrwTreePath) depth<".depth."> 2nd subst (first depth removed)")
8107 if getline('.') =~ '/$'
8108" call Decho("extract tree directory from current line")
8109 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8110" call Decho("(s:NetrwTreePath) treedir<".treedir.">")
8111 else
8112" call Decho("(s:NetrwTreePath) do not extract tree directory from current line and set treedir to empty")
8113 let treedir= ""
8114 endif
8115 " construct treedir by searching backwards at correct depth
8116" call Decho("(s:NetrwTreePath) construct treedir by searching backwards for correct depth")
8117" call Decho("(s:NetrwTreePath) initial treedir<".treedir."> depth<".depth.">")
8118 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
8119 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
8120 let treedir= dirname.treedir
8121 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8122" call Decho("(s:NetrwTreePath) constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">")
8123 endwhile
8124 if a:treetop =~ '/$'
8125 let treedir= a:treetop.treedir
8126 else
8127 let treedir= a:treetop.'/'.treedir
8128 endif
8129 let treedir= substitute(treedir,'//$','/','')
8130" call Dret("s:NetrwTreePath <".treedir.">")
8131 return treedir
8132endfun
8133
8134" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135" s:NetrwWideListing: {{{2
8136fun! s:NetrwWideListing()
8137
8138 if w:netrw_liststyle == s:WIDELIST
8139" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
8140 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008141 " cpf: characters per filename
8142 " fpl: filenames per line
8143 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02008144 setl ma noro
8145" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 let b:netrw_cpf= 0
8147 if line("$") >= w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008148 exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008149 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008150 else
8151" call Dret("NetrwWideListing")
8152 return
8153 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008154 let b:netrw_cpf= b:netrw_cpf + 2
8155" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156
8157 " determine qty files per line (fpl)
8158 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
8159 if w:netrw_fpl <= 0
8160 let w:netrw_fpl= 1
8161 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008162" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008163
8164 " make wide display
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008165 exe 'sil keepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008166 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
8168 let newcolstart = w:netrw_bannercnt + fpc
8169 let newcolend = newcolstart + fpc - 1
8170" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008171 if has("clipboard")
8172 sil! let keepregstar = @*
8173 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174 while line("$") >= newcolstart
8175 if newcolend > line("$") | let newcolend= line("$") | endif
8176 let newcolqty= newcolend - newcolstart
8177 exe newcolstart
8178 if newcolqty == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008179 exe "sil! keepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008181 exe "sil! keepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008182 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008183 exe "sil! keepj ".newcolstart.','.newcolend.'d'
8184 exe 'sil! keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01008186 if has("clipboard")
8187 sil! let @*= keepregstar
8188 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008189 exe "sil! keepj ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008190 keepj call histdel("/",-1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008191 exe "nmap <buffer> <silent> w /^\\\\|\\s\\s\\zs\\S/\<cr>"
8192 exe "nmap <buffer> <silent> b ?^\\\\|\\s\\s\\zs\\S?\<cr>"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008193" call Decho("NetrwWideListing) setl noma nomod ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02008194 exe "setl ".g:netrw_bufsettings
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008195" call Decho("(NetrwWideListing) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008197 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008198 else
8199 if hasmapto("w","n")
8200 sil! nunmap <buffer> w
8201 endif
8202 if hasmapto("b","n")
8203 sil! nunmap <buffer> b
8204 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205 endif
8206
8207endfun
8208
8209" ---------------------------------------------------------------------
8210" s:PerformListing: {{{2
8211fun! s:PerformListing(islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008212" call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01008213" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214
Bram Moolenaar15146672011-10-20 22:22:38 +02008215 " set up syntax highlighting {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008216" call Decho("set up syntax highlighting")
Bram Moolenaar15146672011-10-20 22:22:38 +02008217 if has("syntax")
8218 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaara6878372014-03-22 21:02:50 +01008219" call Decho("but g:syntax_on".(exists("g:syntax_on")? "=".g:syntax_on : "<doesn't exist>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008220 setl ft=
Bram Moolenaar15146672011-10-20 22:22:38 +02008221 elseif &ft != "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008222" call Decho("setl ft=netrw")
Bram Moolenaarff034192013-04-24 18:51:19 +02008223 setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02008224 endif
8225 endif
8226
Bram Moolenaaradc21822011-04-01 18:03:16 +02008227 keepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01008228 setl noro ma
8229" call Decho("setl noro ma bh=".&bh)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008230
8231" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008232" call Decho("(netrw) Processing your browsing request...")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233" endif " Decho
8234
8235" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
8236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
8237 " force a refresh for tree listings
Bram Moolenaara6878372014-03-22 21:02:50 +01008238" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008239 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008240 endif
8241
8242 " save current directory on directory history list
Bram Moolenaaradc21822011-04-01 18:03:16 +02008243 keepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008244
8245 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008246 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008247" call Decho("set up banner")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008248 keepj call setline(1,'" ============================================================================')
8249 keepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008250 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
8251 keepj call setline(3,'" '.substitute(b:netrw_curdir,'/','\\','g'))
8252 else
8253 keepj call setline(3,'" '.b:netrw_curdir)
8254 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008255 let w:netrw_bannercnt= 3
Bram Moolenaaradc21822011-04-01 18:03:16 +02008256 keepj exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008257 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008258 keepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01008259 let w:netrw_bannercnt= 1
8260 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008261" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008262
8263 let sortby= g:netrw_sort_by
8264 if g:netrw_sort_direction =~ "^r"
8265 let sortby= sortby." reversed"
8266 endif
8267
8268 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008269 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008270" call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008271 if g:netrw_sort_by =~ "^n"
Bram Moolenaara6878372014-03-22 21:02:50 +01008272" call Decho("directories will be sorted by name")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008273 " sorted by name
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008274 keepj put ='\" Sorted by '.sortby
8275 keepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01008276 let w:netrw_bannercnt= w:netrw_bannercnt + 2
8277 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008278" call Decho("directories will be sorted by size or time")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008279 " sorted by size or date
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008280 keepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01008281 let w:netrw_bannercnt= w:netrw_bannercnt + 1
8282 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008283 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01008284" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008285" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008287
8288 " show copy/move target, if any
Bram Moolenaar5c736222010-01-06 20:54:52 +01008289 if g:netrw_banner
8290 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara6878372014-03-22 21:02:50 +01008291" call Decho("show copy/move target<".s:netrwmftgt.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008292 keepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01008293 if s:netrwmftgt_islocal
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008294 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008295 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008296 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008297 endif
8298 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008299 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008300" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008301 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008302 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008303 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008304
8305 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008306 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008307" call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008308 if g:netrw_list_hide != "" && g:netrw_hide
8309 if g:netrw_hide == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008310 keepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008311 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008312 keepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008313 endif
8314 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008315 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008316 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008317
8318" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
8319 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
8320" call Decho("quickhelp =".quickhelp)
8321 keepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
8322" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
8323 keepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01008324 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01008325" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008326" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008327 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008328
8329 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01008330 if g:netrw_banner
8331 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008332 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008333" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008334" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008335" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008336 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008337
Bram Moolenaar446cb832008-06-24 21:56:24 +00008338 " get list of files
Bram Moolenaara6878372014-03-22 21:02:50 +01008339" call Decho("Get list of files - islocal=".a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008340 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02008341 keepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008342 else " remote
Bram Moolenaara6878372014-03-22 21:02:50 +01008343 keepj let badresult= s:NetrwRemoteListing()
8344 if badresult
8345" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
8346" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
8347 return
8348 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008349 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008350
8351 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008352 if !exists("w:netrw_bannercnt")
8353 let w:netrw_bannercnt= 0
8354 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008355" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)")
8356" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
8357
Bram Moolenaar5c736222010-01-06 20:54:52 +01008358 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008359" call Decho("manipulate directory listing (hide)")
8360" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008361 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008362 keepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008363 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008364 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008365" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008366
8367 if g:netrw_sort_by =~ "^n"
8368 " sort by name
Bram Moolenaaradc21822011-04-01 18:03:16 +02008369 keepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008370
Bram Moolenaar5c736222010-01-06 20:54:52 +01008371 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008372" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008373 if g:netrw_sort_direction =~ 'n'
8374 " normal direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008375 exe 'sil keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008376 else
8377 " reverse direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008378 exe 'sil keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008379 endif
8380 endif
8381 " remove priority pattern prefix
Bram Moolenaara6878372014-03-22 21:02:50 +01008382" call Decho("remove priority pattern prefix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008383 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008384 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385
8386 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01008387 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008388" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008389 if g:netrw_sort_direction =~ 'n'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008390" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008391 exe 'sil! keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02008393" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort!')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008394 exe 'sil! keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008395 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008396 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008397 keepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399 endif
8400
8401 elseif g:netrw_sort_direction =~ 'r'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008402" call Decho('(s:PerformListing) reverse the sorted listing')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008403 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008404 exe 'sil! keepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008405 call histdel("/",-1)
8406 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008407 endif
8408 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008409" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008410
8411 " convert to wide/tree listing {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008412" call Decho("modify display if wide/tree listing style")
8413" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008414 keepj call s:NetrwWideListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01008415" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008416 keepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01008417" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418
Bram Moolenaar5c736222010-01-06 20:54:52 +01008419 if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 " place cursor on the top-left corner of the file listing
Bram Moolenaara6878372014-03-22 21:02:50 +01008421" call Decho("place cursor on top-left corner of file listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008422 exe 'sil! keepj '.w:netrw_bannercnt
8423 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 endif
8425
8426 " record previous current directory
8427 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01008428" call Decho("record netrw_prvdir<".w:netrw_prvdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429
8430 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008431" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008432 keepj call s:SetBufWinVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01008433" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008434 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008435" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436
8437 " set display to netrw display settings
Bram Moolenaara6878372014-03-22 21:02:50 +01008438" call Decho("set display to netrw display settings (".g:netrw_bufsettings.")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008439 exe "setl ".g:netrw_bufsettings
Bram Moolenaara6878372014-03-22 21:02:50 +01008440" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008441 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara6878372014-03-22 21:02:50 +01008442" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008443 exe "setl ts=".(g:netrw_maxfilenamelen+1)
8444 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445
Bram Moolenaar8d043172014-01-23 14:24:41 +01008446 if exists("s:treecurpos")
Bram Moolenaara6878372014-03-22 21:02:50 +01008447" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)")
8448 keepj call netrw#RestorePosn(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 unlet s:treecurpos
8450 endif
8451
Bram Moolenaara6878372014-03-22 21:02:50 +01008452" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
8454endfun
8455
8456" ---------------------------------------------------------------------
8457" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008458fun! s:SetupNetrwStatusLine(statline)
8459" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
8460
8461 if !exists("s:netrw_setup_statline")
8462 let s:netrw_setup_statline= 1
8463" call Decho("do first-time status line setup")
8464
8465 if !exists("s:netrw_users_stl")
8466 let s:netrw_users_stl= &stl
8467 endif
8468 if !exists("s:netrw_users_ls")
8469 let s:netrw_users_ls= &laststatus
8470 endif
8471
8472 " set up User9 highlighting as needed
8473 let keepa= @a
8474 redir @a
8475 try
8476 hi User9
8477 catch /^Vim\%((\a\+)\)\=:E411/
8478 if &bg == "dark"
8479 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
8480 else
8481 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
8482 endif
8483 endtry
8484 redir END
8485 let @a= keepa
8486 endif
8487
8488 " set up status line (may use User9 highlighting)
8489 " insure that windows have a statusline
8490 " make sure statusline is displayed
8491 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02008492 setl laststatus=2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008493" call Decho("stl=".&stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008494 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00008495
8496" call Dret("SetupNetrwStatusLine : stl=".&stl)
8497endfun
8498
8499" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500" Remote Directory Browsing Support: {{{1
8501" ===========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00008502
8503" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01008504" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
8505" This function assumes that a long listing will be received. Size, time,
8506" and reverse sorts will be requested of the server but not otherwise
8507" enforced here.
8508fun! s:NetrwRemoteFtpCmd(path,listcmd)
8509" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
8510" call Decho("line($)=".line("$")." w:netrw_bannercnt=".w:netrw_bannercnt)
8511 " sanity check: {{{3
8512 if !exists("w:netrw_method")
8513 if exists("b:netrw_method")
8514 let w:netrw_method= b:netrw_method
8515 else
8516 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
8517" call Dret("NetrwRemoteFtpCmd")
8518 return
8519 endif
8520 endif
8521
8522 " WinXX ftp uses unix style input, so set ff to unix " {{{3
8523 let ffkeep= &ff
8524 setl ma ff=unix noro
8525" call Decho("setl ma ff=unix noro")
8526
8527 " clear off any older non-banner lines " {{{3
8528 " note that w:netrw_bannercnt indexes the line after the banner
8529" call Decho('exe sil! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)")
8530 exe "sil! keepjumps ".w:netrw_bannercnt.",$d"
8531
8532 ".........................................
8533 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
8534 " ftp + <.netrc>: Method #2
8535 if a:path != ""
8536 keepj put ='cd \"'.a:path.'\"'
8537 endif
8538 if exists("g:netrw_ftpextracmd")
8539 keepj put =g:netrw_ftpextracmd
8540" call Decho("filter input: ".getline('.'))
8541 endif
8542 keepj call setline(line("$")+1,a:listcmd)
8543" exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
8544 if exists("g:netrw_port") && g:netrw_port != ""
8545" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
8546 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
8547 else
8548" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
8549 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
8550 endif
8551
8552 ".........................................
8553 elseif w:netrw_method == 3 " {{{3
8554 " ftp + machine,id,passwd,filename: Method #3
8555 setl ff=unix
8556 if exists("g:netrw_port") && g:netrw_port != ""
8557 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
8558 else
8559 keepj put ='open '.g:netrw_machine
8560 endif
8561
8562 " handle userid and password
8563 let host= substitute(g:netrw_machine,'\..*$','','')
8564" call Decho("host<".host.">")
8565 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
8566 call NetUserPass("ftp:".host)
8567 endif
8568 if exists("g:netrw_uid") && g:netrw_uid != ""
8569 if exists("g:netrw_ftp") && g:netrw_ftp == 1
8570 keepj put =g:netrw_uid
8571 if exists("s:netrw_passwd") && s:netrw_passwd != ""
8572 keepj put ='\"'.s:netrw_passwd.'\"'
8573 endif
8574 elseif exists("s:netrw_passwd")
8575 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
8576 endif
8577 endif
8578
8579 if a:path != ""
8580 keepj put ='cd \"'.a:path.'\"'
8581 endif
8582 if exists("g:netrw_ftpextracmd")
8583 keepj put =g:netrw_ftpextracmd
8584" call Decho("filter input: ".getline('.'))
8585 endif
8586 keepj call setline(line("$")+1,a:listcmd)
8587
8588 " perform ftp:
8589 " -i : turns off interactive prompting from ftp
8590 " -n unix : DON'T use <.netrc>, even though it exists
8591 " -n win32: quit being obnoxious about password
8592 if exists("w:netrw_bannercnt")
8593" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
8594" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
8595 exe s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
8596" else " Decho
8597" call Decho("WARNING: w:netrw_bannercnt doesn't exist!")
8598" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline(".")) " COMBAK
8599 endif
8600
8601 ".........................................
8602 elseif w:netrw_method == 9 " {{{3
8603 " sftp username@machine: Method #9
8604 " s:netrw_sftp_cmd
8605 setl ff=unix
8606
8607 " restore settings
8608 let &ff= ffkeep
8609" call Dret("NetrwRemoteFtpCmd")
8610 return
8611
8612 ".........................................
8613 else " {{{3
8614 keepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
8615 endif
8616
8617 " cleanup for Windows " {{{3
8618 if has("win32") || has("win95") || has("win64") || has("win16")
8619 sil! keepj %s/\r$//e
8620 keepj call histdel("/",-1)
8621 endif
8622 if a:listcmd == "dir"
8623 " infer directory/link based on the file permission string
8624 sil! keepj g/d\%([-r][-w][-x]\)\{3}/keepj s@$@/@e
8625 sil! keepj g/l\%([-r][-w][-x]\)\{3}/keepj s/$/@/e
8626 keepj call histdel("/",-1)
8627 keepj call histdel("/",-1)
8628 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
8629 exe "sil! keepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
8630 keepj call histdel("/",-1)
8631 endif
8632 endif
8633
8634 " ftp's listing doesn't seem to include ./ or ../ " {{{3
8635 if !search('^\.\/$\|\s\.\/$','wn')
8636 exe 'keepj '.w:netrw_bannercnt
8637 keepj put ='./'
8638 endif
8639 if !search('^\.\.\/$\|\s\.\.\/$','wn')
8640 exe 'keepj '.w:netrw_bannercnt
8641 keepj put ='../'
8642 endif
8643
8644 " restore settings " {{{3
8645 let &ff= ffkeep
8646" call Dret("NetrwRemoteFtpCmd")
8647endfun
8648
8649" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650" s:NetrwRemoteListing: {{{2
8651fun! s:NetrwRemoteListing()
8652" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00008653
Bram Moolenaara6878372014-03-22 21:02:50 +01008654 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
8655 let w:netrw_bannercnt= s:bannercnt
8656 endif
8657 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
8658 let w:netrw_bannercnt= s:bannercnt
8659 endif
8660
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008662
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 " sanity check:
8664 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008665" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 if !executable("ftp")
Bram Moolenaara6878372014-03-22 21:02:50 +01008667" call Decho("ftp is not executable")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 if !exists("g:netrw_quiet")
8669 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
8670 endif
8671 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008672" call Dret("s:NetrwRemoteListing -1")
8673 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00008674 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008675
Bram Moolenaar8d043172014-01-23 14:24:41 +01008676 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara6878372014-03-22 21:02:50 +01008677" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008679 if g:netrw_list_cmd == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01008680 keepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02008682 keepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008684 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008685
Bram Moolenaaradc21822011-04-01 18:03:16 +02008686 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008687" call Dret("s:NetrwRemoteListing -1")
8688 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008689 endif " (remote handling sanity check)
Bram Moolenaara6878372014-03-22 21:02:50 +01008690" call Decho("passed remote listing sanity checks")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008691
Bram Moolenaar446cb832008-06-24 21:56:24 +00008692 if exists("b:netrw_method")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008693" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008694 let w:netrw_method= b:netrw_method
8695 endif
8696
Bram Moolenaar13600302014-05-22 18:26:40 +02008697 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008698 " use ftp to get remote file listing {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699" call Decho("use ftp to get remote file listing")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700 let s:method = "ftp"
8701 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702 if g:netrw_sort_by =~ '^t'
8703 let listcmd= g:netrw_ftp_timelist_cmd
8704 elseif g:netrw_sort_by =~ '^s'
8705 let listcmd= g:netrw_ftp_sizelist_cmd
8706 endif
8707" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)")
8708 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008709" exe "sil! keepalt keepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710
Bram Moolenaara6878372014-03-22 21:02:50 +01008711 " report on missing file or directory messages
8712 if search('[Nn]o such file or directory\|Failed to change directory')
8713 let mesg= getline(".")
8714 if exists("w:netrw_bannercnt")
8715 setl ma
8716 exe w:netrw_bannercnt.",$d"
8717 setl noma
8718 endif
8719 keepj call s:NetrwOptionRestore("w:")
8720 call netrw#ErrorMsg(s:WARNING,mesg,96)
8721" call Dret("s:NetrwRemoteListing : -1")
8722 return -1
8723 endif
8724
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
8726 " shorten the listing
8727" call Decho("generate short listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008728 exe "sil! keepalt keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008729
8730 " cleanup
8731 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008732 exe "sil! keepalt keepj g/".g:netrw_ftp_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008733 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008735 sil! keepj %s/\r$//e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008736 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008738 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008740 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01008741 let line2= search('\.\.\/\%(\s\|$\)','cnW')
8742" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743 if line2 == 0
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008744" call Decho("netrw is putting ../ into listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008745 sil! keepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008747 exe "sil! keepj ".line1
8748 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749
8750" call Decho("line1=".line1." line2=".line2." line(.)=".line("."))
8751 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
8752" call Decho("M$ ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008753 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008754 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008755 else " normal ftp cleanup
8756" call Decho("normal ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008757 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
8758 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
8759 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008760 keepj call histdel("/",-1)
8761 keepj call histdel("/",-1)
8762 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763 endif
8764 endif
8765
Bram Moolenaar13600302014-05-22 18:26:40 +02008766 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767 " use ssh to get remote file listing {{{3
8768" call Decho("use ssh to get remote file listing: s:path<".s:path.">")
8769 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
8770" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)")
8771 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008772" call Decho("1: exe sil r! ".shellescape(listcmd.s:path, 1))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008773 exe "sil! keepj r! ".listcmd.shellescape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008775 sil! keepj g/^Listing directory/keepj d
8776 sil! keepj g/^d[-rwx][-rwx][-rwx]/keepj s+$+/+e
8777 sil! keepj g/^l[-rwx][-rwx][-rwx]/keepj s+$+@+e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008778 keepj call histdel("/",-1)
8779 keepj call histdel("/",-1)
8780 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008782 sil! keepj g/^[dlsp-][-rwx][-rwx][-rwx]/keepj s/^.*\s\(\S\+\)$/\1/e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008783 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008784 endif
8785 else
8786 if s:path == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008787" call Decho("2: exe sil r! ".listcmd)
Bram Moolenaar15146672011-10-20 22:22:38 +02008788 exe "sil! keepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 else
Bram Moolenaar251e1912011-06-19 05:09:16 +02008790" call Decho("3: exe sil r! ".listcmd.' '.shellescape(fnameescape(s:path),1))
Bram Moolenaar15146672011-10-20 22:22:38 +02008791 exe "sil! keepj keepalt r! ".listcmd.' '.shellescape(fnameescape(s:path),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792" call Decho("listcmd<".listcmd."> path<".s:path.">")
8793 endif
8794 endif
8795
8796 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01008797 if g:netrw_ssh_browse_reject != ""
8798" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/keepjumps d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008799 exe "sil! g/".g:netrw_ssh_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008800 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008801 endif
8802 endif
8803
8804 if w:netrw_liststyle == s:LONGLIST
8805 " do a long listing; these substitutions need to be done prior to sorting {{{3
8806" call Decho("fix long listing:")
8807
8808 if s:method == "ftp"
8809 " cleanup
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008810 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 while getline('.') =~ g:netrw_ftp_browse_reject
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008812 sil! keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008814 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008816 sil! keepj 1
8817 sil! keepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008818 let line2= line(".")
8819 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008820 if b:netrw_curdir != '/'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008821 exe 'sil! keepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 endif
8823 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008824 exe "sil! keepj ".line1
8825 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826 endif
8827
8828 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
8829" call Decho("M$ ftp site listing cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008830 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 +00008831 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
8832" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008833 exe 'sil keepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
8834 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
8835 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02008836 keepj call histdel("/",-1)
8837 keepj call histdel("/",-1)
8838 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008839 endif
8840 endif
8841
8842" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008843" exe "keepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008844" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008845
8846" call Dret("s:NetrwRemoteListing 0")
8847 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008848endfun
8849
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850" ---------------------------------------------------------------------
8851" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
8852fun! s:NetrwRemoteRm(usrhost,path) range
8853" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
8854" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaara6878372014-03-22 21:02:50 +01008855 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
8857 let all= 0
8858 if exists("s:netrwmarkfilelist_{bufnr('%')}")
8859 " remove all marked files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008860" call Decho("remove all marked files with bufnr#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 for fname in s:netrwmarkfilelist_{bufnr("%")}
8862 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
8863 if ok =~ 'q\%[uit]'
8864 break
8865 elseif ok =~ 'a\%[ll]'
8866 let all= 1
8867 endif
8868 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01008869 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008870
8871 else
8872 " remove files specified by range
Bram Moolenaar5c736222010-01-06 20:54:52 +01008873" call Decho("remove files specified by range")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874
8875 " preparation for removing multiple files/directories
8876 let ctr= a:firstline
8877
8878 " remove multiple files and directories
8879 while ctr <= a:lastline
Bram Moolenaar15146672011-10-20 22:22:38 +02008880 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
8882 if ok =~ 'q\%[uit]'
8883 break
8884 elseif ok =~ 'a\%[ll]'
8885 let all= 1
8886 endif
8887 let ctr= ctr + 1
8888 endwhile
8889 endif
8890
8891 " refresh the (remote) directory listing
8892" call Decho("refresh remote directory listing")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008893 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01008894 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895
8896" call Dret("s:NetrwRemoteRm")
8897endfun
8898
8899" ---------------------------------------------------------------------
8900" s:NetrwRemoteRmFile: {{{2
8901fun! s:NetrwRemoteRmFile(path,rmfile,all)
8902" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
8903
8904 let all= a:all
8905 let ok = ""
8906
8907 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
8908 " attempt to remove file
8909" call Decho("attempt to remove file (all=".all.")")
8910 if !all
8911 echohl Statement
8912" call Decho("case all=0:")
8913 call inputsave()
8914 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8915 call inputrestore()
8916 echohl NONE
8917 if ok == ""
8918 let ok="no"
8919 endif
8920 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8921 if ok =~ 'a\%[ll]'
8922 let all= 1
8923 endif
8924 endif
8925
8926 if all || ok =~ 'y\%[es]' || ok == ""
8927" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""))
8928 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
8929" call Decho("case ftp:")
8930 let path= a:path
8931 if path =~ '^\a\+://'
8932 let path= substitute(path,'^\a\+://[^/]\+/','','')
8933 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008934 sil! keepj .,$d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008935 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
8936 else
8937" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">")
8938 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
8939" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
8940 if !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008941 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942 let ok="q"
8943 else
8944 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
8945" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
8946" call Decho("remotedir<".remotedir.">")
8947" call Decho("rmfile<".a:rmfile.">")
8948 if remotedir != ""
8949 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile))
8950 else
8951 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile))
8952 endif
8953" call Decho("call system(".netrw_rm_cmd.")")
8954 let ret= system(netrw_rm_cmd)
8955 if ret != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02008956 keepj call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008957 endif
8958" call Decho("returned=".ret." errcode=".v:shell_error)
8959 endif
8960 endif
8961 elseif ok =~ 'q\%[uit]'
8962" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 endif
8964
8965 else
8966 " attempt to remove directory
8967" call Decho("attempt to remove directory")
8968 if !all
8969 call inputsave()
8970 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8971 call inputrestore()
8972 if ok == ""
8973 let ok="no"
8974 endif
8975 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8976 if ok =~ 'a\%[ll]'
8977 let all= 1
8978 endif
8979 endif
8980
8981 if all || ok =~ 'y\%[es]' || ok == ""
8982 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02008983 keepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008984 else
8985 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008986 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008987" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008988 let ret= system(netrw_rmdir_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989" call Decho("returned=".ret." errcode=".v:shell_error)
8990
8991 if v:shell_error != 0
Bram Moolenaarc236c162008-07-13 17:41:49 +00008992" call Decho("v:shell_error not 0")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008993 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 +00008994" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
8995 let ret= system(netrw_rmf_cmd)
8996" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008997
8998 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008999 keepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009000 endif
9001 endif
9002 endif
9003
9004 elseif ok =~ 'q\%[uit]'
Bram Moolenaarff034192013-04-24 18:51:19 +02009005" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009006 endif
9007 endif
9008
9009" call Dret("s:NetrwRemoteRmFile ".ok)
9010 return ok
9011endfun
9012
9013" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014" s:NetrwRemoteRename: rename a remote file or directory {{{2
9015fun! s:NetrwRemoteRename(usrhost,path) range
9016" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
9017
9018 " preparation for removing multiple files/directories
Bram Moolenaara6878372014-03-22 21:02:50 +01009019 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009020 let ctr = a:firstline
9021 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
9022
9023 " rename files given by the markfilelist
9024 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9025 for oldname in s:netrwmarkfilelist_{bufnr("%")}
9026" call Decho("oldname<".oldname.">")
9027 if exists("subfrom")
9028 let newname= substitute(oldname,subfrom,subto,'')
9029" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9030 else
9031 call inputsave()
9032 let newname= input("Moving ".oldname." to : ",oldname)
9033 call inputrestore()
9034 if newname =~ '^s/'
9035 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9036 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9037 let newname = substitute(oldname,subfrom,subto,'')
9038" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9039 endif
9040 endif
9041
9042 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02009043 keepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00009045 let oldname= shellescape(a:path.oldname)
9046 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009047" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
9048 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049 endif
9050
9051 endfor
9052 call s:NetrwUnMarkFile(1)
9053
9054 else
9055
9056 " attempt to rename files/directories
9057 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009058 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059
9060 let oldname= s:NetrwGetWord()
9061" call Decho("oldname<".oldname.">")
9062
9063 call inputsave()
9064 let newname= input("Moving ".oldname." to : ",oldname)
9065 call inputrestore()
9066
9067 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
9068 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
9069 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00009070 let oldname= shellescape(a:path.oldname)
9071 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009072" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
9073 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075
9076 let ctr= ctr + 1
9077 endwhile
9078 endif
9079
9080 " refresh the directory
Bram Moolenaaradc21822011-04-01 18:03:16 +02009081 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009082 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083
9084" call Dret("NetrwRemoteRename")
9085endfun
9086
9087" ---------------------------------------------------------------------
9088" Local Directory Browsing Support: {{{1
9089" ==========================================
9090
9091" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009092" netrw#FileUrlRead: handles reading file://* files {{{2
9093" Should accept: file://localhost/etc/fstab
9094" file:///etc/fstab
9095" file:///c:/WINDOWS/clock.avi
9096" file:///c|/WINDOWS/clock.avi
9097" file://localhost/c:/WINDOWS/clock.avi
9098" file://localhost/c|/WINDOWS/clock.avi
9099" file://c:/foo.txt
9100" file:///c:/foo.txt
9101" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
9102fun! netrw#FileUrlRead(fname)
9103" call Dfunc("netrw#FileUrlRead(fname<".a:fname.">)")
9104 let fname = a:fname
9105 if fname =~ '^file://localhost/'
9106" call Decho('converting file://localhost/ -to- file:///')
9107 let fname= substitute(fname,'^file://localhost/','file:///','')
9108" call Decho("fname<".fname.">")
9109 endif
9110 if (has("win32") || has("win95") || has("win64") || has("win16"))
9111 if fname =~ '^file:///\=\a[|:]/'
9112" call Decho('converting file:///\a|/ -to- file://\a:/')
9113 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
9114" call Decho("fname<".fname.">")
9115 endif
9116 endif
9117 let fname2396 = netrw#RFC2396(fname)
9118 let fname2396e= fnameescape(fname2396)
9119 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
9120 if (has("win32") || has("win95") || has("win64") || has("win16"))
9121" call Decho("windows exception for plainfname")
9122 if plainfname =~ '^/\+\a:'
9123" call Decho('removing leading "/"s')
9124 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
9125 endif
9126 endif
9127" call Decho("fname2396<".fname2396.">")
9128" call Decho("plainfname<".plainfname.">")
9129 exe "sil doau BufReadPre ".fname2396e
9130 exe 'keepj r '.plainfname
Bram Moolenaarff034192013-04-24 18:51:19 +02009131 exe 'sil! bdelete '.plainfname
9132 exe 'keepalt file! '.plainfname
Bram Moolenaar97d62492012-11-15 21:28:22 +01009133 keepj 1d
Bram Moolenaara6878372014-03-22 21:02:50 +01009134" call Decho("setl nomod")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009135 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01009136" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009137" call Dret("netrw#FileUrlRead")
9138 exe "sil doau BufReadPost ".fname2396e
9139endfun
9140
9141" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142" netrw#LocalBrowseCheck: {{{2
9143fun! netrw#LocalBrowseCheck(dirname)
9144 " unfortunate interaction -- split window debugging can't be
9145 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
9146 " event triggers another call to LocalBrowseCheck() when attempts
9147 " to write to the DBG buffer are made.
9148 " The &ft == "netrw" test was installed because the BufEnter event
9149 " would hit when re-entering netrw windows, creating unexpected
9150 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaara6878372014-03-22 21:02:50 +01009151" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">")
9152" call Decho("isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : "")))
9153" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
9154" call Dredir("ls!","ls!")
9155
Bram Moolenaar97d62492012-11-15 21:28:22 +01009156 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009157 if isdirectory(a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009158" call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse)
9159 let svposn= netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009160 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009161" call Decho("case 1 : ft=".&ft)
Bram Moolenaarff034192013-04-24 18:51:19 +02009162 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009163 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009164
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009166" call Decho("case 2 (ft≡netrw && line($)≡1)")
Bram Moolenaarff034192013-04-24 18:51:19 +02009167 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009168 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009169
Bram Moolenaar5c736222010-01-06 20:54:52 +01009170 elseif exists("s:treeforceredraw")
Bram Moolenaara6878372014-03-22 21:02:50 +01009171" call Decho("case 3 (treeforceredraw)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009172 unlet s:treeforceredraw
Bram Moolenaarff034192013-04-24 18:51:19 +02009173 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009174 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009176
Bram Moolenaara6878372014-03-22 21:02:50 +01009177" call Dret("netrw#LocalBrowseCheck")
9178 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009179 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009180
Bram Moolenaar97d62492012-11-15 21:28:22 +01009181 " following code wipes out currently unused netrw buffers
9182 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
9183 " AND IF the listing style is not a tree listing
9184 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01009185" call Decho("wiping out currently unused netrw buffers")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009186 let ibuf = 1
9187 let buflast = bufnr("$")
9188 while ibuf <= buflast
9189 if bufwinnr(ibuf) == -1 && isdirectory(bufname(ibuf))
Bram Moolenaarff034192013-04-24 18:51:19 +02009190 exe "sil! keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009191 endif
9192 let ibuf= ibuf + 1
9193 endwhile
9194 endif
9195 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009196" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +01009198" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009199endfun
9200
9201" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009202" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203" performed any shell command. The idea is to cause all local-browsing
9204" buffers to be refreshed after a user has executed some shell command,
9205" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +01009206fun! s:LocalBrowseRefresh()
9207" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
9208" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'))
9209" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'))
9210
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 " determine which buffers currently reside in a tab
9212 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009213" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214 return
9215 endif
9216 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +01009217" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009218 return
9219 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009220 if exists("s:netrw_events") && s:netrw_events == 1
9221 " s:LocalFastBrowser gets called (indirectly) from a
9222 let s:netrw_events= 2
9223" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
9224 return
Bram Moolenaar5c736222010-01-06 20:54:52 +01009225 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009226 let itab = 1
9227 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +01009228 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 while itab <= tabpagenr("$")
9230 let buftablist = buftablist + tabpagebuflist()
9231 let itab = itab + 1
9232 tabn
9233 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009234" call Decho("buftablist".string(buftablist))
9235" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009236 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
9237 " | refresh any netrw window
9238 " | wipe out any non-displaying netrw buffer
9239 let curwin = winnr()
9240 let ibl = 0
9241 for ibuf in s:netrw_browselist
Bram Moolenaara6878372014-03-22 21:02:50 +01009242" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
9244 " wipe out any non-displaying netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009245" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009246 exe "sil! bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009247 call remove(s:netrw_browselist,ibl)
Bram Moolenaara6878372014-03-22 21:02:50 +01009248" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 continue
9250 elseif index(tabpagebuflist(),ibuf) != -1
9251 " refresh any netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009252" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01009254 if getline(".") =~ 'Quick Help'
9255 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
9256 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
9257 let g:netrw_quickhelp= g:netrw_quickhelp - 1
9258 endif
9259" call Decho("#3: quickhelp=".g:netrw_quickhelp)
Bram Moolenaaradc21822011-04-01 18:03:16 +02009260 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 endif
9262 let ibl= ibl + 1
9263 endfor
9264 exe curwin."wincmd w"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009265 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009266
Bram Moolenaara6878372014-03-22 21:02:50 +01009267" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268endfun
9269
9270" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009271" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
9272"
9273" g:netrw_ Directory Is
9274" fastbrowse Local Remote
9275" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
9276" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
9277" fast 2 H H
9278"
9279" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
9280" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +01009281" (re-using a buffer may not be as accurate)
9282"
9283" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
9284" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
9285" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
9286" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
9287" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009288fun! s:LocalFastBrowser()
Bram Moolenaara6878372014-03-22 21:02:50 +01009289" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
9290" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'))
9291" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "installed" : "not installed"))
9292" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "installed" : "not installed"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009293
9294 " initialize browselist, a list of buffer numbers that the local browser has used
9295 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009296" call Decho("initialize s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009297 let s:netrw_browselist= []
9298 endif
9299
9300 " append current buffer to fastbrowse list
9301 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara6878372014-03-22 21:02:50 +01009302" call Decho("appendng current buffer to browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009303 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009304" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009305 endif
9306
9307 " enable autocmd events to handle refreshing/removing local browser buffers
9308 " If local browse buffer is currently showing: refresh it
9309 " If local browse buffer is currently hidden : wipe it
9310 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
9311 " =1 : medium speed, re-use directory listing for remote only
9312 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +01009313 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
9314 let s:netrw_events= 1
9315 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009316 au!
9317 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009318" call Decho("installing autocmd: ShellCmdPost")
9319 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009320 else
Bram Moolenaara6878372014-03-22 21:02:50 +01009321" call Decho("installing autocmds: ShellCmdPost FocusGained")
9322 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009323 endif
9324 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +01009325
9326 " user must have changed fastbrowse to its fast setting, so remove
9327 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +01009328 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
9329" call Decho("remove AuNetrwEvent autcmd group")
9330 unlet s:netrw_events
9331 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009332 au!
9333 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +01009334 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009335 endif
9336
9337" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
9338endfun
9339
9340" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009341" s:LocalListing: does the job of "ls" for local directories {{{2
9342fun! s:LocalListing()
9343" call Dfunc("s:LocalListing()")
9344" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
9345" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
9346
9347" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif
9348" 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
9349" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9350
9351 " get the list of files contained in the current directory
9352 let dirname = b:netrw_curdir
9353 let dirnamelen = strlen(b:netrw_curdir)
9354 let filelist = glob(s:ComposePath(dirname,"*"),0,1)
9355 let filelist = filelist + glob(s:ComposePath(dirname,".*"),0,1)
9356" call Decho("filelist=".filelist)
9357
9358 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
9359" call Decho("filelist=".string(filelist))
9360 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
9361 " include ../ in the glob() entry if its missing
9362" call Decho("forcibly including on \"..\"")
9363 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
9364" call Decho("filelist=".string(filelist))
9365 endif
9366
9367" call Decho("before while: dirname<".dirname.">")
9368" call Decho("before while: dirnamelen<".dirnamelen.">")
9369" call Decho("before while: filelist=".string(filelist))
9370
9371 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
9372 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
9373 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
9374" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy))
9375" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen)
9376 endif
9377" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9378
9379 for filename in filelist
9380" call Decho(" ")
9381" call Decho("for filename in filelist: filename<".filename.">")
9382
9383 if getftype(filename) == "link"
9384 " indicate a symbolic link
9385" call Decho("indicate <".filename."> is a symbolic link with trailing @")
9386 let pfile= filename."@"
9387
9388 elseif getftype(filename) == "socket"
9389 " indicate a socket
9390" call Decho("indicate <".filename."> is a socket with trailing =")
9391 let pfile= filename."="
9392
9393 elseif getftype(filename) == "fifo"
9394 " indicate a fifo
9395" call Decho("indicate <".filename."> is a fifo with trailing |")
9396 let pfile= filename."|"
9397
9398 elseif isdirectory(filename)
9399 " indicate a directory
9400" call Decho("indicate <".filename."> is a directory with trailing /")
9401 let pfile= filename."/"
9402
9403 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename)
9404 if (has("win32") || has("win95") || has("win64") || has("win16"))
9405 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
9406 " indicate an executable
9407" call Decho("indicate <".filename."> is executable with trailing *")
9408 let pfile= filename."*"
9409 else
9410 " normal file
9411 let pfile= filename
9412 endif
9413 elseif executable(filename)
9414 " indicate an executable
9415" call Decho("indicate <".filename."> is executable with trailing *")
9416 let pfile= filename."*"
9417 else
9418 " normal file
9419 let pfile= filename
9420 endif
9421
9422 else
9423 " normal file
9424 let pfile= filename
9425 endif
9426" call Decho("pfile<".pfile."> (after *@/ appending)")
9427
9428 if pfile =~ '//$'
9429 let pfile= substitute(pfile,'//$','/','e')
9430" call Decho("change // to /: pfile<".pfile.">")
9431 endif
9432 let pfile= strpart(pfile,dirnamelen)
9433 let pfile= substitute(pfile,'^[/\\]','','e')
9434" call Decho("filename<".filename.">")
9435" call Decho("pfile <".pfile.">")
9436
9437 if w:netrw_liststyle == s:LONGLIST
9438 let sz = getfsize(filename)
9439 let fsz = strpart(" ",1,15-strlen(sz)).sz
9440 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
9441" call Decho("sz=".sz." fsz=".fsz)
9442 endif
9443
9444 if g:netrw_sort_by =~ "^t"
9445 " sort by time (handles time up to 1 quintillion seconds, US)
9446" call Decho("getftime(".filename.")=".getftime(filename))
9447 let t = getftime(filename)
9448 let ft = strpart("000000000000000000",1,18-strlen(t)).t
9449" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
9450 let ftpfile= ft.'/'.pfile
9451 sil! keepj put=ftpfile
9452
9453 elseif g:netrw_sort_by =~ "^s"
9454 " sort by size (handles file sizes up to 1 quintillion bytes, US)
9455" call Decho("getfsize(".filename.")=".getfsize(filename))
9456 let sz = getfsize(filename)
9457 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
9458" call Decho("exe keepj put ='".fsz.'/'.filename."'")
9459 let fszpfile= fsz.'/'.pfile
9460 sil! keepj put =fszpfile
9461
9462 else
9463 " sort by name
9464" call Decho("exe keepjumps put ='".pfile."'")
9465 sil! keepj put=pfile
9466 endif
9467 endfor
9468
9469 " cleanup any windows mess at end-of-line
9470 sil! keepj g/^$/d
9471 sil! keepj %s/\r$//e
9472 call histdel("/",-1)
9473" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
9474 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9475
9476" call Dret("s:LocalListing")
9477endfun
9478
9479" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009480" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
9481fun! s:NetrwLocalExecute(cmd)
9482" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
9483 let ykeep= @@
9484 " sanity check
9485 if !executable(a:cmd)
9486 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
9487 let @@= ykeep
9488" call Dret("s:NetrwLocalExecute")
9489 return
9490 endif
9491
9492 let optargs= input(":!".a:cmd,"","file")
9493" call Decho("optargs<".optargs.">")
9494 let result= system(a:cmd.optargs)
Bram Moolenaara6878372014-03-22 21:02:50 +01009495" call Decho("result)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009496
9497 " strip any ansi escape sequences off
9498 let result = substitute(result,"\e\\[[0-9;]*m","","g")
9499
9500 " show user the result(s)
9501 echomsg result
9502 let @@= ykeep
9503
9504" call Dret("s:NetrwLocalExecute")
9505endfun
9506
9507" ---------------------------------------------------------------------
9508" s:NetrwLocalRename: rename a remote file or directory {{{2
9509fun! s:NetrwLocalRename(path) range
9510" call Dfunc("NetrwLocalRename(path<".a:path.">)")
9511
9512 " preparation for removing multiple files/directories
9513 let ykeep = @@
9514 let ctr = a:firstline
Bram Moolenaara6878372014-03-22 21:02:50 +01009515 let svpos = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009516
9517 " rename files given by the markfilelist
9518 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9519 for oldname in s:netrwmarkfilelist_{bufnr("%")}
9520" call Decho("oldname<".oldname.">")
9521 if exists("subfrom")
9522 let newname= substitute(oldname,subfrom,subto,'')
9523" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9524 else
9525 call inputsave()
9526 let newname= input("Moving ".oldname." to : ",oldname)
9527 call inputrestore()
9528 if newname =~ '^s/'
9529 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9530 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9531" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9532 let newname = substitute(oldname,subfrom,subto,'')
9533 endif
9534 endif
9535 call rename(oldname,newname)
9536 endfor
9537 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
9538
9539 else
9540
9541 " attempt to rename files/directories
9542 while ctr <= a:lastline
9543 exe "keepj ".ctr
9544
9545 " sanity checks
9546 if line(".") < w:netrw_bannercnt
9547 let ctr= ctr + 1
9548 continue
9549 endif
9550 let curword= s:NetrwGetWord()
9551 if curword == "./" || curword == "../"
9552 let ctr= ctr + 1
9553 continue
9554 endif
9555
9556 keepj norm! 0
9557 let oldname= s:ComposePath(a:path,curword)
9558" call Decho("oldname<".oldname.">")
9559
9560 call inputsave()
9561 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
9562 call inputrestore()
9563
9564 call rename(oldname,newname)
9565" call Decho("renaming <".oldname."> to <".newname.">")
9566
9567 let ctr= ctr + 1
9568 endwhile
9569 endif
9570
9571 " refresh the directory
9572" call Decho("refresh the directory listing")
9573 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009574 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009575 let @@= ykeep
9576
9577" call Dret("NetrwLocalRename")
9578endfun
9579
9580" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581" s:NetrwLocalRm: {{{2
9582fun! s:NetrwLocalRm(path) range
9583" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
9584" call Decho("firstline=".a:firstline." lastline=".a:lastline)
9585
9586 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +01009587 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 let ret = 0
9589 let all = 0
Bram Moolenaara6878372014-03-22 21:02:50 +01009590 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591
9592 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9593 " remove all marked files
9594" call Decho("remove all marked files")
9595 for fname in s:netrwmarkfilelist_{bufnr("%")}
9596 let ok= s:NetrwLocalRmFile(a:path,fname,all)
9597 if ok =~ 'q\%[uit]' || ok == "no"
9598 break
9599 elseif ok =~ 'a\%[ll]'
9600 let all= 1
9601 endif
9602 endfor
9603 call s:NetrwUnMarkFile(1)
9604
9605 else
9606 " remove (multiple) files and directories
9607" call Decho("remove files in range [".a:firstline.",".a:lastline."]")
9608
9609 let ctr = a:firstline
9610 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009611 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009612
9613 " sanity checks
9614 if line(".") < w:netrw_bannercnt
9615 let ctr= ctr + 1
9616 continue
9617 endif
9618 let curword= s:NetrwGetWord()
9619 if curword == "./" || curword == "../"
9620 let ctr= ctr + 1
9621 continue
9622 endif
9623 let ok= s:NetrwLocalRmFile(a:path,curword,all)
9624 if ok =~ 'q\%[uit]' || ok == "no"
9625 break
9626 elseif ok =~ 'a\%[ll]'
9627 let all= 1
9628 endif
9629 let ctr= ctr + 1
9630 endwhile
9631 endif
9632
9633 " refresh the directory
9634" call Decho("bufname<".bufname("%").">")
9635 if bufname("%") != "NetrwMessage"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009636 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009637 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01009639 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640
9641" call Dret("s:NetrwLocalRm")
9642endfun
9643
9644" ---------------------------------------------------------------------
9645" s:NetrwLocalRmFile: remove file fname given the path {{{2
9646" Give confirmation prompt unless all==1
9647fun! s:NetrwLocalRmFile(path,fname,all)
9648" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
9649
9650 let all= a:all
9651 let ok = ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009652 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let rmfile= s:ComposePath(a:path,a:fname)
9654" call Decho("rmfile<".rmfile.">")
9655
9656 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
9657 " attempt to remove file
9658" call Decho("attempt to remove file<".rmfile.">")
9659 if !all
9660 echohl Statement
9661 call inputsave()
9662 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9663 call inputrestore()
9664 echohl NONE
9665 if ok == ""
9666 let ok="no"
9667 endif
9668" call Decho("response: ok<".ok.">")
9669 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9670" call Decho("response: ok<".ok."> (after sub)")
9671 if ok =~ 'a\%[ll]'
9672 let all= 1
9673 endif
9674 endif
9675
9676 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00009677 let ret= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009678" call Decho("errcode=".v:shell_error." ret=".ret)
9679 endif
9680
9681 else
9682 " attempt to remove directory
9683 if !all
9684 echohl Statement
9685 call inputsave()
9686 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9687 call inputrestore()
9688 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9689 if ok == ""
9690 let ok="no"
9691 endif
9692 if ok =~ 'a\%[ll]'
9693 let all= 1
9694 endif
9695 endif
9696 let rmfile= substitute(rmfile,'[\/]$','','e')
9697
9698 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009699" call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.shellescape(rmfile).')')
9700 call system(netrw#WinPath(g:netrw_localrmdir).' '.shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701" call Decho("v:shell_error=".v:shell_error)
9702
9703 if v:shell_error != 0
9704" call Decho("2nd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009705 let errcode= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009706" call Decho("errcode=".errcode)
9707
9708 if errcode != 0
9709 if has("unix")
9710" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009711 call system("rm ".shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712 if v:shell_error != 0 && !exists("g:netrw_quiet")
9713 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
9714 let ok="no"
9715 endif
9716 elseif !exists("g:netrw_quiet")
9717 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
9718 let ok="no"
9719 endif
9720 endif
9721 endif
9722 endif
9723 endif
9724
9725" call Dret("s:NetrwLocalRmFile ".ok)
9726 return ok
9727endfun
9728
9729" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009730" Support Functions: {{{1
9731
Bram Moolenaar488c6512005-08-11 20:09:58 +00009732" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009733" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
9734" 0: marked file list of current buffer
9735" 1: marked file target
9736fun! netrw#Access(ilist)
9737 if a:ilist == 0
9738 if exists("s:netrwmarkfilelist_".bufnr('%'))
9739 return s:netrwmarkfilelist_{bufnr('%')}
9740 else
9741 return "no-list-buf#".bufnr('%')
9742 endif
9743 elseif a:ilist == 1
9744 return s:netrwmftgt
9745endfun
9746
9747" ------------------------------------------------------------------------
9748" netrw#RestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2
9749fun! netrw#RestorePosn(...)
9750" call Dfunc("netrw#RestorePosn() 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))
9751 let eikeep= &ei
9752 setl ei=all
9753 if expand("%") == "NetrwMessage"
9754 if exists("s:winBeforeErr")
9755 exe s:winBeforeErr."wincmd w"
9756 endif
9757 endif
9758
9759 if a:0 > 0
9760 exe "keepj ".a:1
9761 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009762" call Decho("a:1 = ".((a:0 > 0)? a:1 : 'n/a'))
9763" call Decho("liststyle = ".(exists("liststyle")? liststyle : 'n/a'). " w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
9764 if exists("liststyle") && exists("w:netrw_liststyle") && liststyle != w:netrw_liststyle
9765 let usesrch= 1
9766 else
9767 let usesrch= 0
9768 endif
9769
9770" call Decho("winh = ".(exists("w:netrw_winh")? w:netrw_winh : -1))
9771" call Decho("winw = ".(exists("w:netrw_winw")? w:netrw_winw : -1))
9772" call Decho("cur winheight=".winheight(0)." winwidth=".winwidth(0))
9773" call Decho("w:netrw_winfile = ".(exists("w:netrw_winfile")? w:netrw_winfile : 'n/a'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009774
9775 " restore window
9776 if exists("w:netrw_winnr")
9777" call Decho("restore window: exe sil! ".w:netrw_winnr."wincmd w")
9778 exe "sil! ".w:netrw_winnr."wincmd w"
9779 endif
9780 if v:shell_error == 0
9781 " as suggested by Bram M: redraw on no error
9782 " allows protocol error messages to remain visible
9783" redraw!
9784 endif
9785
9786 " restore top-of-screen line
9787 if exists("w:netrw_hline")
9788" call Decho("restore topofscreen: exe keepj norm! ".w:netrw_hline."G0z")
9789 exe "keepj norm! ".w:netrw_hline."G0z\<CR>"
9790 endif
9791
9792 " restore position
Bram Moolenaar13600302014-05-22 18:26:40 +02009793 " when the window's height x width has changed, the line,col is no longer useful
9794 if w:netrw_winh == winheight(0) && w:netrw_winw == winwidth(0) && exists("w:netrw_line") && exists("w:netrw_col") && !usesrch
9795" call Decho("using posn: exe keepj norm! ".w:netrw_line."G0".w:netrw_col."|")
Bram Moolenaara6878372014-03-22 21:02:50 +01009796 exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaar13600302014-05-22 18:26:40 +02009797
9798 elseif exists("w:netrw_winfile")
9799 if !search('\<'.escape(w:netrw_winfile,g:netrw_fname_escape),'cw')
9800 if exists("w:netrw_bannercnt")
9801" call Decho("using bannercnt: win#".winnr()." ".winheight(0)."x".winwidth(0)." w:netrw_winfile<".w:netrw_winfile.">")
9802 exe "keepj ".w:netrw_bannercnt
9803 norm! 0
9804 else
9805 " go to upper left corner
9806" call Decho("goto ulc: win#".winnr()." ".winheight(0)."x".winwidth(0)." w:netrw_winfile<".w:netrw_winfile.">")
9807 keepj 1
9808 norm! 0
9809 endif
9810 else
9811" call Decho("used search: w:netrw_winfile<".w:netrw_winfile.">")
9812 endif
9813
9814 else
9815" call Decho("goto ulc: win#".winnr()." ".winheight(0)."x".winwidth(0))
9816 keepj 1
9817 norm! 0
Bram Moolenaara6878372014-03-22 21:02:50 +01009818 endif
9819
9820 let &ei= eikeep
9821" call Dret("netrw#RestorePosn : line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
9822endfun
9823
9824" ---------------------------------------------------------------------
9825" netrw#RFC2396: converts %xx into characters {{{2
9826fun! netrw#RFC2396(fname)
9827" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
9828 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
9829" call Dret("netrw#RFC2396 ".fname)
9830 return fname
9831endfun
9832
9833" ---------------------------------------------------------------------
9834" netrw#SavePosn: saves position of cursor on screen {{{2
9835fun! netrw#SavePosn()
9836" call Dfunc("netrw#SavePosn() line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
9837 " Save current line and column
9838 let w:netrw_winnr= winnr()
9839 let w:netrw_line = line(".")
9840 let w:netrw_col = virtcol(".")
9841" call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col)
9842
Bram Moolenaar13600302014-05-22 18:26:40 +02009843 " save filename under cursor
9844" call Decho("line#".line(".")." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'))
9845 if exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt && &ft == "netrw"
9846 let winfile = "|let w:netrw_winfile='".s:NetrwGetWord()."'"
9847 else
9848 let winfile= ""
9849 endif
9850" call Decho("winfile<".winfile.">")
9851 if exists("w:netrw_liststyle")
9852 let liststyle = "|let liststyle=".w:netrw_liststyle
9853 else
9854 let liststyle= ""
9855 endif
9856" call Decho("liststyle=".liststyle)
9857
Bram Moolenaara6878372014-03-22 21:02:50 +01009858 " Save top-of-screen line
9859 keepj norm! H0
9860 let w:netrw_hline= line(".")
9861
Bram Moolenaar13600302014-05-22 18:26:40 +02009862 " save up alternate position information
9863 " use this when window height x width has changed
9864 let w:netrw_winh = winheight(0)
9865 let w:netrw_winw = winwidth(0)
9866
Bram Moolenaara6878372014-03-22 21:02:50 +01009867 " set up string holding position parameters
Bram Moolenaar13600302014-05-22 18:26:40 +02009868 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."|let w:netrw_winh=".w:netrw_winh."|let w:netrw_winw=".w:netrw_winw.liststyle.winfile
Bram Moolenaara6878372014-03-22 21:02:50 +01009869
9870 keepj call netrw#RestorePosn()
9871" call Dret("netrw#SavePosn : winnr=".(exists("w:netrw_winnr")? w:netrw_winnr : "n/a")." line=".(exists("w:netrw_line")? w:netrw_line : "n/a")." col=".(exists("w:netrw_col")? w:netrw_col : "n/a")." hline=".(exists("w:netrw_hline")? w:netrw_hline : "n/a"))
9872 return ret
9873endfun
9874
9875" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009876" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
9877fun! netrw#WinPath(path)
9878" call Dfunc("netrw#WinPath(path<".a:path.">)")
9879 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
9880 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +01009881 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009882 " remove trailing slash (Win95)
9883 let path = substitute(path, '\(\\\|/\)$', '', 'g')
9884 " remove escaped spaces
9885 let path = substitute(path, '\ ', ' ', 'g')
9886 " convert slashes to backslashes
9887 let path = substitute(path, '/', '\', 'g')
9888 else
9889 let path= a:path
9890 endif
9891" call Dret("netrw#WinPath <".path.">")
9892 return path
9893endfun
9894
9895" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009896" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
9897fun! s:ComposePath(base,subdir)
9898" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
9899
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009900 if has("amiga")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009901" call Decho("amiga")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009902 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +00009903 if ec != '/' && ec != ':'
9904 let ret = a:base . "/" . a:subdir
9905 else
9906 let ret = a:base . a:subdir
9907 endif
9908
9909 elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
9910" call Decho("windows")
9911 let ret= a:subdir
9912
Bram Moolenaar5c736222010-01-06 20:54:52 +01009913 elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
9914" call Decho("windows")
9915 if a:base =~ '[/\\]$'
9916 let ret= a:base.a:subdir
9917 else
9918 let ret= a:base."/".a:subdir
9919 endif
9920
Bram Moolenaarc236c162008-07-13 17:41:49 +00009921 elseif a:base =~ '^\a\+://'
9922" call Decho("remote linux/macos")
9923 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
9924 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
9925 if a:subdir == '../'
9926 if curpath =~ '[^/]/[^/]\+/$'
9927 let curpath= substitute(curpath,'[^/]\+/$','','')
9928 else
9929 let curpath=""
9930 endif
9931 let ret= urlbase.curpath
9932 else
9933 let ret= urlbase.curpath.a:subdir
9934 endif
9935" call Decho("urlbase<".urlbase.">")
9936" call Decho("curpath<".curpath.">")
9937" call Decho("ret<".ret.">")
9938
9939 else
9940" call Decho("local linux/macos")
9941 let ret = substitute(a:base."/".a:subdir,"//","/","g")
9942 if a:base =~ '^//'
9943 " keeping initial '//' for the benefit of network share listing support
9944 let ret= '/'.ret
9945 endif
9946 let ret= simplify(ret)
9947 endif
9948
9949" call Dret("s:ComposePath ".ret)
9950 return ret
9951endfun
9952
9953" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009954" s:FileReadable: o/s independent filereadable {{{2
9955fun! s:FileReadable(fname)
9956" call Dfunc("s:FileReadable(fname<".a:fname.">)")
9957
9958 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01009959 let ret= filereadable(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/',''))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009960 else
9961 let ret= filereadable(a:fname)
9962 endif
9963
9964" call Dret("s:FileReadable ".ret)
9965 return ret
9966endfun
9967
9968" ---------------------------------------------------------------------
9969" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
9970" Places correct suffix on end of temporary filename,
9971" using the suffix provided with fname
9972fun! s:GetTempfile(fname)
9973" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
9974
9975 if !exists("b:netrw_tmpfile")
9976 " get a brand new temporary filename
9977 let tmpfile= tempname()
9978" call Decho("tmpfile<".tmpfile."> : from tempname()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979
Bram Moolenaarc236c162008-07-13 17:41:49 +00009980 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009981" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
Bram Moolenaar9964e462007-05-05 17:54:07 +00009983 " sanity check -- does the temporary file's directory exist?
9984 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009985" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009986 keepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009987" call Dret("s:GetTempfile getcwd<".getcwd().">")
9988 return ""
9989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990
Bram Moolenaar9964e462007-05-05 17:54:07 +00009991 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar5c736222010-01-06 20:54:52 +01009992 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX()
Bram Moolenaar9964e462007-05-05 17:54:07 +00009993" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994
Bram Moolenaar9964e462007-05-05 17:54:07 +00009995 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009997 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009998 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999 if !exists("+shellslash") || !&ssl
10000 let tmpfile = substitute(tmpfile,'/','\','g')
10001 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010002 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010004 endif
10005 let b:netrw_tmpfile= tmpfile
10006" call Decho("o/s dependent fixed tempname<".tmpfile.">")
10007 else
10008 " re-use temporary filename
10009 let tmpfile= b:netrw_tmpfile
10010" call Decho("tmpfile<".tmpfile."> re-using")
10011 endif
10012
10013 " use fname's suffix for the temporary file
10014 if a:fname != ""
10015 if a:fname =~ '\.[^./]\+$'
10016" call Decho("using fname<".a:fname.">'s suffix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010017 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010018 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010019 elseif a:fname =~ '.txz$'
10020 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010021 else
10022 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
10023 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010024" call Decho("suffix<".suffix.">")
10025 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
10026" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)")
10027 let tmpfile .= suffix
10028" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
10029 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
10030 endif
10031 endif
10032
Bram Moolenaara6878372014-03-22 21:02:50 +010010033" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010034" call Dret("s:GetTempfile <".tmpfile.">")
10035 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000010037
10038" ---------------------------------------------------------------------
10039" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000010040" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000010041fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010043 if s:user == ""
10044 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
10045 else
10046 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
10047 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010048 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010049 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010050 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010051 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010052 else
10053 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
10054 endif
10055" call Dret("s:MakeSshCmd <".sshcmd.">")
10056 return sshcmd
10057endfun
10058
10059" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010060" s:NetrwBMShow: {{{2
10061fun! s:NetrwBMShow()
10062" call Dfunc("s:NetrwBMShow()")
10063 redir => bmshowraw
10064 menu
10065 redir END
10066 let bmshowlist = split(bmshowraw,'\n')
10067 if bmshowlist != []
10068 let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"')
10069 if bmshowfuncs != []
10070 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
10071 if bmshowfunc =~ '^call.*BMShow()'
Bram Moolenaaradc21822011-04-01 18:03:16 +020010072 exe "sil! keepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000010073 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010074 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000010076" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
10077endfun
10078
10079" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020010080" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
10081fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010082 if !exists("w:netrw_liststyle")
10083 let w:netrw_liststyle= g:netrw_liststyle
10084 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020010085" call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020010086
10087 if &ft != "netrw"
10088 " if the current window isn't a netrw directory listing window, then use user cursorline/column
10089 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaar15146672011-10-20 22:22:38 +020010090" call Decho("case ft!=netrw: use user cul,cuc")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010091 let &l:cursorline = s:netrw_usercul
10092 let &l:cursorcolumn = s:netrw_usercuc
10093
10094 elseif g:netrw_cursor == 4
10095 " all styles: cursorline, cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +020010096" call Decho("case g:netrw_cursor==4: setl cul cuc")
10097 setl cursorline
10098 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020010099
10100 elseif g:netrw_cursor == 3
10101 " thin-long-tree: cursorline, user's cursorcolumn
10102 " wide : cursorline, cursorcolumn
10103 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +020010104" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc")
Bram Moolenaar15146672011-10-20 22:22:38 +020010105 setl cursorline
10106 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020010107 else
Bram Moolenaarff034192013-04-24 18:51:19 +020010108" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)")
Bram Moolenaar15146672011-10-20 22:22:38 +020010109 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010110 let &l:cursorcolumn = s:netrw_usercuc
10111 endif
10112
10113 elseif g:netrw_cursor == 2
10114 " thin-long-tree: cursorline, user's cursorcolumn
10115 " wide : cursorline, user's cursorcolumn
Bram Moolenaarff034192013-04-24 18:51:19 +020010116" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010117 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020010118 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010119
10120 elseif g:netrw_cursor == 1
10121 " thin-long-tree: user's cursorline, user's cursorcolumn
10122 " wide : cursorline, user's cursorcolumn
10123 let &l:cursorcolumn = s:netrw_usercuc
10124 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +020010125" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010126 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010127 else
Bram Moolenaar15146672011-10-20 22:22:38 +020010128" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010129 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010130 endif
10131
10132 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020010133 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +020010134" call Decho("default: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010135 let &l:cursorline = s:netrw_usercul
10136 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010137 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020010138
10139" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010140endfun
10141
10142" ---------------------------------------------------------------------
10143" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
10144fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010010145" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020010146 if exists("s:netrw_usercul")
10147 let &l:cursorline = s:netrw_usercul
10148 endif
10149 if exists("s:netrw_usercuc")
10150 let &l:cursorcolumn = s:netrw_usercuc
10151 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010152" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
10153endfun
10154
10155" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010156" s:NetrwDelete: Deletes a file. {{{2
10157" Uses Steve Hall's idea to insure that Windows paths stay
10158" acceptable. No effect on Unix paths.
10159" Examples of use: let result= s:NetrwDelete(path)
10160fun! s:NetrwDelete(path)
10161" call Dfunc("s:NetrwDelete(path<".a:path.">)")
10162
Bram Moolenaar5c736222010-01-06 20:54:52 +010010163 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010164 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
10165 if exists("+shellslash")
10166 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020010167 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000010168 let result = delete(path)
10169 let &shellslash = sskeep
10170 else
10171" call Decho("exe let result= ".a:cmd."('".path."')")
10172 let result= delete(path)
10173 endif
10174 else
10175" call Decho("let result= delete(".path.")")
10176 let result= delete(path)
10177 endif
10178 if result < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +020010179 keepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010180 endif
10181
10182" call Dret("s:NetrwDelete ".result)
10183 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000010184endfun
10185
10186" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010010188fun! s:NetrwEnew(...)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010189" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010190" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010191
Bram Moolenaar446cb832008-06-24 21:56:24 +000010192 " grab a function-local-variable copy of buffer variables
Bram Moolenaara6878372014-03-22 21:02:50 +010010193" call Decho("make function-local copy of netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010194 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
10195 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
10196 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
10197 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
10198 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
10199 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
10200 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
10201 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
10202 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
10203 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
10204 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
10205 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
10206 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
10207 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
10208 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
10209 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
10210
Bram Moolenaaradc21822011-04-01 18:03:16 +020010211 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010212" call Decho("generate a buffer with keepjumps keepalt enew!")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010213 let netrw_keepdiff= &l:diff
Bram Moolenaar13600302014-05-22 18:26:40 +020010214 noswapfile keepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010215 let &l:diff= netrw_keepdiff
Bram Moolenaara6878372014-03-22 21:02:50 +010010216" call Decho("bufnr($)=".bufnr("$")." winnr($)=".winnr("$"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020010217 keepj call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010218
Bram Moolenaar446cb832008-06-24 21:56:24 +000010219 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara6878372014-03-22 21:02:50 +010010220" call Decho("copy function-local variables back to buffer netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010221 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
10222 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
10223 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
10224 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
10225 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
10226 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
10227 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
10228 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
10229 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
10230 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
10231 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
10232 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
10233 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
10234 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
10235 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
10236 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
10237
Bram Moolenaar5c736222010-01-06 20:54:52 +010010238 if a:0 > 0
10239 let b:netrw_curdir= a:1
10240 if b:netrw_curdir =~ '/$'
10241 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10242 file NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 setl bt=nowrite noswf bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020010244 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
10245 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010010246 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010247 exe "sil! keepalt file ".fnameescape(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010248 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010249 endif
10250 endif
10251
Bram Moolenaar8d043172014-01-23 14:24:41 +010010252" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010253endfun
10254
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010255" ---------------------------------------------------------------------
10256" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
10257fun! s:NetrwInsureWinVars()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010258" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010259 if !exists("w:netrw_liststyle")
10260 let curbuf = bufnr("%")
10261 let curwin = winnr()
10262 let iwin = 1
10263 while iwin <= winnr("$")
10264 exe iwin."wincmd w"
10265 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
10266 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
10267 let winvars= w:
10268 break
10269 endif
10270 let iwin= iwin + 1
10271 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020010272 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010273 if exists("winvars")
10274" call Decho("copying w#".iwin." window variables to w#".curwin)
10275 for k in keys(winvars)
10276 let w:{k}= winvars[k]
10277 endfor
10278 endif
10279 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010280" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010281endfun
10282
Bram Moolenaara6878372014-03-22 21:02:50 +010010283" ---------------------------------------------------------------------
10284" s:NetrwLcd: handles changing the (local) directory {{{2
10285fun! s:NetrwLcd(newdir)
10286" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
10287
10288 try
10289 exe 'keepj sil lcd '.fnameescape(a:newdir)
10290 catch /^Vim\%((\a\+)\)\=:E344/
10291 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
10292 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
10293 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
10294 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
10295 " forward slashes by earlier code; so check for both.
10296 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
10297 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
10298 let dirname = '\'
10299 exe 'keepj sil lcd '.fnameescape(dirname)
10300 endif
10301 endif
10302 catch /^Vim\%((\a\+)\)\=:E472/
10303 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
10304 if exists("w:netrw_prvdir")
10305 let a:newdir= w:netrw_prvdir
10306 else
10307 call s:NetrwOptionRestore("w:")
10308" call Decho("setl noma nomod nowrap")
Bram Moolenaar13600302014-05-22 18:26:40 +020010309 exe "setl ".g:netrw_bufsettings
Bram Moolenaara6878372014-03-22 21:02:50 +010010310" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
10311 let a:newdir= dirname
10312" call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
10313 return
10314 endif
10315 endtry
10316
10317" call Dret("s:NetrwLcd")
10318endfun
10319
Bram Moolenaar9964e462007-05-05 17:54:07 +000010320" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010321" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
10322" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
10323fun! s:NetrwSaveWordPosn()
10324" call Dfunc("NetrwSaveWordPosn()")
10325 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
10326" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
10327endfun
10328
10329" ---------------------------------------------------------------------
10330" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
10331" changed sorting, etc. Also see s:NetrwSaveWordPosn().
10332fun! s:NetrwRestoreWordPosn()
10333" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010334 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010335" call Dret("NetrwRestoreWordPosn")
10336endfun
10337
10338" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010339" s:RestoreBufVars: {{{2
10340fun! s:RestoreBufVars()
10341" call Dfunc("s:RestoreBufVars()")
10342
10343 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
10344 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
10345 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
10346 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
10347 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
10348 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
10349
10350" call Dret("s:RestoreBufVars")
10351endfun
10352
10353" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010354" s:RemotePathAnalysis: {{{2
10355fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020010356" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010357
Bram Moolenaara6878372014-03-22 21:02:50 +010010358 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010010359 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010360 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010010361 let s:user = substitute(a:dirname,dirpat,'\3','')
10362 let s:machine = substitute(a:dirname,dirpat,'\4','')
10363 let s:port = substitute(a:dirname,dirpat,'\5','')
10364 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020010365 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010010366 if s:machine =~ '@'
10367 let dirpat = '^\(.*\)@\(.\{-}\)$'
10368 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
10369 let s:machine = substitute(s:machine,dirpat,'\2','')
10370 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010371
10372" call Decho("set up s:method <".s:method .">")
10373" call Decho("set up s:user <".s:user .">")
10374" call Decho("set up s:machine<".s:machine.">")
10375" call Decho("set up s:port <".s:port.">")
10376" call Decho("set up s:path <".s:path .">")
10377" call Decho("set up s:fname <".s:fname .">")
10378
10379" call Dret("s:RemotePathAnalysis")
10380endfun
10381
10382" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010383" s:RemoteSystem: runs a command on a remote host using ssh {{{2
10384" Returns status
10385" Runs system() on
10386" [cd REMOTEDIRPATH;] a:cmd
10387" Note that it doesn't do shellescape(a:cmd)!
10388fun! s:RemoteSystem(cmd)
10389" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
10390 if !executable(g:netrw_ssh_cmd)
Bram Moolenaaradc21822011-04-01 18:03:16 +020010391 keepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010392 elseif !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010393 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010394 else
10395 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
10396 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
10397 if remotedir != ""
10398 let cmd= cmd.' cd '.shellescape(remotedir).";"
10399 else
10400 let cmd= cmd.' '
10401 endif
10402 let cmd= cmd.a:cmd
10403" call Decho("call system(".cmd.")")
10404 let ret= system(cmd)
10405 endif
10406" call Dret("s:RemoteSystem ".ret)
10407 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000010408endfun
10409
10410" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010412fun! s:RestoreWinVars()
10413" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000010414 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010415 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
10416 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
10417 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
10418 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
10419 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
10420 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
10421 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
10422 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
10423 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
10424 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
10425 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
10426 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000010427 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
10428 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010429 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
10430 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
10431 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
10432" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000010433endfun
10434
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010435" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
10437"
10438" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
10439" is true) and a command, :Rexplore, which call this function.
10440"
10441" s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir()
10442fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020010443 if exists("s:netrwdrag")
10444 return
10445 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020010446" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +010010447" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">")
10448
10449 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
10450" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">")
10451 exe "e ".w:netrw_rexfile
10452 unlet w:netrw_rexfile
10453" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020010454 return
10455 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010456
10457 " record current file so :Rex can return to it from netrw
10458 let w:netrw_rexfile= expand("%")
10459
10460 if !exists("w:netrw_rexlocal")
10461" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft.")")
10462 return
10463 endif
10464" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
Bram Moolenaaradc21822011-04-01 18:03:16 +020010465 if w:netrw_rexlocal
10466 keepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020010468 keepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020010470 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010010471 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020010472 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010473 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010474" call Decho("restore posn, then unlet s:rexposn_".bufnr('%'))
10475 keepj call netrw#RestorePosn(s:rexposn_{bufnr('%')})
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010476 unlet s:rexposn_{bufnr('%')}
10477 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010478" call Decho("s:rexposn_".bufnr('%')." doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010480
Bram Moolenaar5c736222010-01-06 20:54:52 +010010481 if exists("s:explore_match")
10482 exe "2match netrwMarkFile /".s:explore_match."/"
10483 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010484
10485" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
10486" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487endfun
10488
10489" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010010490" s:SaveBufVars: save selected b: variables to s: variables {{{2
10491" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000010492fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010493" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010494
10495 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
10496 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
10497 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
10498 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
10499 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
10500 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
10501
10502" call Dret("s:SaveBufVars")
10503endfun
10504
10505" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010507fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010508" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000010509 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
10510 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
10511 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
10512 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
10513 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
10514 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
10515 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
10516 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
10517 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
10518 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
10519 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
10520 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
10521 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
10522 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
10523 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
10524 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
10525 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
10526 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
10527" call Dret("s:SaveWinVars")
10528endfun
10529
10530" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010532" To allow separate windows to have their own activities, such as
10533" Explore **/pattern, several variables have been made window-oriented.
10534" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010535" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010536" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010537fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010538" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000010539 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
10540 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
10541 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
10542 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
10543 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
10544 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
10545 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
10546 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
10547 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
10548 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
10549" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010550endfun
10551
10552" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553" s:SetRexDir: set directory for :Rexplore {{{2
10554fun! s:SetRexDir(islocal,dirname)
10555" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010556 let w:netrw_rexdir = a:dirname
10557 let w:netrw_rexlocal = a:islocal
Bram Moolenaar97d62492012-11-15 21:28:22 +010010558" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559endfun
10560
10561" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010010562" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
10563" Solution from Nicolai Weibull, vim docs (:help strlen()),
10564" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010566" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
10567
10568 if v:version >= 703 && exists("*strdisplaywidth")
10569 let ret= strdisplaywidth(a:x)
10570
10571 elseif type(g:Align_xstrlen) == 1
10572 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
10573 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
10574
10575 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 " number of codepoints (Latin a + combining circumflex is two codepoints)
10577 " (comment from TM, solution from NW)
10578 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010579
10580 elseif g:Align_xstrlen == 2
10581 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
10583 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010584 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
10585
10586 elseif g:Align_xstrlen == 3
10587 " virtual length (counting, for instance, tabs as anything between 1 and
10588 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 " preceded by lam, one otherwise, etc.)
10590 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010591 let modkeep= &l:mod
10592 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 call setline(line("."),a:x)
10594 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010595 d
Bram Moolenaarff034192013-04-24 18:51:19 +020010596 keepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010010597 let &l:mod= modkeep
10598
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 else
10600 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010010601 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010603" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 return ret
10605endfun
10606
10607" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608" s:TreeListMove: {{{2
10609fun! s:TreeListMove(dir)
10610" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
10611 let curline = getline('.')
10612 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
10613 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
10614 let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010010615 let indentm1 = substitute(curindent,'^'.s:treedepthstring.' ','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616" call Decho("prvline <".prvline."> #".line(".")-1)
10617" call Decho("curline <".curline."> #".line("."))
10618" call Decho("nxtline <".nxtline."> #".line(".")+1)
10619" call Decho("curindent<".curindent.">")
10620" call Decho("indentm1 <".indentm1.">")
10621
10622 if curline !~ '/$'
10623" call Decho('regfile')
10624 if a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010625 keepj norm! 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010626 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627" call Decho("regfile srch back: ".nl)
10628 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010629 keepj norm! $
Bram Moolenaar8d043172014-01-23 14:24:41 +010010630 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631" call Decho("regfile srch fwd: ".nl)
10632 endif
10633
10634 elseif a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010635 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 let curline= line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010637 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','bWe') " search backwards From directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638" call Decho("dir srch back ind: ".nl)
10639 if nl != 0
10640 if line(".") == curline-1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010641 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010642" call Decho("dir srch back ind-1: ".nl)
10643 endif
10644 endif
10645
10646 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010647 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let curline = line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010649 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','We') " search forwards from directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000010650" call Decho("dir srch fwd ind: ".nl)
10651 if nl != 0
10652 if line(".") == curline+1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010653 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654" call Decho("dir srch fwd ind-1: ".nl)
10655 endif
10656 endif
10657
10658 endif
10659
10660" call Dret("s:TreeListMove")
10661endfun
10662
10663" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010664" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
10665" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
10666" can't be called except via emenu. But due to locale, that menu line may not be called
10667" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
10668fun! s:UpdateBuffersMenu()
10669" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010670 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000010671 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020010672 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000010673 catch /^Vim\%((\a\+)\)\=:E/
10674 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +020010675 sil keepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000010676 endtry
10677 endif
10678" call Dret("s:UpdateBuffersMenu")
10679endfun
10680
10681" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020010683" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010684fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000010685" call Dfunc("s:UseBufWinVars()")
10686 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010687 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
10688 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
10689 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
10690 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
10691 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
10692 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
10693 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
10694 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
10695 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 +000010696" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010697endfun
10698
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010699" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010700" Settings Restoration: {{{1
Bram Moolenaar83bab712005-08-01 21:58:57 +000010701let &cpo= s:keepcpo
10702unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000010703
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +000010705" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706" vim:ts=8 fdm=marker