blob: 5b1c27a8a204753ea4c361fd10b1b89df6db87bd [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 Moolenaara6878372014-03-22 21:02:50 +01003" Date: Mar 20, 2014
4" Version: 151
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 Moolenaara6878372014-03-22 21:02:50 +010025let g:loaded_netrw = "v151"
Bram Moolenaar9964e462007-05-05 17:54:07 +000026if !exists("s:NOTE")
27 let s:NOTE = 0
28 let s:WARNING = 1
29 let s:ERROR = 2
30endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000031
Bram Moolenaar1afcace2005-11-25 19:54:28 +000032let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010033setl cpo&vim
34"let g:dechofuncname=1
Bram Moolenaar8d043172014-01-23 14:24:41 +010035"DechoRemOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000036"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw)
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000038" ======================
39" Netrw Variables: {{{1
40" ======================
41
Bram Moolenaar071d4272004-06-13 20:20:40 +000042" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020043" netrw#ErrorMsg: {{{2
44" 0=note = s:NOTE
45" 1=warning = s:WARNING
46" 2=error = s:ERROR
Bram Moolenaara6878372014-03-22 21:02:50 +010047" Mar 04, 2014 : max errnum currently is 96
Bram Moolenaar5b435d62012-04-05 17:33:26 +020048fun! netrw#ErrorMsg(level,msg,errnum)
49" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
50
51 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020052" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020053 return
54 endif
55
56 if a:level == 1
57 let level= "**warning** (netrw) "
58 elseif a:level == 2
59 let level= "**error** (netrw) "
60 else
61 let level= "**note** (netrw) "
62 endif
63" call Decho("level=".level)
64
65 if g:netrw_use_errorwindow
66 " (default) netrw creates a one-line window to show error/warning
67 " messages (reliably displayed)
68
69 " record current window number for NetrwRestorePosn()'s benefit
70 let s:winBeforeErr= winnr()
71" call Decho("s:winBeforeErr=".s:winBeforeErr)
72
73 " getting messages out reliably is just plain difficult!
74 " This attempt splits the current window, creating a one line window.
75 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
76" call Decho("write to NetrwMessage buffer")
77 exe bufwinnr("NetrwMessage")."wincmd w"
78" call Decho("setl ma noro")
79 setl ma noro
80 keepj call setline(line("$")+1,level.a:msg)
81 keepj $
82 else
83" call Decho("create a NetrwMessage buffer window")
84 bo 1split
85 sil! call s:NetrwEnew()
86 sil! keepj call s:NetrwSafeOptions()
87 setl bt=nofile
88 keepj file NetrwMessage
Bram Moolenaarff034192013-04-24 18:51:19 +020089" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090 setl ma noro
91 call setline(line("$"),level.a:msg)
92 endif
93" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr())
94 if &fo !~ '[ta]'
95 syn clear
96 syn match netrwMesgNote "^\*\*note\*\*"
97 syn match netrwMesgWarning "^\*\*warning\*\*"
98 syn match netrwMesgError "^\*\*error\*\*"
99 hi link netrwMesgWarning WarningMsg
100 hi link netrwMesgError Error
101 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100102" call Decho("setl noma ro bh=wipe")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103 setl noma ro bh=wipe
104
105 else
106 " (optional) netrw will show messages using echomsg. Even if the
107 " message doesn't appear, at least it'll be recallable via :messages
108" redraw!
109 if a:level == s:WARNING
110 echohl WarningMsg
111 elseif a:level == s:ERROR
112 echohl Error
113 endif
114 echomsg level.a:msg
115" call Decho("echomsg ***netrw*** ".a:msg)
116 echohl None
117 endif
118
119" call Dret("netrw#ErrorMsg")
120endfun
121
122" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +0100123" NetrwInit: initializes variables if they haven't been defined {{{2
124" Loosely, varname = value.
125fun s:NetrwInit(varname,value)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200126" call Decho("varname<".a:varname."> value=".a:value)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100127 if !exists(a:varname)
128 if type(a:value) == 0
129 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200130 elseif type(a:value) == 1 && a:value =~ '^[{[]'
131 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100132 elseif type(a:value) == 1
133 exe "let ".a:varname."="."'".a:value."'"
134 else
135 exe "let ".a:varname."=".a:value
136 endif
137 endif
138endfun
139
140" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000141" Netrw Constants: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100142call s:NetrwInit("g:netrw_dirhist_cnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000143if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100144 call s:NetrwInit("s:THINLIST",0)
145 call s:NetrwInit("s:LONGLIST",1)
146 call s:NetrwInit("s:WIDELIST",2)
147 call s:NetrwInit("s:TREELIST",3)
148 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000149endif
150
151" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000152" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200153call s:NetrwInit("g:netrw_use_errorwindow",1)
154
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000155if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100156 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000157 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100158 elseif executable("curl")
159 let g:netrw_dav_cmd = "curl"
160 else
161 let g:netrw_dav_cmd = ""
162 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000164if !exists("g:netrw_fetch_cmd")
165 if executable("fetch")
166 let g:netrw_fetch_cmd = "fetch -o"
167 else
168 let g:netrw_fetch_cmd = ""
169 endif
170endif
171if !exists("g:netrw_ftp_cmd")
172 let g:netrw_ftp_cmd = "ftp"
173endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200174let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200175if !exists("g:netrw_ftp_options")
176 let g:netrw_ftp_options= "-i -n"
177endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000178if !exists("g:netrw_http_cmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000179 if executable("elinks")
180 let g:netrw_http_cmd = "elinks"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100181 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000182 elseif executable("links")
183 let g:netrw_http_cmd = "links"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100184 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000185 elseif executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100186 let g:netrw_http_cmd = "curl"
187 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000188 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 let g:netrw_http_cmd = "wget"
190 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000191 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192 let g:netrw_http_cmd = "fetch"
193 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000194 else
195 let g:netrw_http_cmd = ""
196 endif
197endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100198call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100199call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
200call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200201if !exists("g:netrw_scp_cmd")
202 if executable("scp")
203 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
204 elseif executable("pscp")
205 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
206 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
207 else
208 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
209 endif
210 else
211 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
212 endif
213endif
214
Bram Moolenaar5c736222010-01-06 20:54:52 +0100215call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
216call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000217
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000218if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000219 \ && exists("g:netrw_use_nt_rcp")
220 \ && g:netrw_use_nt_rcp
221 \ && executable( $SystemRoot .'/system32/rcp.exe')
222 let s:netrw_has_nt_rcp = 1
223 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000224else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000225 let s:netrw_has_nt_rcp = 0
226 let s:netrw_rcpmode = ''
227endif
228
229" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000230" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000231" Cygwin Detection ------- {{{3
232if !exists("g:netrw_cygwin")
233 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100234 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000235 let g:netrw_cygwin= 1
236 else
237 let g:netrw_cygwin= 0
238 endif
239 else
240 let g:netrw_cygwin= 0
241 endif
242endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000243" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100244call s:NetrwInit("g:netrw_alto" , &sb)
245call s:NetrwInit("g:netrw_altv" , &spr)
246call s:NetrwInit("g:netrw_banner" , 1)
247call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200248call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249call s:NetrwInit("g:netrw_chgwin" , -1)
250call s:NetrwInit("g:netrw_compress" , "gzip")
251call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200252if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
253 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
254 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000255endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200256call s:NetrwInit("g:netrw_cursor" , 2)
257let s:netrw_usercul = &cursorline
258let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar8d043172014-01-23 14:24:41 +0100259call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000260" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200261call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262call s:NetrwInit("g:netrw_dirhist_cnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200263call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100264call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200265call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266call s:NetrwInit("g:netrw_fastbrowse" , 1)
267call 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 +0000268if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000269 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
270 let g:netrw_ftp_list_cmd = "ls -lF"
271 let g:netrw_ftp_timelist_cmd = "ls -tlF"
272 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000273 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000274 let g:netrw_ftp_list_cmd = "dir"
275 let g:netrw_ftp_timelist_cmd = "dir"
276 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000277 endif
278endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100279call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000280" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000282if !exists("g:netrw_ignorenetrc")
283 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
284 let g:netrw_ignorenetrc= 1
285 else
286 let g:netrw_ignorenetrc= 0
287 endif
288endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100289call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000290if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000291 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000292 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200293 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000294 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
295 endif
296 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
297 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200298 " provide a scp-based default listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000299 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100301" call Decho("g:netrw_ssh_cmd." is not executable")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 let g:netrw_list_cmd= ""
303 endif
304endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100305call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000306" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200307if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200308 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200309 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
310endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100311if !exists("g:netrw_localcmdshell")
312 let g:netrw_localcmdshell= ""
313endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000314if !exists("g:netrw_localcopycmd")
315 if has("win32") || has("win95") || has("win64") || has("win16")
316 if g:netrw_cygwin
317 let g:netrw_localcopycmd= "cp"
318 else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100319 let g:netrw_localcopycmd= "cmd /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000320 endif
321 elseif has("unix") || has("macunix")
322 let g:netrw_localcopycmd= "cp"
323 else
324 let g:netrw_localcopycmd= ""
325 endif
326endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200327if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100328 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200329 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
330endif
331call s:NetrwInit("g:netrw_localmkdir","mkdir")
Bram Moolenaar15146672011-10-20 22:22:38 +0200332call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200333if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200334 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200335 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
336endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337if !exists("g:netrw_localmovecmd")
338 if has("win32") || has("win95") || has("win64") || has("win16")
339 if g:netrw_cygwin
340 let g:netrw_localmovecmd= "mv"
341 else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100342 let g:netrw_localmovecmd= "cmd /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000343 endif
344 elseif has("unix") || has("macunix")
345 let g:netrw_localmovecmd= "mv"
346 else
347 let g:netrw_localmovecmd= ""
348 endif
349endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200350call s:NetrwInit("g:netrw_localrmdir", "rmdir")
351if exists("g:netrw_local_rmdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200352 let g:netrw_localrmdir= g:netrw_local_rmdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200353 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
354endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
356" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000357if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000359endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000361 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
362endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000363" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
365call s:NetrwInit("g:netrw_maxfilenamelen", 32)
366call s:NetrwInit("g:netrw_menu" , 1)
367call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200368call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~ '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100369call s:NetrwInit("g:netrw_retmap" , 0)
370if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
371 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
372elseif has("win32") || has("win95") || has("win64") || has("win16")
373 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
374else
375 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000376endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100377call s:NetrwInit("g:netrw_preview" , 0)
378call s:NetrwInit("g:netrw_scpport" , "-P")
379call s:NetrwInit("g:netrw_sshport" , "-p")
380call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
381call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
382call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100383call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
384" Default values - q-s ---------- {{{3
385call s:NetrwInit("g:netrw_quickhelp",0)
386let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
387 \ "%:create new file d:create new directory",
388 \ "o:split&open v:vert-split&open",
389 \ "i:style qf:file info O:obtain r:reverse p:preview",
390 \ "mf:mark file mt:set target mm:move mc:copy",
391 \ "-bookmarks- mb:make mB:delete qb:list gb:go to",
392 \ "-history- qb:list u:go up U:go down",
393 \ "-targets- mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100394" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
395call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200396call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100397call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
398call s:NetrwInit("g:netrw_sort_options" , "")
399call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000400if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100401 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200402 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100403 else
404 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000405 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000406endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100407call s:NetrwInit("g:netrw_special_syntax" , 0)
408call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100409call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000410" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100411call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200412if !exists("g:netrw_xstrlen")
413 if exists("g:Align_xstrlen")
414 let g:netrw_xstrlen= g:Align_xstrlen
415 elseif exists("g:drawit_xstrlen")
416 let g:netrw_xstrlen= g:drawit_xstrlen
417 elseif &enc == "latin1" || !has("multi_byte")
418 let g:netrw_xstrlen= 0
419 else
420 let g:netrw_xstrlen= 1
421 endif
422endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100423call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100424call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200425call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200426if g:netrw_winsize == 0|let g:netrw_winsize= -1|endif
427if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000428" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000429" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100430call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200431if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200432 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200433else
Bram Moolenaarff034192013-04-24 18:51:19 +0200434 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200435endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200436call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100437call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
438call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100439if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100440 let s:treedepthstring= "│ "
441else
442 let s:treedepthstring= "| "
443endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000444
445" BufEnter event ignored by decho when following variable is true
446" Has a side effect that doau BufReadPost doesn't work, so
447" files read by network transfer aren't appropriately highlighted.
448"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaaradc21822011-04-01 18:03:16 +0200450" ======================
451" Netrw Initialization: {{{1
452" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200453if 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 +0100454" call Decho("installed beval events")
Bram Moolenaara6878372014-03-22 21:02:50 +0100455 let &l:bexpr = "netrw#BalloonHelp()"
456 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100457 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
458 au VimEnter * let s:initbeval= &beval
459"else " Decho
460" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700") | endif
461" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval") | endif
462" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists") | endif
463" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists") | endif
464" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting") | endif
465" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists") | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200466endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200467au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200468
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000469" ==============================
470" Netrw Utility Functions: {{{1
471" ==============================
472
Bram Moolenaaradc21822011-04-01 18:03:16 +0200473" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100474" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100475if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
476" call Decho("loading netrw#BalloonHelp()")
Bram Moolenaara6878372014-03-22 21:02:50 +0100477 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100478 if &ft != "netrw"
479 return ""
480 endif
481 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
482 let mesg= ""
483 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
484 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
485 elseif getline(v:beval_lnum) =~ '^"\s*/'
486 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
487 elseif v:beval_text == "Sorted" || v:beval_text == "by"
488 let mesg = 's: sort by name, time, or file size r: reverse sorting order mt: mark target'
489 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
490 let mesg = "S: edit sorting sequence"
491 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
492 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
493 elseif v:beval_text == "Quick" || v:beval_text == "Help"
494 let mesg = "Help: press <F1>"
495 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
496 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
497 else
498 let mesg= ""
499 endif
500 return mesg
501 endfun
502"else " Decho
503" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -")|endif
504" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval") |endif
505" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled") |endif
506" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on=".g:syntax_on) |endif
507" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists") |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200508endif
509
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200511" netrw#Explore: launch the local browser in the directory of the current file {{{2
512" indx: == -1: Nexplore
513" == -2: Pexplore
514" == +: this is overloaded:
515" * If Nexplore/Pexplore is in use, then this refers to the
516" indx'th item in the w:netrw_explore_list[] of items which
517" matched the */pattern **/pattern *//pattern **//pattern
518" * If Hexplore or Vexplore, then this will override
519" g:netrw_winsize to specify the qty of rows or columns the
520" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100521" 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 +0200522" dosplit==1: the window will be split before running the local browser
523" style == 0: Explore style == 1: Explore!
524" == 2: Hexplore style == 3: Hexplore!
525" == 4: Vexplore style == 5: Vexplore!
526" == 6: Texplore
527fun! netrw#Explore(indx,dosplit,style,...)
528" 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("%"))
529 if !exists("b:netrw_curdir")
530 let b:netrw_curdir= getcwd()
Bram Moolenaara6878372014-03-22 21:02:50 +0100531" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200532 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100533
534 " record current file for Rexplore's benefit
535 if &ft != "netrw"
536 let w:netrw_rexfile= expand("%:p")
537 endif
538
539 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200540 let curdir = simplify(b:netrw_curdir)
541 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200542 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
543 let curdir= substitute(curdir,'\','/','g')
544 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100545" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">")
546
547 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
548 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
549 " try Explore again.
550 if a:0 > 0
551" call Decho('considering retry: a:1<'.a:1.'>: '.
552 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
553 \ ((filereadable(a:1))? 'is readable' : 'is not readable').', '.
554 \ ((isdirectory(a:1))? 'is a directory' : 'is not a directory'))
555 if a:1 =~ "\\\s" && !filereadable(a:1) && !isdirectory(a:1)
556" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">")
557 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
558" call Dret("netrw#Explore : returning from retry")
559 return
560" else " Decho
561" call Decho("retry not needed")
562 endif
563 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200564
565 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100566 if has("clipboard")
567 sil! let keepregstar = @*
568 sil! let keepregplus = @+
569 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200570 sil! let keepregslash= @/
571
Bram Moolenaar8d043172014-01-23 14:24:41 +0100572 " if dosplit
573 " -or- file has been modified AND file not hidden when abandoned
574 " -or- Texplore used
575 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara6878372014-03-22 21:02:50 +0100576" 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 +0200577 call s:SaveWinVars()
578 let winsz= g:netrw_winsize
579 if a:indx > 0
580 let winsz= a:indx
581 endif
582
583 if a:style == 0 " Explore, Sexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100584" call Decho("style=0: Explore or Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200585 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
586 exe winsz."wincmd s"
587
588 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100589" call Decho("style=1: Explore! or Sexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200590 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
591 exe "keepalt ".winsz."wincmd v"
592
593 elseif a:style == 2 " Hexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100594" call Decho("style=2: Hexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200595 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
596 exe "keepalt bel ".winsz."wincmd s"
597
598 elseif a:style == 3 " Hexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100599" call Decho("style=3: Hexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200600 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
601 exe "keepalt abo ".winsz."wincmd s"
602
603 elseif a:style == 4 " Vexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100604" call Decho("style=4: Vexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200605 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
606 exe "keepalt lefta ".winsz."wincmd v"
607
608 elseif a:style == 5 " Vexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100609" call Decho("style=5: Vexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200610 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
611 exe "keepalt rightb ".winsz."wincmd v"
612
613 elseif a:style == 6 " Texplore
614 call s:SaveBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +0100615" call Decho("style = 6: Texplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200616 exe "keepalt tabnew ".fnameescape(curdir)
617 call s:RestoreBufVars()
618 endif
619 call s:RestoreWinVars()
620" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +0100621" 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 +0200622 endif
623 keepj norm! 0
624
625 if a:0 > 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100626" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200627 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara6878372014-03-22 21:02:50 +0100628" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin")
Bram Moolenaarff034192013-04-24 18:51:19 +0200629 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara6878372014-03-22 21:02:50 +0100630" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200631 elseif a:1 == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +0100632" call Decho("..case a:1<".a:1.">: matches .")
Bram Moolenaarff034192013-04-24 18:51:19 +0200633 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
634 if dirname !~ '/$'
635 let dirname= dirname."/"
636 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100637" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200638 elseif a:1 =~ '\$'
Bram Moolenaara6878372014-03-22 21:02:50 +0100639" call Decho("..case a:1<".a:1.">: matches ending $")
Bram Moolenaarff034192013-04-24 18:51:19 +0200640 let dirname= simplify(expand(a:1))
Bram Moolenaara6878372014-03-22 21:02:50 +0100641" call Decho("..using user-specified dirname<".dirname."> with $env-var")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200642 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +0100643" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200644 let dirname= simplify(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100645" call Decho("..using user-specified dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200646 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100647" call Decho("..case a:1: pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200648 let dirname= a:1
649 endif
650 else
651 " clear explore
Bram Moolenaara6878372014-03-22 21:02:50 +0100652" call Decho("case a:0=".a:0.": clearing Explore list")
Bram Moolenaarff034192013-04-24 18:51:19 +0200653 call s:NetrwClearExplore()
654" call Dret("netrw#Explore : cleared list")
655 return
656 endif
657
Bram Moolenaara6878372014-03-22 21:02:50 +0100658" call Decho("dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200659 if dirname =~ '\.\./\=$'
660 let dirname= simplify(fnamemodify(dirname,':p:h'))
661 elseif dirname =~ '\.\.' || dirname == '.'
662 let dirname= simplify(fnamemodify(dirname,':p'))
663 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100664" call Decho("dirname<".dirname."> (after simplify)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200665
666 if dirname =~ '^\*//'
667 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100668" call Decho("case starpat=1: Explore *//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200669 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
670 let starpat= 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100671" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
673
674 elseif dirname =~ '^\*\*//'
675 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100676" call Decho("case starpat=2: Explore **//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200677 let pattern= substitute(dirname,'^\*\*//','','')
678 let starpat= 2
Bram Moolenaara6878372014-03-22 21:02:50 +0100679" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200680
681 elseif dirname =~ '/\*\*/'
682 " handle .../**/.../filepat
Bram Moolenaara6878372014-03-22 21:02:50 +0100683" call Decho("case starpat=4: Explore .../**/.../filepat")
Bram Moolenaarff034192013-04-24 18:51:19 +0200684 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
685 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
686 let b:netrw_curdir = prefixdir
687 else
688 let b:netrw_curdir= getcwd().'/'.prefixdir
689 endif
690 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
691 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100692" call Decho("..pwd<".getcwd()."> dirname<".dirname.">")
693" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200694
695 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200696 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200697 let starpat= 3
Bram Moolenaara6878372014-03-22 21:02:50 +0100698" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200699
700 elseif dirname=~ '^\*\*/'
701 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
702 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100703" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200704
705 else
706 let starpat= 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100707" call Decho("case starpat=0: default")
Bram Moolenaarff034192013-04-24 18:51:19 +0200708 endif
709
710 if starpat == 0 && a:indx >= 0
711 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara6878372014-03-22 21:02:50 +0100712" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200713 if dirname == ""
714 let dirname= curfiledir
Bram Moolenaara6878372014-03-22 21:02:50 +0100715" call Decho("..empty dirname, using current file's directory<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200716 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200717 if dirname =~ '^scp://' || dirname =~ '^ftp://'
718 call netrw#Nread(2,dirname)
719 "call s:NetrwBrowse(0,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200720 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200721 if dirname == ""
722 let dirname= getcwd()
723 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +0100724 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
725 " depending on whether backslashes have been converted to forward slashes by earlier code).
726 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200727 let dirname= b:netrw_curdir."/".dirname
728 endif
729 elseif dirname !~ '^/'
730 let dirname= b:netrw_curdir."/".dirname
731 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100732" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +0100734" call Decho("win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 endif
736 if exists("w:netrw_bannercnt")
737 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
738 " If one wants to return the same place in the netrw window, use :Rex instead.
739 exe w:netrw_bannercnt
740 endif
741
Bram Moolenaara6878372014-03-22 21:02:50 +0100742" call Decho("curdir<".curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 " ---------------------------------------------------------------------
744 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
745" if has("win32") || has("win95") || has("win64") || has("win16")
746" keepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
747" else
748" keepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
749" endif
750 " ---------------------------------------------------------------------
751
752 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
753 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
754 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
755 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
756 elseif a:indx <= 0
757 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara6878372014-03-22 21:02:50 +0100758" 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 +0200759 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100760" call Decho("..set up <s-up> and <s-down> maps")
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let s:didstarstar= 1
762 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
763 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
764 endif
765
766 if has("path_extra")
Bram Moolenaara6878372014-03-22 21:02:50 +0100767" call Decho("..starpat=".starpat.": has +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 if !exists("w:netrw_explore_indx")
769 let w:netrw_explore_indx= 0
770 endif
771
772 let indx = a:indx
Bram Moolenaara6878372014-03-22 21:02:50 +0100773" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]")
Bram Moolenaarff034192013-04-24 18:51:19 +0200774
775 if indx == -1
776 " Nexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100777" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 if !exists("w:netrw_explore_list") " sanity check
779 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 +0100780 if has("clipboard")
781 sil! let @* = keepregstar
782 sil! let @+ = keepregstar
783 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 sil! let @/ = keepregslash
785" call Dret("netrw#Explore")
786 return
787 endif
788 let indx= w:netrw_explore_indx
789 if indx < 0 | let indx= 0 | endif
790 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
791 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100792" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
794 let indx= indx + 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100795" call Decho("....indx=".indx." (Nexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 endwhile
797 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100798" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200799
800 elseif indx == -2
801 " Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100802" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 if !exists("w:netrw_explore_list") " sanity check
804 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 +0100805 if has("clipboard")
806 sil! let @* = keepregstar
807 sil! let @+ = keepregstar
808 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 sil! let @/ = keepregslash
810" call Dret("netrw#Explore")
811 return
812 endif
813 let indx= w:netrw_explore_indx
814 if indx < 0 | let indx= 0 | endif
815 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
816 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100817" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 while indx >= 0 && curfile == w:netrw_explore_list[indx]
819 let indx= indx - 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100820" call Decho("....indx=".indx." (Pexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 endwhile
822 if indx < 0 | let indx= 0 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100823" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200824
825 else
826 " Explore -- initialize
827 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100828" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 keepj keepalt call s:NetrwClearExplore()
830 let w:netrw_explore_indx= 0
831 if !exists("b:netrw_curdir")
832 let b:netrw_curdir= getcwd()
833 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100834" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 " switch on starpat to build the w:netrw_explore_list of files
837 if starpat == 1
838 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100839" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls)
840" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 try
842 exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
843 catch /^Vim\%((\a\+)\)\=:E480/
844 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
845" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
846 return
847 endtry
848 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
849 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
850
851 elseif starpat == 2
852 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100853" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)")
854" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 try
856 exe "sil keepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
857 catch /^Vim\%((\a\+)\)\=:E480/
858 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
859 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100860 if has("clipboard")
861 sil! let @* = keepregstar
862 sil! let @+ = keepregstar
863 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 sil! let @/ = keepregslash
865" call Dret("netrw#Explore : no files matched pattern")
866 return
867 endtry
868 let s:netrw_curdir = b:netrw_curdir
869 let w:netrw_explore_list = getqflist()
870 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
871 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
872
873 elseif starpat == 3
874 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100875" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 let filepat= substitute(dirname,'^\*/','','')
877 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara6878372014-03-22 21:02:50 +0100878" call Decho("....b:netrw_curdir<".b:netrw_curdir.">")
879" call Decho("....filepat<".filepat.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200880 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
881 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
882
883 elseif starpat == 4
884 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100885" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200886 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
887 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
888 endif " switch on starpat to build w:netrw_explore_list
889
890 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara6878372014-03-22 21:02:50 +0100891" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">")
892" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +0200893
894 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
895 keepalt keepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +0100896 if has("clipboard")
897 sil! let @* = keepregstar
898 sil! let @+ = keepregstar
899 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200900 sil! let @/ = keepregslash
901" call Dret("netrw#Explore : no files matched")
902 return
903 endif
904 endif " if indx ... endif
905
906 " NetrwStatusLine support - for exploring support
907 let w:netrw_explore_indx= indx
Bram Moolenaara6878372014-03-22 21:02:50 +0100908" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +0200909
910 " wrap the indx around, but issue a note
911 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100912" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200913 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
914 let w:netrw_explore_indx= indx
915 keepalt keepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
916 endif
917
918 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara6878372014-03-22 21:02:50 +0100919" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +0100921" call Decho("....newdir<".newdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200922
Bram Moolenaara6878372014-03-22 21:02:50 +0100923" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 call netrw#LocalBrowseCheck(newdir)
925 if !exists("w:netrw_liststyle")
926 let w:netrw_liststyle= g:netrw_liststyle
927 endif
928 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
929 keepalt keepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
930 else
931 keepalt keepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
932 endif
933 let w:netrw_explore_mtchcnt = indx + 1
934 let w:netrw_explore_bufnr = bufnr("%")
935 let w:netrw_explore_line = line(".")
936 keepalt keepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara6878372014-03-22 21:02:50 +0100937" 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 +0200938
939 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100940" call Decho("..your vim does not have +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 if !exists("g:netrw_quiet")
942 keepalt keepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
943 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100944 if has("clipboard")
945 sil! let @* = keepregstar
946 sil! let @+ = keepregstar
947 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 sil! let @/ = keepregslash
949" call Dret("netrw#Explore : missing +path_extra")
950 return
951 endif
952
953 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100954" call Decho("..default case: Explore newdir<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
956 sil! unlet w:netrw_treedict
957 sil! unlet w:netrw_treetop
958 endif
959 let newdir= dirname
960 if !exists("b:netrw_curdir")
961 keepj call netrw#LocalBrowseCheck(getcwd())
962 else
963 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
964 endif
965 endif
966
967 " visual display of **/ **// */ Exploration files
Bram Moolenaara6878372014-03-22 21:02:50 +0100968" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"))
969" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100971" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +0100973 " only update match list when current directory isn't the same as before
Bram Moolenaara6878372014-03-22 21:02:50 +0100974" call Decho("only update match list when current directory not the same as before")
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 let s:explore_prvdir = b:netrw_curdir
976 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +0100977 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 if b:netrw_curdir !~ '/$'
979 let dirlen= dirlen + 1
980 endif
981 let prvfname= ""
982 for fname in w:netrw_explore_list
Bram Moolenaara6878372014-03-22 21:02:50 +0100983" call Decho("fname<".fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 if fname =~ '^'.b:netrw_curdir
985 if s:explore_match == ""
986 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
987 else
988 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
989 endif
990 elseif fname !~ '^/' && fname != prvfname
991 if s:explore_match == ""
992 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
993 else
994 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
995 endif
996 endif
997 let prvfname= fname
998 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +0100999" call Decho("explore_match<".s:explore_match.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 exe "2match netrwMarkFile /".s:explore_match."/"
1001 endif
1002 echo "<s-up>==Pexplore <s-down>==Nexplore"
1003 else
1004 2match none
1005 if exists("s:explore_match") | unlet s:explore_match | endif
1006 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1007 echo " "
Bram Moolenaara6878372014-03-22 21:02:50 +01001008" call Decho("cleared explore match list")
Bram Moolenaarff034192013-04-24 18:51:19 +02001009 endif
1010
Bram Moolenaara6878372014-03-22 21:02:50 +01001011 " since Explore may be used to initialize netrw's browser,
1012 " there's no danger of a late FocusGained event on initialization.
1013 " Consequently, set s:netrw_events to 2.
1014 let s:netrw_events= 2
1015 if has("clipboard")
1016 sil! let @* = keepregstar
1017 sil! let @+ = keepregstar
1018 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 sil! let @/ = keepregslash
1020" call Dret("netrw#Explore : @/<".@/.">")
1021endfun
1022
1023" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001024" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
1025fun! netrw#Lexplore(...)
1026" call Dfunc("netrw#Lexplore() a:0=".a:0)
Bram Moolenaara6878372014-03-22 21:02:50 +01001027 if a:0 > 0 && a:1 != ""
1028 " if a netrw window is already on the left-side of the tab
1029 " and a directory has been specified, explore with that
1030 " directory.
1031 let lexwinnr= winnr()
1032 exe "1wincmd w"
1033 if &ft == "netrw"
1034 exe "Explore ".fnameescape(a:1)
1035 exe lexwinnr."wincmd w"
1036 endif
1037 exe lexwinnr."wincmd w"
1038" call Dret("netrw#Lexplore")
1039 return
1040 endif
1041
Bram Moolenaar8d043172014-01-23 14:24:41 +01001042 if exists("t:netrw_lexbufnr")
1043 " close down netrw explorer window
1044 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
1045 if lexwinnr != -1
1046 let curwin = winnr()
1047 exe lexwinnr."wincmd w"
1048 close
1049 exe curwin."wincmd w"
1050 endif
1051 unlet t:netrw_lexbufnr
1052
1053 else
1054 " open netrw explorer window
1055 exe "1wincmd w"
1056 let keep_altv = g:netrw_altv
1057 let g:netrw_altv = 0
1058 if a:0 > 0 && a:1 != ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001059 exe "Vexplore ".fnameescape(a:1)
Bram Moolenaar8d043172014-01-23 14:24:41 +01001060 else
1061 Vexplore .
1062 endif
1063 let g:netrw_altv = keep_altv
1064 let t:netrw_lexbufnr = bufnr("%")
1065 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001066 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
1067 let g:netrw_chgwin= 2
1068 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001069" call Dret("netrw#Lexplore")
1070endfun
1071
1072" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001073" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001074" supports :NetrwClean -- remove netrw from first directory on runtimepath
1075" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001076fun! netrw#Clean(sys)
1077" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001078
1079 if a:sys
1080 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1081 else
1082 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1083 endif
1084" call Decho("choice=".choice)
1085 let diddel= 0
1086 let diddir= ""
1087
1088 if choice == 1
1089 for dir in split(&rtp,',')
1090 if filereadable(dir."/plugin/netrwPlugin.vim")
1091" call Decho("removing netrw-related files from ".dir)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001092 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1093 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1094 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1095 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1096 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1097 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 +00001098 let diddir= dir
1099 let diddel= diddel + 1
1100 if !a:sys|break|endif
1101 endif
1102 endfor
1103 endif
1104
1105 echohl WarningMsg
1106 if diddel == 0
1107 echomsg "netrw is either not installed or not removable"
1108 elseif diddel == 1
1109 echomsg "removed one copy of netrw from <".diddir.">"
1110 else
1111 echomsg "removed ".diddel." copies of netrw"
1112 endif
1113 echohl None
1114
Bram Moolenaara6878372014-03-22 21:02:50 +01001115" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001116endfun
1117
Bram Moolenaar5c736222010-01-06 20:54:52 +01001118" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001119" netrw#MakeTgt: make a target out of the directory name provided {{{2
1120fun! netrw#MakeTgt(dname)
1121" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1122 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
1123 let svpos = netrw#SavePosn()
1124 let s:netrwmftgt_islocal= (a:dname !~ '^\a\+://')
1125" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal)
1126 if s:netrwmftgt_islocal
1127 let netrwmftgt= simplify(a:dname)
1128 else
1129 let netrwmftgt= a:dname
1130 endif
1131 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1132 " re-selected target, so just clear it
1133 unlet s:netrwmftgt s:netrwmftgt_islocal
1134 else
1135 let s:netrwmftgt= netrwmftgt
1136 endif
1137 if g:netrw_fastbrowse <= 1
1138 call s:NetrwRefresh((b:netrw_curdir !~ '\a\+://'),b:netrw_curdir)
1139 endif
1140 call netrw#RestorePosn(svpos)
1141" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001142endfun
1143
Bram Moolenaara6878372014-03-22 21:02:50 +01001144" ---------------------------------------------------------------------
1145" netrw#Obtain: {{{2
1146" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001147" islocal=0 obtain from remote source
1148" =1 obtain from local source
1149" fname : a filename or a list of filenames
1150" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001151fun! netrw#Obtain(islocal,fname,...)
1152" 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 +02001153 " NetrwStatusLine support - for obtaining support
1154
1155 if type(a:fname) == 1
1156 let fnamelist= [ a:fname ]
1157 elseif type(a:fname) == 3
1158 let fnamelist= a:fname
1159 else
1160 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 +01001161" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001162 return
1163 endif
1164" call Decho("fnamelist<".string(fnamelist).">")
1165 if a:0 > 0
1166 let tgtdir= a:1
1167 else
1168 let tgtdir= getcwd()
1169 endif
1170" call Decho("tgtdir<".tgtdir.">")
1171
1172 if exists("b:netrw_islocal") && b:netrw_islocal
1173 " obtain a file from local b:netrw_curdir to (local) tgtdir
1174" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir)
1175 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1176 let topath= s:ComposePath(tgtdir,"")
1177 if (has("win32") || has("win95") || has("win64") || has("win16"))
1178 " transfer files one at time
1179" call Decho("transfer files one at a time")
1180 for fname in fnamelist
1181" call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")")
1182 call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1183 if v:shell_error != 0
1184 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1185" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1186 return
1187 endif
1188 endfor
1189 else
1190 " transfer files with one command
1191" call Decho("transfer files with one command")
1192 let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)"))
1193" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")")
1194 call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1195 if v:shell_error != 0
1196 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1197" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1198 return
1199 endif
1200 endif
1201 elseif !exists("b:netrw_curdir")
1202 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1203 else
1204 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1205 endif
1206
1207 else
1208 " obtain files from remote b:netrw_curdir to local tgtdir
1209" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir)
1210 if type(a:fname) == 1
1211 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1212 endif
1213 call s:NetrwMethod(b:netrw_curdir)
1214
1215 if b:netrw_method == 4
1216 " obtain file using scp
1217" call Decho("obtain via scp (method#4)")
1218 if exists("g:netrw_port") && g:netrw_port != ""
1219 let useport= " ".g:netrw_scpport." ".g:netrw_port
1220 else
1221 let useport= ""
1222 endif
1223 if b:netrw_fname =~ '/'
1224 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1225 else
1226 let path= ""
1227 endif
1228 let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)'))
1229" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1))
1230 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1)
1231
1232 elseif b:netrw_method == 2
1233 " obtain file using ftp + .netrc
1234" call Decho("obtain via ftp+.netrc (method #2)")
1235 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
1236 let tmpbufnr= bufnr("%")
1237 setl ff=unix
1238 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
1239 keepj put =g:netrw_ftpmode
1240" call Decho("filter input: ".getline('$'))
1241 endif
1242
1243 if exists("b:netrw_fname") && b:netrw_fname != ""
1244 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
1245" call Decho("filter input: ".getline('$'))
1246 endif
1247
1248 if exists("g:netrw_ftpextracmd")
1249 keepj put =g:netrw_ftpextracmd
1250" call Decho("filter input: ".getline('$'))
1251 endif
1252 for fname in fnamelist
1253 call setline(line("$")+1,'get "'.fname.'"')
1254" call Decho("filter input: ".getline('$'))
1255 endfor
1256 if exists("g:netrw_port") && g:netrw_port != ""
1257" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1258 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
1259 else
1260" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1261 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
1262 endif
1263 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1264 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1265 let debugkeep= &debug
1266 setl debug=msg
1267 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1268 let &debug= debugkeep
1269 endif
1270
1271 elseif b:netrw_method == 3
1272 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
1273" call Decho("obtain via ftp+mipf (method #3)")
1274 call s:SaveBufVars()|sil keepjumps new|call s:RestoreBufVars()
1275 let tmpbufnr= bufnr("%")
1276 setl ff=unix
1277
1278 if exists("g:netrw_port") && g:netrw_port != ""
1279 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
1280" call Decho("filter input: ".getline('$'))
1281 else
1282 keepj put ='open '.g:netrw_machine
1283" call Decho("filter input: ".getline('$'))
1284 endif
1285
1286 if exists("g:netrw_uid") && g:netrw_uid != ""
1287 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1288 keepj put =g:netrw_uid
1289" call Decho("filter input: ".getline('$'))
1290 if exists("s:netrw_passwd") && s:netrw_passwd != ""
1291 keepj put ='\"'.s:netrw_passwd.'\"'
1292 endif
1293" call Decho("filter input: ".getline('$'))
1294 elseif exists("s:netrw_passwd")
1295 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
1296" call Decho("filter input: ".getline('$'))
1297 endif
1298 endif
1299
1300 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
1301 keepj put =g:netrw_ftpmode
1302" call Decho("filter input: ".getline('$'))
1303 endif
1304
1305 if exists("b:netrw_fname") && b:netrw_fname != ""
1306 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
1307" call Decho("filter input: ".getline('$'))
1308 endif
1309
1310 if exists("g:netrw_ftpextracmd")
1311 keepj put =g:netrw_ftpextracmd
1312" call Decho("filter input: ".getline('$'))
1313 endif
1314
1315 if exists("g:netrw_ftpextracmd")
1316 keepj put =g:netrw_ftpextracmd
1317" call Decho("filter input: ".getline('$'))
1318 endif
1319 for fname in fnamelist
1320 keepj call setline(line("$")+1,'get "'.fname.'"')
1321 endfor
1322" call Decho("filter input: ".getline('$'))
1323
1324 " perform ftp:
1325 " -i : turns off interactive prompting from ftp
1326 " -n unix : DON'T use <.netrc>, even though it exists
1327 " -n win32: quit being obnoxious about password
1328 keepj norm! 1Gdd
1329" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
1330 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
1331 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1332 if getline(1) !~ "^$"
1333" call Decho("error<".getline(1).">")
1334 if !exists("g:netrw_quiet")
1335 keepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
1336 endif
1337 endif
1338 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaara6878372014-03-22 21:02:50 +01001339" call Dfunc("netrw#Obtain : unsupported method")
Bram Moolenaarff034192013-04-24 18:51:19 +02001340 return
1341 endif
1342
1343 " restore status line
1344 if type(a:fname) == 1 && exists("s:netrw_users_stl")
1345 keepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
1346 endif
1347
1348 endif
1349
1350 " cleanup
1351 if exists("tmpbufnr")
1352 if bufnr("%") != tmpbufnr
1353 exe tmpbufnr."bw!"
1354 else
1355 q!
1356 endif
1357 endif
1358
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" call Dret("netrw#Obtain")
1360endfun
1361
1362" ---------------------------------------------------------------------
1363" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1364fun! netrw#Nread(mode,fname)
1365" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
1366 call netrw#SavePosn()
1367 call netrw#NetRead(a:mode,a:fname)
1368 call netrw#RestorePosn()
1369
1370 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1371 if exists("w:netrw_bannercnt")
1372 " start with cursor just after the banner
1373 exe w:netrw_bannercnt
1374 endif
1375 endif
1376" call Dret("netrw#Nread")
1377endfun
1378
1379" ------------------------------------------------------------------------
1380" s:NetrwOptionRestore: restore options (based on prior s:NetrwOptionSave) {{{2
1381fun! s:NetrwOptionRestore(vt)
1382" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1383" 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)
1384 if !exists("{a:vt}netrw_optionsave")
1385 if exists("s:nbcd_curpos_{bufnr('%')}")
1386" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
1387 keepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
1388" call Decho("win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1389" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1390 unlet s:nbcd_curpos_{bufnr('%')}
1391 else
1392" call Decho("no previous position")
1393 endif
1394" 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)
1395" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1396" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
1397 return
1398 endif
1399 unlet {a:vt}netrw_optionsave
1400
1401 if exists("+acd")
1402 if exists("{a:vt}netrw_acdkeep")
1403" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1404 let curdir = getcwd()
1405 let &l:acd = {a:vt}netrw_acdkeep
1406 unlet {a:vt}netrw_acdkeep
1407 if &l:acd
1408 call s:NetrwLcd(curdir)
1409 endif
1410 endif
1411 endif
1412 if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif
1413 if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif
1414 if g:netrw_liststyle != s:TREELIST
1415 if exists("{a:vt}netrw_bhkeep") |let &l:bh = {a:vt}netrw_bhkeep |unlet {a:vt}netrw_bhkeep |endif
1416 endif
1417 if exists("{a:vt}netrw_blkeep") |let &l:bl = {a:vt}netrw_blkeep |unlet {a:vt}netrw_blkeep |endif
1418 if exists("{a:vt}netrw_btkeep") |let &l:bt = {a:vt}netrw_btkeep |unlet {a:vt}netrw_btkeep |endif
1419 if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif
1420 if exists("{a:vt}netrw_cedit") |let &cedit = {a:vt}netrw_cedit |unlet {a:vt}netrw_cedit |endif
1421 if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif
1422 if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif
1423 if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif
1424 if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif
1425 if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif
1426 if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif
1427 if exists("{a:vt}netrw_fenkeep") |let &l:fen = {a:vt}netrw_fenkeep |unlet {a:vt}netrw_fenkeep |endif
1428 if exists("{a:vt}netrw_ffkeep") |let &l:ff = {a:vt}netrw_ffkeep |unlet {a:vt}netrw_ffkeep |endif
1429 if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif
1430 if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif
1431 if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif
1432 if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif
1433 if exists("{a:vt}netrw_iskkeep") |let &l:isk = {a:vt}netrw_iskkeep |unlet {a:vt}netrw_iskkeep |endif
1434 if exists("{a:vt}netrw_lskeep") |let &l:ls = {a:vt}netrw_lskeep |unlet {a:vt}netrw_lskeep |endif
1435 if exists("{a:vt}netrw_makeep") |let &l:ma = {a:vt}netrw_makeep |unlet {a:vt}netrw_makeep |endif
1436 if exists("{a:vt}netrw_magickeep")|let &l:magic = {a:vt}netrw_magickeep |unlet {a:vt}netrw_magickeep|endif
1437 if exists("{a:vt}netrw_modkeep") |let &l:mod = {a:vt}netrw_modkeep |unlet {a:vt}netrw_modkeep |endif
1438 if exists("{a:vt}netrw_nukeep") |let &l:nu = {a:vt}netrw_nukeep |unlet {a:vt}netrw_nukeep |endif
1439 if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif
1440 if exists("{a:vt}netrw_rokeep") |let &l:ro = {a:vt}netrw_rokeep |unlet {a:vt}netrw_rokeep |endif
1441 if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif
1442 if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif
1443 if has("clipboard")
1444 if exists("{a:vt}netrw_starkeep") |let @* = {a:vt}netrw_starkeep |unlet {a:vt}netrw_starkeep |endif
1445 endif
1446 " Problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1447" if exists("{a:vt}netrw_tskeep") |let &l:ts = {a:vt}netrw_tskeep |unlet {a:vt}netrw_tskeep |endif
1448 if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif
1449 if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif
1450 if exists("{a:vt}netrw_wrapkeep") |let &l:wrap = {a:vt}netrw_wrapkeep |unlet {a:vt}netrw_wrapkeep |endif
1451 if exists("{a:vt}netrw_writekeep")|let &l:write = {a:vt}netrw_writekeep |unlet {a:vt}netrw_writekeep|endif
1452 if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif
1453 if exists("{a:vt}netrw_swfkeep")
1454 if &directory == ""
1455 " user hasn't specified a swapfile directory;
1456 " netrw will temporarily set the swapfile directory
1457 " to the current directory as returned by getcwd().
1458 let &l:directory= getcwd()
1459 sil! let &l:swf = {a:vt}netrw_swfkeep
1460 setl directory=
1461 unlet {a:vt}netrw_swfkeep
1462 elseif &l:swf != {a:vt}netrw_swfkeep
1463 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1464 sil! let &l:swf= {a:vt}netrw_swfkeep
1465 unlet {a:vt}netrw_swfkeep
1466 endif
1467 endif
1468 if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
1469 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1470 if exists("{a:vt}netrw_dirkeep")
1471 call s:NetrwLcd(dirkeep)
1472 unlet {a:vt}netrw_dirkeep
1473 endif
1474 endif
1475 if has("clipboard")
1476 if exists("{a:vt}netrw_regstar") |sil! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif
1477 endif
1478 if exists("{a:vt}netrw_regslash")|sil! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif
1479 if exists("s:nbcd_curpos_{bufnr('%')}")
1480" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
1481 keepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
1482" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1483 if exists("s:nbcd_curpos_".bufnr('%'))
1484 unlet s:nbcd_curpos_{bufnr('%')}
1485 endif
1486 else
1487" call Decho("no previous position")
1488 endif
1489
1490" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1491" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"))
1492" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1493" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"))
1494" call Decho("ts=".&l:ts)
1495 " Moved the filetype detect here from NetrwGetFile() because remote files
1496 " were having their filetype detect-generated settings overwritten by
1497 " NetrwOptionRestore.
1498 if &ft != "netrw"
1499" call Decho("filetype detect (ft=".&ft.")")
1500 filetype detect
1501 endif
1502" 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)
1503" call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
1504endfun
1505
1506" ---------------------------------------------------------------------
1507" s:NetrwOptionSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1508" Options get restored by s:NetrwOptionRestore()
1509" 06/08/07 : removed call to NetrwSafeOptions(), either placed
1510" immediately after NetrwOptionSave() calls in NetRead
1511" and NetWrite, or after the s:NetrwEnew() call in
1512" NetrwBrowse.
1513" vt: normally its "w:" or "s:" (a variable type)
1514fun! s:NetrwOptionSave(vt)
1515" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1516" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"))
1517" 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)
1518
1519 if !exists("{a:vt}netrw_optionsave")
1520 let {a:vt}netrw_optionsave= 1
1521 else
1522" call Dret("s:NetrwOptionSave : options already saved")
1523 return
1524 endif
1525" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
1526
1527 " Save current settings and current directory
1528" call Decho("saving current settings and current directory")
1529 let s:yykeep = @@
1530 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1531 let {a:vt}netrw_aikeep = &l:ai
1532 let {a:vt}netrw_awkeep = &l:aw
1533 let {a:vt}netrw_bhkeep = &l:bh
1534 let {a:vt}netrw_blkeep = &l:bl
1535" let {a:vt}netrw_btkeep = &l:bt
1536 let {a:vt}netrw_bombkeep = &l:bomb
1537 let {a:vt}netrw_cedit = &cedit
1538 let {a:vt}netrw_cikeep = &l:ci
1539 let {a:vt}netrw_cinkeep = &l:cin
1540 let {a:vt}netrw_cinokeep = &l:cino
1541 let {a:vt}netrw_comkeep = &l:com
1542 let {a:vt}netrw_cpokeep = &l:cpo
1543 let {a:vt}netrw_diffkeep = &l:diff
1544 let {a:vt}netrw_fenkeep = &l:fen
1545 let {a:vt}netrw_ffkeep = &l:ff
1546 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1547 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1548 let {a:vt}netrw_hidkeep = &l:hidden
1549 let {a:vt}netrw_imkeep = &l:im
1550 let {a:vt}netrw_iskkeep = &l:isk
1551 let {a:vt}netrw_lskeep = &l:ls
1552 let {a:vt}netrw_makeep = &l:ma
1553 let {a:vt}netrw_magickeep = &l:magic
1554 let {a:vt}netrw_modkeep = &l:mod
1555 let {a:vt}netrw_nukeep = &l:nu
1556 let {a:vt}netrw_repkeep = &l:report
1557 let {a:vt}netrw_rokeep = &l:ro
1558 let {a:vt}netrw_selkeep = &l:sel
1559 let {a:vt}netrw_spellkeep = &l:spell
1560 if g:netrw_use_noswf
1561 let {a:vt}netrw_swfkeep = &l:swf
1562 endif
1563 if has("clipboard")
1564 let {a:vt}netrw_starkeep = @*
1565 endif
1566 let {a:vt}netrw_tskeep = &l:ts
1567 let {a:vt}netrw_twkeep = &l:tw " textwidth
1568 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1569 let {a:vt}netrw_wrapkeep = &l:wrap
1570 let {a:vt}netrw_writekeep = &l:write
1571
1572 " save a few selected netrw-related variables
1573" call Decho("saving a few selected netrw-related variables")
1574 if g:netrw_keepdir
1575 let {a:vt}netrw_dirkeep = getcwd()
1576 endif
1577 if has("clipboard")
1578 if &go =~# 'a' | sil! let {a:vt}netrw_regstar = @* | endif
1579 endif
1580 sil! let {a:vt}netrw_regslash= @/
1581
1582" 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)
1583" call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr())
1584endfun
1585
1586" ------------------------------------------------------------------------
1587" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
1588" Use s:NetrwSaveOptions() to save user settings
1589" Use s:NetrwOptionRestore() to restore user settings
1590fun! s:NetrwSafeOptions()
1591" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1592" call Decho("win#".winnr()."'s ft=".&ft)
1593" 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)
1594 if exists("+acd") | setl noacd | endif
1595 setl noai
1596 setl noaw
1597 setl nobl
1598 setl nobomb
1599 setl bt=nofile
1600 setl noci
1601 setl nocin
1602 if g:netrw_liststyle == s:TREELIST
1603 setl bh=hide
1604 endif
1605 setl cino=
1606 setl com=
1607 setl cpo-=a
1608 setl cpo-=A
1609 setl fo=nroql2
1610 setl nohid
1611 setl noim
1612 setl isk+=@ isk+=* isk+=/
1613 setl magic
1614 if g:netrw_use_noswf
1615 setl noswf
1616 endif
1617 setl report=10000
1618 setl sel=inclusive
1619 setl nospell
1620 setl tw=0
1621 setl wig=
1622 setl cedit&
1623 call s:NetrwCursor()
1624
1625 " allow the user to override safe options
1626" call Decho("ft<".&ft."> ei=".&ei)
1627 if &ft == "netrw"
1628" call Decho("do any netrw FileType autocmds (doau FileType netrw)")
1629 sil! keepalt keepj doau FileType netrw
1630 endif
1631
1632" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh)
1633" 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)
1634" call Dret("s:NetrwSafeOptions")
Bram Moolenaarff034192013-04-24 18:51:19 +02001635endfun
1636
1637" ---------------------------------------------------------------------
1638" NetrwStatusLine: {{{2
1639fun! NetrwStatusLine()
1640
1641" vvv NetrwStatusLine() debugging vvv
1642" let g:stlmsg=""
1643" if !exists("w:netrw_explore_bufnr")
1644" let g:stlmsg="!X<explore_bufnr>"
1645" elseif w:netrw_explore_bufnr != bufnr("%")
1646" let g:stlmsg="explore_bufnr!=".bufnr("%")
1647" endif
1648" if !exists("w:netrw_explore_line")
1649" let g:stlmsg=" !X<explore_line>"
1650" elseif w:netrw_explore_line != line(".")
1651" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1652" endif
1653" if !exists("w:netrw_explore_list")
1654" let g:stlmsg=" !X<explore_list>"
1655" endif
1656" ^^^ NetrwStatusLine() debugging ^^^
1657
1658 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")
1659 " restore user's status line
1660 let &stl = s:netrw_users_stl
1661 let &laststatus = s:netrw_users_ls
1662 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1663 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1664 return ""
1665 else
1666 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1667 endif
1668endfun
1669
1670" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001671" Netrw Transfer Functions: {{{1
1672" ===============================
1673
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001675" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001676" mode: =0 read remote file and insert before current line
1677" =1 read remote file and insert after current line
1678" =2 replace with remote file
1679" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001680fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001681" 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 +00001682
Bram Moolenaar5c736222010-01-06 20:54:52 +01001683 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001684 call s:NetrwOptionSave("w:")
1685 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001686 call s:RestoreCursorline()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001687
Bram Moolenaar5c736222010-01-06 20:54:52 +01001688 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001689 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001690 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001691 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001692 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001693 elseif a:mode == 2 " replace with remote file
1694 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001695 elseif a:mode == 3 " skip read of file (leave as temporary)
1696 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001697 else
1698 exe a:mode
1699 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001700 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001701 let ichoice = (a:0 == 0)? 0 : 1
1702" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
1703
Bram Moolenaar5c736222010-01-06 20:54:52 +01001704 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001705 let tmpfile= s:GetTempfile("")
1706 if tmpfile == ""
1707" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001708 return
1709 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001710
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001711 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001712
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001713 " attempt to repeat with previous host-file-etc
1714 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001715" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001716 let choice = b:netrw_lastfile
1717 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001718
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001719 else
1720 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001721" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001722
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001723 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001724 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001725 echomsg 'NetRead Usage:'
1726 echomsg ':Nread machine:path uses rcp'
1727 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1728 echomsg ':Nread "machine id password path" uses ftp'
1729 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1730 echomsg ':Nread fetch://machine/path uses fetch'
1731 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1732 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaara6878372014-03-22 21:02:50 +01001733 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001734 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1735 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1736 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1737 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001738 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001739 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001740
Bram Moolenaar9964e462007-05-05 17:54:07 +00001741 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001742 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001743" call Decho("reconstructing choice")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001744 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001745 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001746 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001747 else
1748 " case "... ... ..."
1749 let choice = strpart(choice,1,strlen(choice)-1)
1750 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001751
Bram Moolenaar9964e462007-05-05 17:54:07 +00001752 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001753 let wholechoice = wholechoice . " " . choice
1754 let ichoice = ichoice + 1
1755 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001756 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001757 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001758 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001759" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001760 return
1761 endif
1762 let choice= a:{ichoice}
1763 endwhile
1764 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1765 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 endif
1767 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001769" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001770 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001771
Bram Moolenaar5c736222010-01-06 20:54:52 +01001772 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001773 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001774 if !exists("b:netrw_method") || b:netrw_method < 0
1775" call Dfunc("netrw#NetRead : unsupported method")
1776 return
1777 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001778 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001779
Bram Moolenaar8d043172014-01-23 14:24:41 +01001780 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaar446cb832008-06-24 21:56:24 +00001781" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02001782 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001783" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001784 keepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001785" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001786 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001788
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001789 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01001790 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001791 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001792 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
1793 echo "(netrw) Processing your read request..."
1794 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001795
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001796 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001797 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001798 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001799" call Decho("read via rcp (method #1)")
Bram Moolenaard68071d2006-05-02 22:08:30 +00001800 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001801 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01001802 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001803 " ER: the tmpfile is full path: rcp sees C:\... as host C
1804 if s:netrw_has_nt_rcp == 1
1805 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1806 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
1807 else
1808 " Any way needed it machine contains a '.'
1809 let uid_machine = g:netrw_machine .'.'. $USERNAME
1810 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001812 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1813 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1814 else
1815 let uid_machine = g:netrw_machine
1816 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00001818" 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 +01001819 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 +00001820 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001821 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001822
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001823 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001824 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001825 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001826" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +00001827 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +02001828 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001829 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02001830 setl ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001831 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001832" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001833 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001834 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001835" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001836 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001837 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
1838" call Decho("filter input: ".getline(line("$")))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001839 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02001840" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
1841 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 +00001842 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02001843" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
1844 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001845 endif
1846 " 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 +00001847 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00001848 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02001849 setl debug=msg
Bram Moolenaaradc21822011-04-01 18:03:16 +02001850 keepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001851 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001852 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00001853 call s:SaveBufVars()
1854 bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01001855 if bufname("%") == "" && getline("$") == "" && line('$') == 1
1856 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00001857 q!
1858 endif
1859 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00001860 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001861 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001862
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001863 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001864 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001865 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
1866 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001867" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001868 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001869 keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001870 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02001871 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001872 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001873 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00001874" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001875 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001876 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00001877" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001878 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001879
Bram Moolenaar97d62492012-11-15 21:28:22 +01001880 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001881 if exists("g:netrw_ftp") && g:netrw_ftp == 1
1882 keepj put =g:netrw_uid
1883" call Decho("filter input: ".getline('.'))
1884 if exists("s:netrw_passwd")
1885 keepj put ='\"'.s:netrw_passwd.'\"'
1886 endif
1887" call Decho("filter input: ".getline('.'))
1888 elseif exists("s:netrw_passwd")
1889 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
1890" call Decho("filter input: ".getline('.'))
1891 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001892 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001893
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001894 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001895 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00001896" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001897 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001898 if exists("g:netrw_ftpextracmd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02001899 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00001900" call Decho("filter input: ".getline('.'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001901 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001902 keepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00001903" call Decho("filter input: ".getline('.'))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001904
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001905 " perform ftp:
1906 " -i : turns off interactive prompting from ftp
1907 " -n unix : DON'T use <.netrc>, even though it exists
1908 " -n win32: quit being obnoxious about password
Bram Moolenaaradc21822011-04-01 18:03:16 +02001909 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001910" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
1911 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001912 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1913 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001914" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001915 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001916 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001917 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001919 call s:SaveBufVars()|bd!|call s:RestoreBufVars()
1920 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: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001925 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001926" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001927 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00001928 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001929 else
1930 let useport= ""
1931 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001932" 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 +00001933 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 +00001934 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001935 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001936
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001937 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001938 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001939 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001940" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001941 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001942 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001943 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001944 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001945" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001946 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001947 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001948
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001949 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
1950 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001951" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001952 if exists("g:netrw_http_xcmd")
Bram Moolenaara6878372014-03-22 21:02:50 +01001953" 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))
1954 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 +00001955 else
Bram Moolenaara6878372014-03-22 21:02:50 +01001956" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
1957 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 +00001958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001959 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001960
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001961 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00001962 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaaradc21822011-04-01 18:03:16 +02001963" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00001964 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
1965 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001966" call Decho("netrw_html<".netrw_html.">")
1967" call Decho("netrw_tag <".netrw_tag.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001968" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
1969 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 +00001970 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001971" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaaradc21822011-04-01 18:03:16 +02001972 exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001973 endif
1974 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01001975" call Decho("setl ro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02001976 setl ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001977
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001978 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001979 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001980 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001981" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001982
Bram Moolenaar5c736222010-01-06 20:54:52 +01001983 if !executable(g:netrw_dav_cmd)
1984 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
1985" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
1986 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001987 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01001988 if g:netrw_dav_cmd =~ "curl"
1989" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
1990 exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
1991 else
1992 " Construct execution string (four lines) which will be passed through filter
1993 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
1994 new
Bram Moolenaarff034192013-04-24 18:51:19 +02001995 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01001996 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001997 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01001998 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001999 keepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002000 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002001 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
2002 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
2003 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002004 keepj put ='get '.netrw_fname.' '.tmpfile
2005 keepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002006
Bram Moolenaar5c736222010-01-06 20:54:52 +01002007 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002008 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002009" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002010 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
2011 bd!
2012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002013 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002014 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002015
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002016 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002017 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002018 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002019" call Decho("read via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002020" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
2021 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 +00002022 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002024
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002025 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002026 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002027 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002028 elseif b:netrw_method == 8
Bram Moolenaar9964e462007-05-05 17:54:07 +00002029" call Decho("read via fetch (method #8)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002030 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002031 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002032 keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002033 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002034" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002035 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002036 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002037 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002038 let netrw_option= "http"
2039 else
2040 let netrw_option= "ftp"
2041 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002042" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaar446cb832008-06-24 21:56:24 +00002044 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002045" 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))
2046 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 +00002047 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00002048" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
2049 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 +00002050 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaar446cb832008-06-24 21:56:24 +00002052 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01002054" call Decho("setl ro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002055 setl ro
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002058 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002059 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +00002060" call Decho("read via sftp (method #9)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002061" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
2062 exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00002063 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002067 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002068 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002069 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 endif
2071 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaar5c736222010-01-06 20:54:52 +01002073 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 if exists("b:netrw_method")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002075" call Decho("cleanup b:netrw_method and b:netrw_fname")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 unlet b:netrw_fname
2078 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002079 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 +00002080" call Decho("cleanup by deleting tmpfile<".tmpfile.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002081 keepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002082 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002083 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002084
Bram Moolenaar9964e462007-05-05 17:54:07 +00002085" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086endfun
2087
2088" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002089" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002090fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002091" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002092
Bram Moolenaar5c736222010-01-06 20:54:52 +01002093 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002095 call s:NetrwOptionSave("w:")
2096 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002097
Bram Moolenaar5c736222010-01-06 20:54:52 +01002098 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002099 let tmpfile= s:GetTempfile("")
2100 if tmpfile == ""
2101" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002102 return
2103 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002104
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 if a:0 == 0
2106 let ichoice = 0
2107 else
2108 let ichoice = 1
2109 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 let curbufname= expand("%")
2112" call Decho("curbufname<".curbufname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002113 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 " For binary writes, always write entire file.
2115 " (line numbers don't really make sense for that).
2116 " Also supports the writing of tar and zip files.
Bram Moolenaaradc21822011-04-01 18:03:16 +02002117" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
2118 exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119 elseif g:netrw_cygwin
2120 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002121 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002122" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002123 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002124 else
2125 " write (selected portion of) file to temporary
Bram Moolenaaradc21822011-04-01 18:03:16 +02002126" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002127 exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002128 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002129
Bram Moolenaar9964e462007-05-05 17:54:07 +00002130 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002131 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002132 " on the temporary file's name. Deletion of the temporary file during
2133 " cleanup then causes an error message.
2134 0file!
2135 endif
2136
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002139
Bram Moolenaar9964e462007-05-05 17:54:07 +00002140 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 " attempt to repeat with previous host-file-etc
2142 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002143" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 let choice = b:netrw_lastfile
2145 let ichoice= ichoice + 1
2146 else
2147 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002148
Bram Moolenaar8d043172014-01-23 14:24:41 +01002149 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002151 echomsg 'NetWrite Usage:"'
2152 echomsg ':Nwrite machine:path uses rcp'
2153 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2154 echomsg ':Nwrite "machine id password path" uses ftp'
2155 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2156 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2157 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2158 echomsg ':Nwrite rcp://machine/path uses rcp'
2159 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2160 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2161 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002162 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002164
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 elseif match(choice,"^\"") != -1
2166 if match(choice,"\"$") != -1
2167 " case "..."
2168 let choice=strpart(choice,1,strlen(choice)-2)
2169 else
2170 " case "... ... ..."
2171 let choice = strpart(choice,1,strlen(choice)-1)
2172 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002173
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 while match(choice,"\"$") == -1
2175 let wholechoice= wholechoice . " " . choice
2176 let ichoice = ichoice + 1
2177 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002178 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002179 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002180 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002181" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 return
2183 endif
2184 let choice= a:{ichoice}
2185 endwhile
2186 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2187 endif
2188 endif
2189 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 let ichoice= ichoice + 1
Bram Moolenaar9964e462007-05-05 17:54:07 +00002191" call Decho("choice<" . choice . "> ichoice=".ichoice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002192
Bram Moolenaar9964e462007-05-05 17:54:07 +00002193 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaaradc21822011-04-01 18:03:16 +02002194 keepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002195 if !exists("b:netrw_method") || b:netrw_method < 0
2196" call Dfunc("netrw#NetWrite : unsupported method")
2197 return
2198 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002199
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002201 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002202 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002203 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2204 echo "(netrw) Processing your write request..."
Bram Moolenaar446cb832008-06-24 21:56:24 +00002205" call Decho("(netrw) Processing your write request...")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002206 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002207
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002209 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002210 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002211" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 if s:netrw_has_nt_rcp == 1
2213 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2214 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2215 else
2216 let uid_machine = g:netrw_machine .'.'. $USERNAME
2217 endif
2218 else
2219 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2220 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2221 else
2222 let uid_machine = g:netrw_machine
2223 endif
2224 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00002225" call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
2226 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 +00002227 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002228
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002230 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002231 elseif b:netrw_method == 2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002232" call Decho("write via ftp+.netrc (method #2)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002233 let netrw_fname = b:netrw_fname
2234
2235 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2236 let bhkeep = &l:bh
2237 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002238 setl bh=hide
2239 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002240
Bram Moolenaar446cb832008-06-24 21:56:24 +00002241" call Decho("filter input window#".winnr())
Bram Moolenaarff034192013-04-24 18:51:19 +02002242 setl ff=unix
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002243 keepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002244" call Decho("filter input: ".getline('$'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002245 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002246 keepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002247" call Decho("filter input: ".getline("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002248 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002249 keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002250" call Decho("filter input: ".getline("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02002252" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
2253 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 +00002254 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00002255" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02002256" call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
2257 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 endif
2259 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2260 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002261 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002262 keepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002263 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002266
2267 " remove enew buffer (quietly)
2268 let filtbuf= bufnr("%")
2269 exe curbuf."b!"
2270 let &l:bh = bhkeep
2271 exe filtbuf."bw!"
2272
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002274
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002276 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002277 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002278 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaar9964e462007-05-05 17:54:07 +00002279" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002280 let netrw_fname = b:netrw_fname
2281 let bhkeep = &l:bh
2282
2283 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2284 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002285 setl bh=hide
2286 keepalt enew
2287 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002290 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00002291" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002293 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00002294" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002296 if exists("g:netrw_uid") && g:netrw_uid != ""
2297 if exists("g:netrw_ftp") && g:netrw_ftp == 1
2298 keepj put =g:netrw_uid
2299" call Decho("filter input: ".getline('.'))
2300 if exists("s:netrw_passwd") && s:netrw_passwd != ""
2301 keepj put ='\"'.s:netrw_passwd.'\"'
2302 endif
2303" call Decho("filter input: ".getline('.'))
2304 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
2305 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
2306" call Decho("filter input: ".getline('.'))
2307 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002309 keepj put =g:netrw_ftpmode
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310" call Decho("filter input: ".getline('$'))
2311 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002312 keepj put =g:netrw_ftpextracmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002313" call Decho("filter input: ".getline("$"))
2314 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002315 keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002316" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 " save choice/id/password for future use
2318 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002319
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 " perform ftp:
2321 " -i : turns off interactive prompting from ftp
2322 " -n unix : DON'T use <.netrc>, even though it exists
2323 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002324 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002325" call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
2326 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2328 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002329 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002330 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002331 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 let mod=1
2333 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002334
2335 " remove enew buffer (quietly)
2336 let filtbuf= bufnr("%")
2337 exe curbuf."b!"
2338 let &l:bh= bhkeep
2339 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002340
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002341 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002342 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002343 elseif b:netrw_method == 4
Bram Moolenaar9964e462007-05-05 17:54:07 +00002344" call Decho("write via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002346 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 else
2348 let useport= ""
2349 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00002350" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
2351 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 +00002352 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002353
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 elseif b:netrw_method == 5
Bram Moolenaar9964e462007-05-05 17:54:07 +00002357" call Decho("write via http (method #5)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002358 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2359 if executable(curl)
2360 let url= g:netrw_choice
2361" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".shellescape(tmpfile,1)." ".shellescape(url,1) )
2362 exe s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".shellescape(tmpfile,1)." ".shellescape(url,1)
2363 elseif !exists("g:netrw_quiet")
2364 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd".">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002365 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002369 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002370" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2374 let bhkeep = &l:bh
2375
2376 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2377 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002378 setl bh=hide
2379 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380
Bram Moolenaarff034192013-04-24 18:51:19 +02002381 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002383 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002385 keepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002387 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002388 keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002389 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002390 keepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002391
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 " perform cadaver operation:
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002393 keepj norm! 1Gdd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002394" call Decho("executing: %!".g:netrw_dav_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002395 exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002396
2397 " remove enew buffer (quietly)
2398 let filtbuf= bufnr("%")
2399 exe curbuf."b!"
2400 let &l:bh = bhkeep
2401 exe filtbuf."bw!"
2402
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002403 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002406 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002407 elseif b:netrw_method == 7
Bram Moolenaar9964e462007-05-05 17:54:07 +00002408" call Decho("write via rsync (method #7)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002409" call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
2410 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 +00002411 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002414 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002415 elseif b:netrw_method == 9
Bram Moolenaar97d62492012-11-15 21:28:22 +01002416" call Decho("write via sftp (method #9)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2419 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2420 else
2421 let uid_machine = g:netrw_machine
2422 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002423
2424 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2425 let bhkeep = &l:bh
2426 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002427 setl bh=hide
2428 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429
Bram Moolenaarff034192013-04-24 18:51:19 +02002430 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002431 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002432" call Decho("filter input: ".getline('.'))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002433" call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002434 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
2435 exe s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002436 let filtbuf= bufnr("%")
2437 exe curbuf."b!"
2438 let &l:bh = bhkeep
2439 exe filtbuf."bw!"
2440 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002443 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002444 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002446 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002449
Bram Moolenaar5c736222010-01-06 20:54:52 +01002450 " NetWrite: Cleanup: {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002451" call Decho("cleanup")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452 if s:FileReadable(tmpfile)
2453" call Decho("tmpfile<".tmpfile."> readable, will now delete it")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002454 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002456 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002457
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459 " restore modifiability; usually equivalent to set nomod
2460 let &mod= mod
Bram Moolenaara6878372014-03-22 21:02:50 +01002461" 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 +02002462 elseif !exists("leavemod")
2463 " indicate that the buffer has not been modified since last written
Bram Moolenaara6878372014-03-22 21:02:50 +01002464" call Decho("set nomod")
2465 setl nomod
2466" 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 +00002467 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaar9964e462007-05-05 17:54:07 +00002469" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002470endfun
2471
2472" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002473" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474" uses NetRead to get a copy of the file into a temporarily file,
2475" then sources that file,
2476" then removes that file.
2477fun! netrw#NetSource(...)
2478" call Dfunc("netrw#NetSource() a:0=".a:0)
2479 if a:0 > 0 && a:1 == '?'
2480 " give help
2481 echomsg 'NetSource Usage:'
2482 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2483 echomsg ':Nsource fetch://machine/path uses fetch'
2484 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002485 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2487 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2488 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2489 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2490 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002491 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002492 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002493 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 call netrw#NetRead(3,a:{i})
Bram Moolenaara6878372014-03-22 21:02:50 +01002495" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002497" call Decho("exe so ".fnameescape(s:netrw_tmpfile))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002498 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002499" call Decho("delete(".s:netrw_tmpfile.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 call delete(s:netrw_tmpfile)
2501 unlet s:netrw_tmpfile
2502 else
2503 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2504 endif
2505 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002507 endif
2508" call Dret("netrw#NetSource")
2509endfun
2510
Bram Moolenaar8d043172014-01-23 14:24:41 +01002511" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002512" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2513" (implements the :Ntree command)
2514fun! netrw#SetTreetop(...)
2515" call Dfunc("netrw#SetTreetop(".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2516
Bram Moolenaar8d043172014-01-23 14:24:41 +01002517 " clear out the current tree
2518 if exists("w:netrw_treetop")
Bram Moolenaara6878372014-03-22 21:02:50 +01002519" call Decho("clearing out current tree")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002520 let inittreetop= w:netrw_treetop
2521 unlet w:netrw_treetop
2522 endif
2523 if exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01002524" call Decho("freeing w:netrw_treedict")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002525 unlet w:netrw_treedict
2526 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002527
2528 if a:1 == "" && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002529 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01002530" call Decho("treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002531 else
2532 if isdirectory(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01002533" call Decho("a:1<".a:1."> is a directory")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002534 let treedir= a:1
2535 elseif exists("b:netrw_curdir") && isdirectory(b:netrw_curdir."/".a:1)
2536 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01002537" call Decho("a:1<".a:1."> is NOT a directory, trying treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002538 else
2539 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara6878372014-03-22 21:02:50 +01002540 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002541 endif
2542 endif
2543" call Decho("treedir<".treedir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002544 let islocal= expand("%") !~ '^\a\+://'
2545" call Decho("islocal=".islocal)
2546 if islocal
2547 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2548 else
2549 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2550 endif
2551" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002552endfun
2553
Bram Moolenaar9964e462007-05-05 17:54:07 +00002554" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002555" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002556" readcmd == %r : replace buffer with newly read file
2557" == 0r : read file at top of buffer
2558" == r : read file after current line
2559" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002560fun! s:NetrwGetFile(readcmd, tfile, method)
2561" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002562
2563 " readcmd=='t': simply do nothing
2564 if a:readcmd == 't'
Bram Moolenaara6878372014-03-22 21:02:50 +01002565" 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 +00002566" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002568 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569
Bram Moolenaar9964e462007-05-05 17:54:07 +00002570 " get name of remote filename (ie. url and all)
2571 let rfile= bufname("%")
2572" call Decho("rfile<".rfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002573
Bram Moolenaar9964e462007-05-05 17:54:07 +00002574 if exists("*NetReadFixup")
2575 " for the use of NetReadFixup (not otherwise used internally)
2576 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002577 endif
2578
Bram Moolenaar9964e462007-05-05 17:54:07 +00002579 if a:readcmd[0] == '%'
2580 " get file into buffer
2581" call Decho("get file into buffer")
2582
2583 " rename the current buffer to the temp file (ie. tfile)
2584 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002585 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002586 else
2587 let tfile= a:tfile
2588 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002589" call Decho("exe sil! keepalt file ".fnameescape(tfile))
2590 exe "sil! keepalt file ".fnameescape(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002591
2592 " edit temporary file (ie. read the temporary file in)
2593 if rfile =~ '\.zip$'
2594" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
2595 call zip#Browse(tfile)
2596 elseif rfile =~ '\.tar$'
2597" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
2598 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002599 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002600" call Decho("handling remote gzip-compressed tar file")
2601 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002602 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002603" call Decho("handling remote bz2-compressed tar file")
2604 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002605 elseif rfile =~ '\.tar\.xz$'
2606" call Decho("handling remote xz-compressed tar file")
2607 call tar#Browse(tfile)
2608 elseif rfile =~ '\.txz$'
2609" call Decho("handling remote xz-compressed tar file (.txz)")
2610 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002611 else
2612" call Decho("edit temporary file")
2613 e!
2614 endif
2615
2616 " rename buffer back to remote filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002617" call Decho("exe sil! keepalt file ".fnameescape(rfile))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002618 exe "sil! keepj keepalt file ".fnameescape(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002619
Bram Moolenaar97d62492012-11-15 21:28:22 +01002620 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002621 " Note that isk must not include a "/" for scripts.vim
2622 " to process this detection correctly.
2623" call Decho("detect filetype of local version of remote file")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002624 let iskkeep= &l:isk
2625 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002626 let &l:isk= iskkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00002627" call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
2628 let line1 = 1
2629 let line2 = line("$")
2630
Bram Moolenaar8d043172014-01-23 14:24:41 +01002631 elseif !&ma
2632 " attempting to read a file after the current line in the file, but the buffer is not modifiable
2633 keepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
2634" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
2635 return
2636
Bram Moolenaar9964e462007-05-05 17:54:07 +00002637 elseif s:FileReadable(a:tfile)
2638 " read file after current line
2639" call Decho("read file<".a:tfile."> after current line")
2640 let curline = line(".")
2641 let lastline= line("$")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002642" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002643 exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002644 let line1= curline + 1
2645 let line2= line("$") - lastline + 1
2646
2647 else
2648 " not readable
Bram Moolenaara6878372014-03-22 21:02:50 +01002649" 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 +00002650" call Decho("tfile<".a:tfile."> not readable")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002651 keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002652" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002653 return
2654 endif
2655
2656 " User-provided (ie. optional) fix-it-up command
2657 if exists("*NetReadFixup")
2658" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002659 keepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002660" else " Decho
2661" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
2662 endif
2663
Bram Moolenaaradc21822011-04-01 18:03:16 +02002664 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002665 " update the Buffers menu
Bram Moolenaaradc21822011-04-01 18:03:16 +02002666 keepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002667 endif
2668
2669" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
2670
2671 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002672" redraw!
2673
Bram Moolenaara6878372014-03-22 21:02:50 +01002674" 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 +00002675" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002676endfun
2677
Bram Moolenaar9964e462007-05-05 17:54:07 +00002678" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002679" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680" Input:
2681" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2682" Output:
2683" b:netrw_method= 1: rcp
2684" 2: ftp + <.netrc>
2685" 3: ftp + machine, id, password, and [path]filename
2686" 4: scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002687" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002688" 6: dav
2689" 7: rsync
2690" 8: fetch
2691" 9: sftp
2692" g:netrw_machine= hostname
2693" b:netrw_fname = filename
2694" g:netrw_port = optional port number (for ftp)
2695" g:netrw_choice = copy of input url (choice)
2696fun! s:NetrwMethod(choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002697" call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002698
Bram Moolenaar251e1912011-06-19 05:09:16 +02002699 " sanity check: choice should have at least three slashes in it
2700 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2701 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2702 let b:netrw_method = -1
2703" call Dret("NetrwMethod : incorrect url format<".a:choice.">")
2704 return
2705 endif
2706
Bram Moolenaar5c736222010-01-06 20:54:52 +01002707 " record current g:netrw_machine, if any
2708 " curmachine used if protocol == ftp and no .netrc
2709 if exists("g:netrw_machine")
2710 let curmachine= g:netrw_machine
2711" call Decho("curmachine<".curmachine.">")
2712 else
2713 let curmachine= "N O T A HOST"
2714 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002715 if exists("g:netrw_port")
2716 let netrw_port= g:netrw_port
2717 endif
2718
2719 " insure that netrw_ftp_cmd starts off every method determination
2720 " with the current g:netrw_ftp_cmd
2721 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002723 " initialization
2724 let b:netrw_method = 0
2725 let g:netrw_machine = ""
2726 let b:netrw_fname = ""
2727 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728 let g:netrw_choice = a:choice
2729
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002730 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002731 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002732 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2733 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002734 " rcpurm : rcp://[user@]host/filename Use rcp
2735 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002737 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 " rsyncurm : rsync://host[:port]/path Use rsync
2740 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2741 " sftpurm : sftp://[user@]host/filename Use scp
2742 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2743 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002744" let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2745" let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
2746" let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
2747 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2748 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002750 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002751 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002752 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002754 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002756
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002757" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002759 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002761" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002762 let b:netrw_method = 1
2763 let userid = substitute(a:choice,rcpurm,'\1',"")
2764 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2765 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002766 if userid != ""
2767 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002769
Bram Moolenaaradc21822011-04-01 18:03:16 +02002770 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002771 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002772" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002773 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002774 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2775 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2776 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002777
Bram Moolenaar15146672011-10-20 22:22:38 +02002778 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002779 elseif match(a:choice,httpurm) == 0
Bram Moolenaara6878372014-03-22 21:02:50 +01002780" call Decho("http[s]://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002781 let b:netrw_method = 5
2782 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
2783 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01002784 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002785
Bram Moolenaaradc21822011-04-01 18:03:16 +02002786 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002787 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002788" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002789 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02002790 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002791 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
2792 else
2793 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
2794 endif
2795 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002796
Bram Moolenaaradc21822011-04-01 18:03:16 +02002797 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002798 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002799" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002800 let b:netrw_method = 7
2801 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
2802 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaaradc21822011-04-01 18:03:16 +02002804 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002805 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002806" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002807 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002808 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
2809 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
2810 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002811" call Decho("g:netrw_machine<".g:netrw_machine.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002812 if userid != ""
2813 let g:netrw_uid= userid
2814 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002815
Bram Moolenaaradc21822011-04-01 18:03:16 +02002816 if curmachine != g:netrw_machine
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002817 if exists("s:netwr_hup[".g:netrw_machine."]")
2818 call NetUserPass("ftp:".g:netrw_machine)
2819 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002820 " if there's a change in hostname, require password re-entry
2821 unlet s:netrw_passwd
2822 endif
2823 if exists("netrw_port")
2824 unlet netrw_port
2825 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002826 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002827
Bram Moolenaar446cb832008-06-24 21:56:24 +00002828 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002829 let b:netrw_method = 3
2830 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002831 let host= substitute(g:netrw_machine,'\..*$','','')
2832 if exists("s:netrw_hup[host]")
2833 call NetUserPass("ftp:".host)
2834
2835 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
Bram Moolenaaradc21822011-04-01 18:03:16 +02002836" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
2837" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
2838 if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002839 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002840" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
2841 endif
2842 let b:netrw_method= 2
2843 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
2844" call Decho("using <".expand("$HOME/.netrc")."> (readable)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002845 let b:netrw_method= 2
2846 else
2847 if !exists("g:netrw_uid") || g:netrw_uid == ""
2848 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002849 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002850 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002851 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002852 endif
2853 let b:netrw_method= 3
2854 endif
2855 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002856
Bram Moolenaaradc21822011-04-01 18:03:16 +02002857 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002858 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002859" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002860 let b:netrw_method = 8
2861 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
2862 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
2863 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
2864 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002865
Bram Moolenaaradc21822011-04-01 18:03:16 +02002866 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002867 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002868" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002870 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
2871 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002872 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002873 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002874 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002875
Bram Moolenaaradc21822011-04-01 18:03:16 +02002876 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002877 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002878" call Decho("(ftp) host file")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002879 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002880 let b:netrw_method = 3
2881 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
2882 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002883
Bram Moolenaar9964e462007-05-05 17:54:07 +00002884 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002885 let b:netrw_method = 2
2886 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
2887 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
2888 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002889
Bram Moolenaaradc21822011-04-01 18:03:16 +02002890 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002891 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002892" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002893 let b:netrw_method = 9
2894 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
2895 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002896
Bram Moolenaaradc21822011-04-01 18:03:16 +02002897 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002898 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002899" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00002900 let b:netrw_method = 1
2901 let userid = substitute(a:choice,rcphf,'\2',"")
2902 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
2903 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002904" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
2905" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
2906" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
2907" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002908 if userid != ""
2909 let g:netrw_uid= userid
2910 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002911
Bram Moolenaaradc21822011-04-01 18:03:16 +02002912 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002913 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002914 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002915 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002916 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002917 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002919 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00002920
Bram Moolenaar81695252004-12-29 20:58:21 +00002921 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02002922 " remove any leading [:#] from port number
2923 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
2924 elseif exists("netrw_port")
2925 " retain port number as implicit for subsequent ftp operations
2926 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00002927 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002928
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002929" call Decho("a:choice <".a:choice.">")
2930" call Decho("b:netrw_method <".b:netrw_method.">")
2931" call Decho("g:netrw_machine<".g:netrw_machine.">")
2932" call Decho("g:netrw_port <".g:netrw_port.">")
2933" if exists("g:netrw_uid") "Decho
2934" call Decho("g:netrw_uid <".g:netrw_uid.">")
2935" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936" if exists("s:netrw_passwd") "Decho
2937" call Decho("s:netrw_passwd <".s:netrw_passwd.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002938" endif "Decho
2939" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002940" call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942
2943" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944" NetReadFixup: this sort of function is typically written by the user {{{2
2945" to handle extra junk that their system's ftp dumps
2946" into the transfer. This function is provided as an
2947" example and as a fix for a Windows 95 problem: in my
2948" experience, win95's ftp always dumped four blank lines
2949" at the end of the transfer.
2950if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
2951 fun! NetReadFixup(method, line1, line2)
2952" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002953
2954 " sanity checks -- attempt to convert inputs to integers
2955 let method = a:method + 0
2956 let line1 = a:line1 + 0
2957 let line2 = a:line2 + 0
2958 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
2959" call Dret("NetReadFixup")
2960 return
2961 endif
2962
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 if method == 3 " ftp (no <.netrc>)
2964 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002965 if fourblanklines >= line1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002966 exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01002967 call histdel("/",-1)
2968 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002970
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971" call Dret("NetReadFixup")
2972 endfun
2973endif
2974
2975" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002976" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002977" Usage: :call NetUserPass() -- will prompt for userid and password
2978" :call NetUserPass("uid") -- will prompt for password
2979" :call NetUserPass("uid","password") -- sets global userid and password
2980" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
2981" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982fun! NetUserPass(...)
2983
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002984" call Dfunc("NetUserPass() a:0=".a:0)
2985
2986 if !exists('s:netrw_hup')
2987 let s:netrw_hup= {}
2988 endif
2989
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01002991 " case: no input arguments
2992
2993 " change host and username if not previously entered; get new password
2994 if !exists("g:netrw_machine")
2995 let g:netrw_machine= input('Enter hostname: ')
2996 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01002998 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 let g:netrw_uid= input('Enter username: ')
3000 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003001 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003002 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003003
3004 " set up hup database
3005 let host = substitute(g:netrw_machine,'\..*$','','')
3006 if !exists('s:netrw_hup[host]')
3007 let s:netrw_hup[host]= {}
3008 endif
3009 let s:netrw_hup[host].uid = g:netrw_uid
3010 let s:netrw_hup[host].passwd = s:netrw_passwd
3011
3012 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003013 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003014
3015 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003016 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003017 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara6878372014-03-22 21:02:50 +01003018" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003019 let host = substitute(a:1,'^ftp:','','')
3020 let host = substitute(host,'\..*','','')
3021 if exists("s:netrw_hup[host]")
3022 let g:netrw_uid = s:netrw_hup[host].uid
3023 let s:netrw_passwd = s:netrw_hup[host].passwd
3024" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3025" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
3026 else
3027 let g:netrw_uid = input("Enter UserId: ")
3028 let s:netrw_passwd = inputsecret("Enter Password: ")
3029 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003030
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003031 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003032 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara6878372014-03-22 21:02:50 +01003033" 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 +02003034 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003035 if g:netrw_machine =~ '[0-9.]\+'
3036 let host= g:netrw_machine
3037 else
3038 let host= substitute(g:netrw_machine,'\..*$','','')
3039 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003040 else
3041 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003042 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003043 let g:netrw_uid = a:1
3044" call Decho("set g:netrw_uid= <".g:netrw_uid.">")
3045 if exists("g:netrw_passwd")
3046 " ask for password if one not previously entered
3047 let s:netrw_passwd= g:netrw_passwd
3048 else
3049 let s:netrw_passwd = inputsecret("Enter Password: ")
3050 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003051 endif
3052
3053" call Decho("host<".host.">")
3054 if exists("host")
3055 if !exists('s:netrw_hup[host]')
3056 let s:netrw_hup[host]= {}
3057 endif
3058 let s:netrw_hup[host].uid = g:netrw_uid
3059 let s:netrw_hup[host].passwd = s:netrw_passwd
3060 endif
3061
3062 elseif a:0 == 2
3063 let g:netrw_uid = a:1
3064 let s:netrw_passwd = a:2
3065
3066 elseif a:0 == 3
3067 " enter hostname, user-id, and password into the hup dictionary
3068 let host = substitute(a:1,'^\a\+:','','')
3069 let host = substitute(host,'\..*$','','')
3070 if !exists('s:netrw_hup[host]')
3071 let s:netrw_hup[host]= {}
3072 endif
3073 let s:netrw_hup[host].uid = a:2
3074 let s:netrw_hup[host].passwd = a:3
3075 let g:netrw_uid = s:netrw_hup[host].uid
3076 let s:netrw_passwd = s:netrw_hup[host].passwd
3077" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3078" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003080
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003081" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083
Bram Moolenaar9964e462007-05-05 17:54:07 +00003084" ===========================================
3085" Shared Browsing Support: {{{1
3086" ===========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003088" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003089" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3090fun! s:ExplorePatHls(pattern)
3091" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3092 let repat= substitute(a:pattern,'^**/\{1,2}','','')
3093" call Decho("repat<".repat.">")
3094 let repat= escape(repat,'][.\')
3095" call Decho("repat<".repat.">")
3096 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3097" call Dret("s:ExplorePatHls repat<".repat.">")
3098 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003099endfun
3100
3101" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003102" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003103" 0: (user: <mb>) bookmark current directory
3104" 1: (user: <gb>) change to the bookmarked directory
3105" 2: (user: <qb>) list bookmarks
3106" 3: (browsing) record current directory history
3107" 4: (user: <u>) go up (previous) bookmark
3108" 5: (user: <U>) go down (next) bookmark
3109" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003110fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003111" 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 +02003112 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3113" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3114 return
3115 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003116
Bram Moolenaar97d62492012-11-15 21:28:22 +01003117 let ykeep= @@
Bram Moolenaar9964e462007-05-05 17:54:07 +00003118 if a:chg == 0
3119 " bookmark the current directory
3120" call Decho("(user: <b>) bookmark the current directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003121 if !exists("g:netrw_bookmarklist")
3122 let g:netrw_bookmarklist= []
3123 endif
3124 if index(g:netrw_bookmarklist,a:curdir) == -1
3125 " curdir not currently in g:netrw_bookmarklist, so include it
3126 call add(g:netrw_bookmarklist,a:curdir)
3127 call sort(g:netrw_bookmarklist)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003128 endif
3129 echo "bookmarked the current directory"
3130
3131 elseif a:chg == 1
3132 " change to the bookmarked directory
Bram Moolenaarff034192013-04-24 18:51:19 +02003133" call Decho("(user: <".v:count."gb>) change to the bookmarked directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003134 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaarff034192013-04-24 18:51:19 +02003135" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003136 exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003137 else
3138 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3139 endif
3140
3141 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003142" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003143 let didwork= 0
3144 " list user's bookmarks
3145" call Decho("(user: <q>) list user's bookmarks")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003146 if exists("g:netrw_bookmarklist")
3147" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
3148 let cnt= 1
3149 for bmd in g:netrw_bookmarklist
3150" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
Bram Moolenaarff034192013-04-24 18:51:19 +02003151 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003152 let didwork = 1
3153 let cnt = cnt + 1
3154 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003155 endif
3156
3157 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003158 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003159 let first = 1
3160 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003161 if g:netrw_dirhistmax > 0
3162 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaar5c736222010-01-06 20:54:52 +01003163" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003164 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003165" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt})
Bram Moolenaarff034192013-04-24 18:51:19 +02003166 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003167 let didwork= 1
3168 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003169 let histcnt = histcnt + 1
3170 let first = 0
3171 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 if cnt < 0
3173 let cnt= cnt + g:netrw_dirhistmax
3174 endif
3175 endwhile
3176 else
3177 let g:netrw_dirhist_cnt= 0
3178 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003179 if didwork
3180 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3181 endif
3182
3183 elseif a:chg == 3
3184 " saves most recently visited directories (when they differ)
3185" call Decho("(browsing) record curdir history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003186 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 +02003187 if g:netrw_dirhistmax > 0
3188 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3189 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
3190 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003191" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003192 endif
3193
3194 elseif a:chg == 4
3195 " u: change to the previous directory stored on the history list
3196" call Decho("(user: <u>) chg to prev dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003197 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003198 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003199 if g:netrw_dirhist_cnt < 0
3200 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3201 endif
3202 else
3203 let g:netrw_dirhist_cnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003204 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003205 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
3206" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003207 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208 setl ma noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003209" call Decho("setl ma noro")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003210 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003211 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01003212" call Decho("setl nomod")
3213" 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 +00003214 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003215" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003216 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003217 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003218 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003219 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003220 else
3221 let g:netrw_dirhist_cnt= 0
3222 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003223 echo "Sorry, no predecessor directory exists yet"
3224 endif
3225
3226 elseif a:chg == 5
3227 " U: change to the subsequent directory stored on the history list
3228" call Decho("(user: <U>) chg to next dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003229 if g:netrw_dirhistmax > 0
3230 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3231 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003232" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +01003234" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003235 setl ma noro
Bram Moolenaaradc21822011-04-01 18:03:16 +02003236 sil! keepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003237" call Decho("removed all lines from buffer (%d)")
Bram Moolenaara6878372014-03-22 21:02:50 +01003238" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003239 setl nomod
3240" 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 +02003241 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003242" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003243 exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
3244 else
3245 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
3246 if g:netrw_dirhist_cnt < 0
3247 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3248 endif
3249 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003250 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003251 else
3252 let g:netrw_dirhist_cnt= 0
3253 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003254 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255
3256 elseif a:chg == 6
Bram Moolenaar5c736222010-01-06 20:54:52 +01003257 " delete the v:count'th bookmark
3258" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
3259 let savefile= s:NetrwHome()."/.netrwbook"
3260 if filereadable(savefile)
Bram Moolenaarff034192013-04-24 18:51:19 +02003261" call Decho("merge bookmarks (active and file)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003262 keepj call s:NetrwBookHistSave() " done here to merge bookmarks first
Bram Moolenaarff034192013-04-24 18:51:19 +02003263" call Decho("bookmark delete savefile<".savefile.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003264 keepj call delete(savefile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003265 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003266" call Decho("remove g:netrw_bookmarklist[".(v:count-1)."]")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003267 keepj call remove(g:netrw_bookmarklist,v:count-1)
Bram Moolenaarff034192013-04-24 18:51:19 +02003268" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003270 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003271 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003272 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003273" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003274endfun
3275
3276" ---------------------------------------------------------------------
3277" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
3278" Sister function: s:NetrwBookHistSave()
3279fun! s:NetrwBookHistRead()
3280" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003281 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3282" " call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
3283 return
3284 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003285 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003286 if !exists("s:netrw_initbookhist")
3287 let home = s:NetrwHome()
3288 let savefile= home."/.netrwbook"
3289 if filereadable(savefile)
3290" call Decho("sourcing .netrwbook")
Bram Moolenaarff034192013-04-24 18:51:19 +02003291 exe "keepalt keepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003292 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003293 if g:netrw_dirhistmax > 0
3294 let savefile= home."/.netrwhist"
3295 if filereadable(savefile)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003296" call Decho("sourcing .netrwhist")
Bram Moolenaarff034192013-04-24 18:51:19 +02003297 exe "keepalt keepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003298 endif
3299 let s:netrw_initbookhist= 1
3300 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003301 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003302 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003303 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003304" call Dret("s:NetrwBookHistRead")
3305endfun
3306
3307" ---------------------------------------------------------------------
3308" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
3309" Sister function: s:NetrwBookHistRead()
3310" I used to do this via viminfo but that appears to
3311" be unreliable for long-term storage
Bram Moolenaar5c736222010-01-06 20:54:52 +01003312fun! s:NetrwBookHistSave()
3313" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003314 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003315" call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
3316 return
3317 endif
3318
Bram Moolenaar5c736222010-01-06 20:54:52 +01003319 let savefile= s:NetrwHome()."/.netrwhist"
3320 1split
3321 call s:NetrwEnew()
Bram Moolenaarff034192013-04-24 18:51:19 +02003322 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3323 setl nocin noai noci magic nospell nohid wig= noaw
3324 setl ma noro write
3325 if exists("+acd") | setl noacd | endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003326 sil! keepj keepalt %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003327
3328 " save .netrwhist -- no attempt to merge
Bram Moolenaarff034192013-04-24 18:51:19 +02003329 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003330 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
3331 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
3332 let lastline = line("$")
3333 let cnt = 1
3334 while cnt <= g:netrw_dirhist_cnt
3335 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3336 let cnt= cnt + 1
3337 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003338 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003339
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003340 sil keepj %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003341 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
3342 " merge and write .netrwbook
3343 let savefile= s:NetrwHome()."/.netrwbook"
3344
3345 if filereadable(savefile)
3346 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaarff034192013-04-24 18:51:19 +02003347 exe "sil keepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003348 for bdm in booklist
3349 if index(g:netrw_bookmarklist,bdm) == -1
3350 call add(g:netrw_bookmarklist,bdm)
3351 endif
3352 endfor
3353 call sort(g:netrw_bookmarklist)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003354 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003355 endif
3356
3357 " construct and save .netrwbook
3358 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003359 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003360 endif
3361 let bgone= bufnr("%")
3362 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003363 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003364
3365" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003366endfun
3367
3368" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003369" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3370" list of the contents of a local or remote directory. It is assumed that the
3371" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3372" with the requested remote hostname first.
3373fun! s:NetrwBrowse(islocal,dirname)
3374 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003375" 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 +01003376" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003377" call Dredir("ls!")
Bram Moolenaara6878372014-03-22 21:02:50 +01003378
Bram Moolenaar97d62492012-11-15 21:28:22 +01003379 " s:NetrwBrowse: initialize history {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003380 if !exists("s:netrw_initbookhist")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003381 keepj call s:NetrwBookHistRead()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003382 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003383
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 " s:NetrwBrowse: simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003385 if a:dirname !~ '^\a\+://'
3386 let dirname= simplify(a:dirname)
3387 else
3388 let dirname= a:dirname
3389 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003390
3391 if exists("s:netrw_skipbrowse")
3392 unlet s:netrw_skipbrowse
Bram Moolenaara6878372014-03-22 21:02:50 +01003393" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">")
3394" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003395 return
3396 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003397
3398 " s:NetrwBrowse: sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003399 if !exists("*shellescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003400 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003401" call Dret("s:NetrwBrowse : missing shellescape()")
3402 return
3403 endif
3404 if !exists("*fnameescape")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003405 keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003406" call Dret("s:NetrwBrowse : missing fnameescape()")
3407 return
3408 endif
3409
Bram Moolenaar97d62492012-11-15 21:28:22 +01003410 " s:NetrwBrowse: save options: {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003411 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003412
Bram Moolenaar97d62492012-11-15 21:28:22 +01003413 " s:NetrwBrowse: re-instate any marked files {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003414 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01003415" call Decho("clearing marked files")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003416 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3417 endif
3418
3419 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar97d62492012-11-15 21:28:22 +01003420 " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003421" call Decho("handle w:netrw_acdkeep:")
3422" call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
3423 call s:NetrwLcd(dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003424 call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01003425" call Decho("getcwd<".getcwd().">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003426
Bram Moolenaar5c736222010-01-06 20:54:52 +01003427 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003428 " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003429" call Decho("attempt transfer as regular file<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003430
Bram Moolenaar97d62492012-11-15 21:28:22 +01003431 " remove any filetype indicator from end of dirname, except for the
Bram Moolenaar446cb832008-06-24 21:56:24 +00003432 " "this is a directory" indicator (/).
3433 " There shouldn't be one of those here, anyway.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003434 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01003435" call Decho("new path<".path.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003436 call s:RemotePathAnalysis(dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003437
Bram Moolenaar97d62492012-11-15 21:28:22 +01003438 " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003439 keepj mark '
Bram Moolenaar5c736222010-01-06 20:54:52 +01003440 call s:NetrwEnew(dirname)
3441 call s:NetrwSafeOptions()
Bram Moolenaarff034192013-04-24 18:51:19 +02003442 setl ma noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003443" call Decho("setl ma noro")
Bram Moolenaar15146672011-10-20 22:22:38 +02003444 let b:netrw_curdir = dirname
3445 let url = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaara6878372014-03-22 21:02:50 +01003446" call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
Bram Moolenaar15146672011-10-20 22:22:38 +02003447 exe "sil! keepj keepalt file ".fnameescape(url)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003448 exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02003449 sil call netrw#NetRead(2,url)
Bram Moolenaara6878372014-03-22 21:02:50 +01003450 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
3451" call Decho("url<".url.">")
3452" call Decho("s:path<".s:path.">")
3453" call Decho("s:fname<".s:fname.">")
3454 if s:path =~ '.bz2'
3455 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3456 elseif s:path =~ '.gz'
3457 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3458 elseif s:path =~ '.gz'
3459 exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3460 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003461 exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003462 endif
3463
Bram Moolenaar97d62492012-11-15 21:28:22 +01003464 " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003465 call s:SetBufWinVars()
3466 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003467" call Decho("setl ma nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003468 setl ma nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01003469" 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 +00003470
Bram Moolenaar446cb832008-06-24 21:56:24 +00003471" call Dret("s:NetrwBrowse : file<".s:fname.">")
3472 return
3473 endif
3474
Bram Moolenaaradc21822011-04-01 18:03:16 +02003475 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003476 call s:UseBufWinVars()
3477
3478 " set up some variables {{{3
3479 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003480 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003481 let s:last_sort_by = g:netrw_sort_by
3482
3483 " set up menu {{{3
Bram Moolenaaradc21822011-04-01 18:03:16 +02003484 keepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003485
Bram Moolenaar97d62492012-11-15 21:28:22 +01003486 " get/set-up buffer {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003487 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
3488 " maintain markfile highlighting
3489 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaara6878372014-03-22 21:02:50 +01003490" call Decho("bufnr(%)=".bufnr('%'))
3491" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003492 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3493 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003494" call Decho("2match none")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003495 2match none
3496 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003497 if reusing && line("$") > 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003498 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003499" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003500 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003501" 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 +00003502" call Dret("s:NetrwBrowse : re-using buffer")
3503 return
3504 endif
3505
3506 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003507" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003508 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003509 if b:netrw_curdir =~ '[/\\]$'
3510 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3511 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003512 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3513 let b:netrw_curdir= b:netrw_curdir."/"
3514 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003515 if b:netrw_curdir == ''
3516 if has("amiga")
3517 " On the Amiga, the empty string connotes the current directory
3518 let b:netrw_curdir= getcwd()
3519 else
3520 " under unix, when the root directory is encountered, the result
3521 " from the preceding substitute is an empty string.
3522 let b:netrw_curdir= '/'
3523 endif
3524 endif
3525 if !a:islocal && b:netrw_curdir !~ '/$'
3526 let b:netrw_curdir= b:netrw_curdir.'/'
3527 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003528" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003529
3530 " ------------
3531 " (local only) {{{3
3532 " ------------
3533 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01003534" call Decho("local only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003535
3536 " Set up ShellCmdPost handling. Append current buffer to browselist
3537 call s:LocalFastBrowser()
3538
3539 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3540 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003541" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
3542" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003543 if !exists("&l:acd") || !&l:acd
Bram Moolenaara6878372014-03-22 21:02:50 +01003544 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003545 endif
3546 endif
3547
3548 " --------------------------------
3549 " remote handling: {{{3
3550 " --------------------------------
3551 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003552" call Decho("remote only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003553
Bram Moolenaar97d62492012-11-15 21:28:22 +01003554 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003555" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003556 if dirname =~ "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003557 let dirname= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003558" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003559 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3560 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3561 if dirname !~ '/$'
3562 let dirname= dirname.'/'
3563 endif
3564 let b:netrw_curdir = dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003565" call Decho("(liststyle is TREELIST) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003566 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003567 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara6878372014-03-22 21:02:50 +01003568" call Decho("(normal) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003569 endif
3570
3571 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3572 if dirname !~ dirpat
3573 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003575 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003577" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003578 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003579" 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 +00003580" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3581 return
3582 endif
3583 let b:netrw_curdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003584" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003585 endif " (additional remote handling)
3586
3587 " -----------------------
3588 " Directory Listing: {{{3
3589 " -----------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02003590 keepj call s:NetrwMaps(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003591 keepj call s:NetrwCommands(a:islocal)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003592 keepj call s:PerformListing(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02003593 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003594 let &l:bexpr= "netrw#BalloonHelp()"
3595" call Decho("set up balloon help: l:bexpr=".&l:bexpr)
3596 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003598 call s:NetrwOptionRestore("w:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599
Bram Moolenaara6878372014-03-22 21:02:50 +01003600 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003601 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
Bram Moolenaara6878372014-03-22 21:02:50 +01003602 " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003603
Bram Moolenaara6878372014-03-22 21:02:50 +01003604" 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 +02003605" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003606 return
3607endfun
3608
3609" ---------------------------------------------------------------------
3610" s:NetrwFileInfo: supports qf (query for file information) {{{2
3611fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003612" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003613 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003614 if a:islocal
3615 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003616
3617 if getline(".") == "../"
3618 echo system("/bin/ls -lsad ".shellescape(".."))
3619" call Decho("#1: echo system(/bin/ls -lsad ".shellescape(..).")")
3620
Bram Moolenaara6878372014-03-22 21:02:50 +01003621 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaar8d043172014-01-23 14:24:41 +01003622 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir))
3623" call Decho("#2: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir).")")
3624
3625 elseif exists("b:netrw_curdir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003626 if b:netrw_curdir =~ '/$'
3627 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003628" call Decho("#3: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname).")")
3629
Bram Moolenaar446cb832008-06-24 21:56:24 +00003630 else
3631 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003632" call Decho("#4: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003633 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003634
Bram Moolenaar446cb832008-06-24 21:56:24 +00003635 else
3636" call Decho('using ls '.a:fname." using cwd<".getcwd().">")
3637 echo system("/bin/ls -lsad ".shellescape(a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003638" call Decho("#5: echo system(/bin/ls -lsad ".shellescape(a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003639 endif
3640 else
3641 " use vim functions to return information about file below cursor
3642" call Decho("using vim functions to query for file info")
3643 if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
3644 let fname= substitute(a:fname,".$","","")
3645 else
3646 let fname= a:fname
3647 endif
3648 let t = getftime(fname)
3649 let sz = getfsize(fname)
3650 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))
Bram Moolenaara6878372014-03-22 21:02:50 +01003651" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003652 endif
3653 else
3654 echo "sorry, \"qf\" not supported yet for remote files"
3655 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003656 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003657" call Dret("s:NetrwFileInfo")
3658endfun
3659
3660" ---------------------------------------------------------------------
3661" s:NetrwGetBuffer: {{{2
3662" returns 0=cleared buffer
3663" 1=re-used buffer
3664fun! s:NetrwGetBuffer(islocal,dirname)
3665" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara6878372014-03-22 21:02:50 +01003666" 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 +00003667 let dirname= a:dirname
3668
3669 " re-use buffer if possible {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003670" call Decho("--re-use a buffer if possible--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003671 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3672 " find NetrwTreeList buffer if there is one
Bram Moolenaara6878372014-03-22 21:02:50 +01003673" call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003674 if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01003675" call Decho(" re-using w:netrw_treebufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003676 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003677 setl ei=all
Bram Moolenaarff034192013-04-24 18:51:19 +02003678 exe "sil! keepalt b ".w:netrw_treebufnr
Bram Moolenaar446cb832008-06-24 21:56:24 +00003679 let &ei= eikeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01003680 setl ma
3681 sil! keepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01003682" 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 +02003683" call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
3684 return 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 endif
3686 let bufnum= -1
Bram Moolenaara6878372014-03-22 21:02:50 +01003687" call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003688
3689 else
3690 " find buffer number of buffer named precisely the same as dirname {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003691" call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003692" call Dredir("(NetrwGetBuffer) ls!","ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003693
3694 " get dirname and associated buffer number
3695 let bufnum = bufnr(escape(dirname,'\'))
Bram Moolenaara6878372014-03-22 21:02:50 +01003696" call Decho(" find buffer<".dirname.">'s number ")
3697" call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003698
3699 if bufnum < 0 && dirname !~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 " try appending a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003701" call Decho(" try appending a trailing / to dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003702 let bufnum= bufnr(escape(dirname.'/','\'))
3703 if bufnum > 0
3704 let dirname= dirname.'/'
3705 endif
3706 endif
3707
3708 if bufnum < 0 && dirname =~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709 " try removing a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003710" call Decho(" try removing a trailing / from dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003711 let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
3712 if bufnum > 0
3713 let dirname= substitute(dirname,'/$','','')
3714 endif
3715 endif
3716
Bram Moolenaara6878372014-03-22 21:02:50 +01003717" call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003718 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches)
3719 if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
3720 " handle approximate matches
Bram Moolenaara6878372014-03-22 21:02:50 +01003721" call Decho(" handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003722 let ibuf = 1
3723 let buflast = bufnr("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01003724" call Decho(" findbuf2: buflast=bufnr($)=".buflast)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003725 while ibuf <= buflast
3726 let bname= substitute(bufname(ibuf),'\\','/','g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00003727 let bname= substitute(bname,'.\zs/$','','')
Bram Moolenaara6878372014-03-22 21:02:50 +01003728" call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003729 if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
3730 " bname is not empty
3731 " dirname ends with bname,
3732 " dirname doesn't start with /, so its not a absolute path
Bram Moolenaara6878372014-03-22 21:02:50 +01003733" call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003734 break
3735 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003736 if bname =~ '^'.dirname.'/\=$'
3737 " bname begins with dirname
3738" call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003739 break
3740 endif
3741 if dirname =~ '^'.bname.'/$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003742" call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
3743 break
3744 endif
3745 if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
3746" call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747 break
3748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003749 let ibuf= ibuf + 1
3750 endwhile
3751 if ibuf > buflast
3752 let bufnum= -1
3753 else
3754 let bufnum= ibuf
3755 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003756" call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003757 endif
3758 endif
3759
3760 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003761" call Decho(" get enew buffer and name it OR re-use buffer")
Bram Moolenaarff034192013-04-24 18:51:19 +02003762 sil! keepj keepalt mark '
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003764" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003765 call s:NetrwEnew(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003766" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767 " name the buffer
3768 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3769 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +01003770" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771 if !exists("s:netrw_treelistnum")
3772 let s:netrw_treelistnum= 1
3773 else
3774 let s:netrw_treelistnum= s:netrw_treelistnum + 1
3775 endif
3776 let w:netrw_treebufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01003777" call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003778 exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003779 setl bt=nofile noswf
Bram Moolenaaradc21822011-04-01 18:03:16 +02003780 nnoremap <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
3781 nnoremap <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
3782 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[')<cr>
3783 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01003784" call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785 else
3786" let v:errmsg= "" " Decho
3787 let escdirname= fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003788" call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003789" call Decho(' exe sil! keepalt file '.escdirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003790" let v:errmsg= "" " Decho
3791 exe 'sil! keepalt file '.escdirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003792" call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003793 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003794" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003795
3796 else " Re-use the buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01003797" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003798 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003799 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800 if getline(2) =~ '^" Netrw Directory Listing'
Bram Moolenaara6878372014-03-22 21:02:50 +01003801" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003802 exe "sil! keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003803 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003804" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
Bram Moolenaarff034192013-04-24 18:51:19 +02003805 exe "sil! keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806 endif
3807 if bufname("%") == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +01003808" call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003809 exe "sil! keepalt file ".fnameescape(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810 endif
3811 let &ei= eikeep
3812 if line("$") <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02003813 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003814" 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 +01003815" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
3816 return 0
3817 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
3818 keepj call s:NetrwListSettings(a:islocal)
3819 sil keepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01003820" 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 +01003821" 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 +00003822 return 0
3823 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01003824" call Decho("--re-use tree listing--")
3825" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003826 sil keepj %d
Bram Moolenaaradc21822011-04-01 18:03:16 +02003827 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003828" 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 +01003829" 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 +00003830 return 0
3831 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003832" 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 +01003833" call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834 return 1
3835 endif
3836 endif
3837
3838 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
3839 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
3840 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
3841 " med 1 D H
3842 " fast 2 H H
Bram Moolenaara6878372014-03-22 21:02:50 +01003843" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 let fname= expand("%")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003845 keepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01003846" call Decho("exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003847 exe "sil! keepj keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848
3849 " delete all lines from buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003850" call Decho("--delete all lines from buffer--")
3851" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003852 sil! keepalt keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853
Bram Moolenaara6878372014-03-22 21:02:50 +01003854" 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 +01003855" call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 return 0
3857endfun
3858
3859" ---------------------------------------------------------------------
3860" s:NetrwGetcwd: get the current directory. {{{2
3861" Change backslashes to forward slashes, if any.
3862" If doesc is true, escape certain troublesome characters
3863fun! s:NetrwGetcwd(doesc)
3864" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
3865 let curdir= substitute(getcwd(),'\\','/','ge')
3866 if curdir !~ '[\/]$'
3867 let curdir= curdir.'/'
3868 endif
3869 if a:doesc
3870 let curdir= fnameescape(curdir)
3871 endif
3872" call Dret("NetrwGetcwd <".curdir.">")
3873 return curdir
3874endfun
3875
3876" ---------------------------------------------------------------------
3877" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
3878fun! s:NetrwGetWord()
3879" call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol("."))
3880 call s:UseBufWinVars()
3881
3882 " insure that w:netrw_liststyle is set up
3883 if !exists("w:netrw_liststyle")
3884 if exists("g:netrw_liststyle")
3885 let w:netrw_liststyle= g:netrw_liststyle
3886 else
3887 let w:netrw_liststyle= s:THINLIST
3888 endif
3889" call Decho("w:netrw_liststyle=".w:netrw_liststyle)
3890 endif
3891
3892 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3893 " Active Banner support
3894" call Decho("active banner handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003895 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 let dirname= "./"
3897 let curline= getline('.')
3898
3899 if curline =~ '"\s*Sorted by\s'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003900 keepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 let s:netrw_skipbrowse= 1
3902 echo 'Pressing "s" also works'
3903
3904 elseif curline =~ '"\s*Sort sequence:'
3905 let s:netrw_skipbrowse= 1
3906 echo 'Press "S" to edit sorting sequence'
3907
3908 elseif curline =~ '"\s*Quick Help:'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003909 keepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910 let s:netrw_skipbrowse= 1
3911 echo 'Pressing "?" also works'
3912
3913 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003914 keepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 let s:netrw_skipbrowse= 1
3916 echo 'Pressing "a" also works'
3917
3918 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003919 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 endif
3921
3922 elseif w:netrw_liststyle == s:THINLIST
3923" call Decho("thin column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003924 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 let dirname= getline('.')
3926
3927 elseif w:netrw_liststyle == s:LONGLIST
3928" call Decho("long column handling")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003929 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003930 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
3931
3932 elseif w:netrw_liststyle == s:TREELIST
3933" call Decho("treelist handling")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003934 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003935
3936 else
3937" call Decho("obtain word from wide listing")
3938 let dirname= getline('.')
3939
3940 if !exists("b:netrw_cpf")
3941 let b:netrw_cpf= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003942 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 +01003943 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944" call Decho("computed cpf=".b:netrw_cpf)
3945 endif
3946
3947" call Decho("buf#".bufnr("%")."<".bufname("%").">")
3948 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
3949" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
3950" call Decho("1: dirname<".dirname.">")
3951 if filestart == 0
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003952 keepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 else
3954 call cursor(line("."),filestart+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003955 keepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 endif
3957 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00003958 let eofname= filestart + b:netrw_cpf + 1
3959 if eofname <= col("$")
3960 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003961 keepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00003962 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003963 keepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00003964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 let dirname = @a
3966 let @a = rega
3967" call Decho("2: dirname<".dirname.">")
3968 let dirname= substitute(dirname,'\s\+$','','e')
3969" call Decho("3: dirname<".dirname.">")
3970 endif
3971
3972 " symlinks are indicated by a trailing "@". Remove it before further processing.
3973 let dirname= substitute(dirname,"@$","","")
3974
3975 " executables are indicated by a trailing "*". Remove it before further processing.
3976 let dirname= substitute(dirname,"\*$","","")
3977
3978" call Dret("s:NetrwGetWord <".dirname.">")
3979 return dirname
3980endfun
3981
3982" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003983" s:NetrwListSettings: make standard settings for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984fun! s:NetrwListSettings(islocal)
3985" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01003986" 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 +00003987 let fname= bufname("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02003988" call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro")
3989 setl bt=nofile nobl ma nonu nowrap noro
3990" call Decho("(NetrwListSettings) exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003991 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02003993 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003995" call Dredir("ls!")
Bram Moolenaarff034192013-04-24 18:51:19 +02003996" call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003997 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02003998 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004000 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004002 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004004" 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 +00004005" call Dret("s:NetrwListSettings")
4006endfun
4007
4008" ---------------------------------------------------------------------
4009" s:NetrwListStyle: {{{2
4010" islocal=0: remote browsing
4011" =1: local browsing
4012fun! s:NetrwListStyle(islocal)
4013" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004014 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 let fname = s:NetrwGetWord()
4016 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
4017 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
4018" call Decho("fname<".fname.">")
4019" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
4020" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
4021
4022 if w:netrw_liststyle == s:THINLIST
4023 " use one column listing
4024" call Decho("use one column list")
4025 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4026
4027 elseif w:netrw_liststyle == s:LONGLIST
4028 " use long list
4029" call Decho("use long list")
4030 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4031
4032 elseif w:netrw_liststyle == s:WIDELIST
4033 " give wide list
4034" call Decho("use wide list")
4035 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4036
4037 elseif w:netrw_liststyle == s:TREELIST
4038" call Decho("use tree list")
4039 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4040
4041 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02004042 keepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004043 let g:netrw_liststyle = s:THINLIST
4044 let w:netrw_liststyle = g:netrw_liststyle
4045 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004047 setl ma noro
4048" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004049
4050 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
4051" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004052 sil! keepj %d
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004053 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara6878372014-03-22 21:02:50 +01004054" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004055 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004056" 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 +00004057
4058 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004059" call Decho("refresh the listing")
4060 let svpos= netrw#SavePosn()
Bram Moolenaaradc21822011-04-01 18:03:16 +02004061 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01004062 keepj call netrw#RestorePosn(svpos)
Bram Moolenaaradc21822011-04-01 18:03:16 +02004063 keepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004064
4065 " keep cursor on the filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004066 sil! keepj $
Bram Moolenaar446cb832008-06-24 21:56:24 +00004067 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4068" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
4069 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004070 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004071 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004072 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004073
4074" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4075endfun
4076
4077" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004078" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4079fun! s:NetrwBannerCtrl(islocal)
4080" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4081
Bram Moolenaar97d62492012-11-15 21:28:22 +01004082 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004083 " toggle the banner (enable/suppress)
4084 let g:netrw_banner= !g:netrw_banner
4085
4086 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004087 let svpos= netrw#SavePosn()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004088 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4089
4090 " keep cursor on the filename
4091 let fname= s:NetrwGetWord()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004092 sil keepj $
Bram Moolenaar5c736222010-01-06 20:54:52 +01004093 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4094" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
4095 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004096 exe "keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01004097 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004098 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004099" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4100endfun
4101
4102" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004103" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4104" .2.[cnt] for bookmarks, and
4105" .3.[cnt] for history
4106" (see s:NetrwMenu())
4107fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004108 if !exists("s:netrw_menucnt")
4109 return
4110 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004111" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112
4113 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004114 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004115 if exists("g:NetrwTopLvlMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004116" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004117 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4118 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004119 endif
4120 if !exists("s:netrw_initbookhist")
4121 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004122 endif
4123
4124 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004125 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004126 let cnt= 1
4127 for bmd in g:netrw_bookmarklist
Bram Moolenaar8d043172014-01-23 14:24:41 +01004128" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd)
4129 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004130
4131 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004132 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004133
4134 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004135 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 +01004136 let cnt= cnt + 1
4137 endfor
4138
4139 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004140
4141 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004142 if g:netrw_dirhistmax > 0
4143 let cnt = g:netrw_dirhist_cnt
4144 let first = 1
4145 let histcnt = 0
4146 while ( first || cnt != g:netrw_dirhist_cnt )
4147 let histcnt = histcnt + 1
4148 let priority = g:netrw_dirhist_cnt + histcnt
4149 if exists("g:netrw_dirhist_{cnt}")
4150 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
4151" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir)
4152 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4153 endif
4154 let first = 0
4155 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4156 if cnt < 0
4157 let cnt= cnt + g:netrw_dirhistmax
4158 endif
4159 endwhile
4160 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004161
Bram Moolenaar9964e462007-05-05 17:54:07 +00004162 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004164endfun
4165
4166" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4168" directory and a new directory name. Also, if the
4169" "new directory name" is actually a file,
4170" NetrwBrowseChgDir() edits the file.
4171fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4172" 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 +01004173" call Decho("win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00004174
Bram Moolenaar97d62492012-11-15 21:28:22 +01004175 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004176 if !exists("b:netrw_curdir")
4177 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4178 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004179 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01004180" call Decho("b:netrw_curdir doesn't exist!")
4181" call Decho("getcwd<".getcwd().">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004182" call Dredir("ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004184 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004185 endif
4186
Bram Moolenaar97d62492012-11-15 21:28:22 +01004187 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01004188" call Decho("saving options")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004189 keepj call s:NetrwOptionSave("s:")
4190 keepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01004191 let nbcd_curpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
Bram Moolenaara6878372014-03-22 21:02:50 +01004193" call Decho("setting s:nbcd_curpos_".bufnr('%')." to SavePosn")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004194 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004195 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004196 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004197 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004198 endif
4199 let newdir = a:newdir
4200 let dolockout = 0
Bram Moolenaara6878372014-03-22 21:02:50 +01004201" call Decho("dirname<".dirname.">")
4202
4203 " ignore <cr>s when done in the banner
4204 if g:netrw_banner
4205" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"))
4206 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
4207 if getline(".") =~ 'Quick Help'
4208" 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.">)")
4209 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
4210" 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.">)")
4211 setl noro ma nowrap
4212 keepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
4213 setl noma nomod nowrap
4214 keepj call netrw#RestorePosn(nbcd_curpos)
4215 keepj call s:NetrwOptionRestore("s:")
4216" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
4217 endif
4218 endif
4219" else " Decho
4220" call Decho("(s:NetrwBrowseChgdir) g:netrw_banner=".g:netrw_banner." (no banner)")
4221 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004222
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 " set up o/s-dependent directory recognition pattern
Bram Moolenaara6878372014-03-22 21:02:50 +01004224" call Decho("set up o/s-dependent directory recognition pattern")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004225 if has("amiga")
4226 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004227 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004228 let dirpat= '[\/]$'
4229 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004230" call Decho("dirname<".dirname."> dirpat<".dirpat.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231
4232 if dirname !~ dirpat
4233 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004234 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004235 let dirname= dirname.'/'
Bram Moolenaara6878372014-03-22 21:02:50 +01004236" call Decho("adjusting dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237 endif
4238
4239 if newdir !~ dirpat
Bram Moolenaar97d62492012-11-15 21:28:22 +01004240 " ------------------------------
4241 " NetrwBrowseChgDir: edit a file {{{3
4242 " ------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004243" call Decho('edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004244
Bram Moolenaar97d62492012-11-15 21:28:22 +01004245 " save position for benefit of Rexplore
Bram Moolenaara6878372014-03-22 21:02:50 +01004246 let s:rexposn_{bufnr("%")}= netrw#SavePosn()
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004247
Bram Moolenaara6878372014-03-22 21:02:50 +01004248" call Decho("edit-a-file: setting s:rexposn_".bufnr("%")." to SavePosn")
4249" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
4250" 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.">")
4251
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara6878372014-03-22 21:02:50 +01004253" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">")
4254" call Decho("edit-a-file: newdir<".newdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 let dirname= s:NetrwTreeDir()
4256 if dirname =~ '/$'
4257 let dirname= dirname.newdir
4258 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004259 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004261" call Decho("edit-a-file: dirname<".dirname.">")
4262" call Decho("edit-a-file: tree listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 elseif newdir =~ '^\(/\|\a:\)'
4264 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004265 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004266 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004267 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004268" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004269 " this lets NetrwBrowseX avoid the edit
4270 if a:0 < 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004271" 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 +02004272 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273 if !exists("s:didsplit")
Bram Moolenaara6878372014-03-22 21:02:50 +01004274" 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 +00004275 if g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004276 " horizontally splitting the window first
Bram Moolenaarff034192013-04-24 18:51:19 +02004277 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004278 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004279 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004280 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004281 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004282 " vertically splitting the window first
Bram Moolenaarff034192013-04-24 18:51:19 +02004283 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004284 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004285 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004288 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004289 keepalt tabnew
Bram Moolenaar446cb832008-06-24 21:56:24 +00004290 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004291 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004293 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004295 return
4296 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004297 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004298 " handling a file, didn't split, so remove menu
Bram Moolenaara6878372014-03-22 21:02:50 +01004299" call Decho("edit-a-file: handling a file+didn't split, so remove menu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 call s:NetrwMenu(0)
4301 " optional change to window
4302 if g:netrw_chgwin >= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02004303 exe "keepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004304 endif
4305 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004306 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004307
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 " the point where netrw actually edits the (local) file
4309 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004310 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004311 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01004312" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004313 " some like c-^ to return to the last edited file
4314 " others like c-^ to return to the netrw buffer
4315 if exists("g:netrw_altfile") && g:netrw_altfile
4316 exe "keepj keepalt e! ".fnameescape(dirname)
4317 else
4318 exe "keepj e! ".fnameescape(dirname)
4319 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004320 call s:NetrwCursor()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004321 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004322" call Decho("edit-a-file: remote file: NetrwBrowse will edit it")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004325
4326 " handle g:Netrw_funcref -- call external-to-netrw functions
4327 " This code will handle g:Netrw_funcref as an individual function reference
4328 " or as a list of function references. It will ignore anything that's not
4329 " a function reference. See :help Funcref for information about function references.
4330 if exists("g:Netrw_funcref")
Bram Moolenaara6878372014-03-22 21:02:50 +01004331" call Decho("edit-a-file: handle optional Funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004332 if type(g:Netrw_funcref) == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01004333" call Decho("edit-a-file: handling a g:Netrw_funcref")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004334 keepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004335 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01004336" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004337 for Fncref in g:Netrw_funcref
4338 if type(FncRef) == 2
Bram Moolenaaradc21822011-04-01 18:03:16 +02004339 keepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004340 endif
4341 endfor
4342 endif
4343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004344 endif
4345
4346 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004347 " ----------------------------------------------------
4348 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4349 " ----------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004350" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004351 let dirname = newdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02004352 keepj call s:SetRexDir(a:islocal,dirname)
4353 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354
4355 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004356 " ---------------------------------------------
4357 " NetrwBrowseChgDir: refresh the directory list {{{3
4358 " ---------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004359" call Decho('refresh-dirlist: case "refresh directory listing": newdir == "./"')
Bram Moolenaaradc21822011-04-01 18:03:16 +02004360 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361
4362 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004363 " --------------------------------------
4364 " NetrwBrowseChgDir: go up one directory {{{3
4365 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004366" call Decho('go-up: case "go up one directory": newdir == "../"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367
4368 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4369 " force a refresh
Bram Moolenaara6878372014-03-22 21:02:50 +01004370" call Decho("go-up: clear buffer<".expand("%")."> with :%d")
4371" call Decho("go-up: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004372 setl noro ma
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004373 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004374 endif
4375
4376 if has("amiga")
4377 " amiga
Bram Moolenaara6878372014-03-22 21:02:50 +01004378" call Decho('go-up: case "go up one directory": newdir == "../" and amiga')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 if a:islocal
4380 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4381 let dirname= substitute(dirname,'/$','','')
4382 else
4383 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4384 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004385" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
Bram Moolenaar8d043172014-01-23 14:24:41 +01004387 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4388 " windows
4389 if a:islocal
4390 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4391 if dirname == ""
4392 let dirname= '/'
4393 endif
4394 else
4395 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4396 endif
4397 if dirname =~ '^\a:$'
4398 let dirname= dirname.'/'
4399 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004400" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004401
Bram Moolenaar446cb832008-06-24 21:56:24 +00004402 else
4403 " unix or cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +01004404" call Decho('go-up: case "go up one directory": newdir == "../" and unix or cygwin')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405 if a:islocal
4406 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4407 if dirname == ""
4408 let dirname= '/'
4409 endif
4410 else
4411 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4412 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004413" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004414 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004415 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416
4417 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004418 " --------------------------------------
4419 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4420 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004421" call Decho('tree-list: case liststyle is TREELIST and w:netrw_treedict exists')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422 " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh)
Bram Moolenaara6878372014-03-22 21:02:50 +01004423" call Decho("tree-list: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004424 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004426" call Decho("tree-list: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004427 keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 endif
4429 let treedir = s:NetrwTreeDir()
4430 let s:treecurpos = nbcd_curpos
4431 let haskey= 0
Bram Moolenaara6878372014-03-22 21:02:50 +01004432" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433
4434 " search treedict for tree dir as-is
4435 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004436" call Decho('tree-list: ....searched for treedir<'.treedir.'> : found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004437 let haskey= 1
4438 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004439" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 endif
4441
4442 " search treedict for treedir with a / appended
4443 if !haskey && treedir !~ '/$'
4444 if has_key(w:netrw_treedict,treedir."/")
4445 let treedir= treedir."/"
Bram Moolenaara6878372014-03-22 21:02:50 +01004446" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let haskey = 1
4448 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004449" call Decho('tree-list: ....searched for treedir<'.treedir.'/> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 endif
4451 endif
4452
4453 " search treedict for treedir with any trailing / elided
4454 if !haskey && treedir =~ '/$'
4455 let treedir= substitute(treedir,'/$','','')
4456 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004457" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 let haskey = 1
4459 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004460" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004461 endif
4462 endif
4463
4464 if haskey
4465 " close tree listing for selected subdirectory
Bram Moolenaara6878372014-03-22 21:02:50 +01004466" call Decho("tree-list: closing selected subdirectory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 call remove(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004468" call Decho("tree-list: removed entry<".treedir."> from treedict")
4469" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004470 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471 else
4472 " go down one directory
4473 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara6878372014-03-22 21:02:50 +01004474" call Decho("tree-list: go down one dir: treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004476 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004477 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478
4479 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004480 " ----------------------------------------
4481 " NetrwBrowseChgDir: Go down one directory {{{3
4482 " ----------------------------------------
4483 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004484" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004485 keepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004486 endif
4487
Bram Moolenaar97d62492012-11-15 21:28:22 +01004488 " --------------------------------------
4489 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4490 " --------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02004491 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 if dolockout
Bram Moolenaara6878372014-03-22 21:02:50 +01004493" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004494 if filewritable(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01004495" call Decho("restore: doing modification lockout settings: ma nomod noro")
4496" call Decho("restore: setl ma nomod noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004497 setl ma nomod noro
Bram Moolenaara6878372014-03-22 21:02:50 +01004498" 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 +02004499 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004500" call Decho("restore: doing modification lockout settings: ma nomod ro")
4501" call Decho("restore: setl ma nomod noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004502 setl ma nomod ro
Bram Moolenaara6878372014-03-22 21:02:50 +01004503" 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 +02004504 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004505 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004506 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004507
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
4509 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004510endfun
4511
4512" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004513" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4514" for thin, long, and wide: cursor placed just after banner
4515" for tree, keeps cursor on current filename
4516fun! s:NetrwBrowseUpDir(islocal)
4517" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
4518 norm! 0
4519 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4520" call Decho("ftp + treestyle")
4521 let curline= getline(".")
4522 let swwline= winline() - 1
4523 if exists("w:netrw_treetop")
4524 let b:netrw_curdir= w:netrw_treetop
4525 endif
4526 if a:islocal
4527 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4528 else
4529 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4530 endif
4531 if !search('\c^'.s:treedepthstring.curline,'cw')
4532 if !search('\c^'.curline,'cw')
4533 sil! keepj 1
4534 endif
4535 endif
4536 exe "sil! keepj norm! z\<cr>"
4537 while winline() < swwline
4538 let curwinline= winline()
4539 exe "sil! keepj norm! \<c-y>"
4540 if curwinline == winline()
4541 break
4542 endif
4543 endwhile
4544 else
4545" call Decho("ftp + not treestyle")
4546 if a:islocal
4547 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4548 else
4549 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4550 endif
4551 if exists("w:netrw_bannercnt")
4552" call Decho("moving to line#".w:netrw_bannercnt)
4553 exe w:netrw_bannercnt
4554 else
4555 1
4556 endif
4557 endif
4558" call Dret("s:NetrwBrowseUpDir")
4559endfun
4560
4561" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004562" s:NetrwBrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
4563" given filename; typically this means given their extension.
4564" 0=local, 1=remote
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565fun! netrw#NetrwBrowseX(fname,remote)
4566" call Dfunc("NetrwBrowseX(fname<".a:fname."> remote=".a:remote.")")
4567
Bram Moolenaar97d62492012-11-15 21:28:22 +01004568 let ykeep = @@
Bram Moolenaara6878372014-03-22 21:02:50 +01004569 let screenposn = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01004570
Bram Moolenaar5c736222010-01-06 20:54:52 +01004571 " special core dump handler
4572 if a:fname =~ '/core\(\.\d\+\)\=$'
4573 if exists("g:Netrw_corehandler")
4574 if type(g:Netrw_corehandler) == 2
4575 " g:Netrw_corehandler is a function reference (see :help Funcref)
4576" call Decho("g:Netrw_corehandler is a funcref")
4577 call g:Netrw_corehandler(a:fname)
Bram Moolenaarff034192013-04-24 18:51:19 +02004578 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01004579 " g:Netrw_corehandler is a List of function references (see :help Funcref)
4580" call Decho("g:Netrw_corehandler is a List")
4581 for Fncref in g:Netrw_corehandler
4582 if type(FncRef) == 2
4583 call FncRef(a:fname)
4584 endif
4585 endfor
4586 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004587 call netrw#RestorePosn(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004588 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004589" call Dret("NetrwBrowseX : coredump handler invoked")
4590 return
4591 endif
4592 endif
4593
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 " set up the filename
4595 " (lower case the extension, make a local copy of a remote file)
4596 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
4597 if has("win32") || has("win95") || has("win64") || has("win16")
4598 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00004599 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004600" call Decho("exten<".exten.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601
4602 " seems kde systems often have gnome-open due to dependencies, even though
4603 " gnome-open's subsidiary display tools are largely absent. Kde systems
4604 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
4605 if !exists("s:haskdeinit")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004606 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004607 let s:haskdeinit= system("ps -e") =~ 'kdeinit'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608 if v:shell_error
4609 let s:haskdeinit = 0
4610 endif
4611 else
4612 let s:haskdeinit= 0
4613 endif
4614" call Decho("setting s:haskdeinit=".s:haskdeinit)
4615 endif
4616
4617 if a:remote == 1
4618 " create a local copy
Bram Moolenaara6878372014-03-22 21:02:50 +01004619" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02004620 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01004621 call netrw#NetRead(3,a:fname)
4622 " attempt to rename tempfile
4623 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004624 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004625" call Decho("basename<".basename.">")
4626" call Decho("newname <".newname.">")
4627 if rename(s:netrw_tmpfile,newname) == 0
4628 " renaming succeeded
4629 let fname= newname
4630 else
4631 " renaming failed
4632 let fname= s:netrw_tmpfile
4633 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00004634 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004635" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004636 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004637 " special ~ handler for local
4638 if fname =~ '^\~' && expand("$HOME") != ""
4639" call Decho('invoking special ~ handler')
4640 let fname= substitute(fname,'^\~',expand("$HOME"),'')
4641 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004642 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004643" call Decho("fname<".fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004644" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
4645
4646 " set up redirection
4647 if &srr =~ "%s"
4648 if (has("win32") || has("win95") || has("win64") || has("win16"))
4649 let redir= substitute(&srr,"%s","nul","")
4650 else
4651 let redir= substitute(&srr,"%s","/dev/null","")
4652 endif
4653 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
4654 let redir= &srr . "nul"
4655 else
4656 let redir= &srr . "/dev/null"
4657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004658" call Decho("set up redirection: redir{".redir."} srr{".&srr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004659
4660 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004661" call Decho("extract any viewing options")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004662 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004663" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004664 if g:netrw_browsex_viewer =~ '\s'
4665 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
4666 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
4667 let oviewer = ''
4668 let cnt = 1
4669 while !executable(viewer) && viewer != oviewer
4670 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
4671 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
4672 let cnt = cnt + 1
4673 let oviewer = viewer
4674" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">")
4675 endwhile
4676 else
4677 let viewer = g:netrw_browsex_viewer
4678 let viewopt = ""
4679 endif
4680" call Decho("viewer<".viewer."> viewopt<".viewopt.">")
4681 endif
4682
4683 " execute the file handler
Bram Moolenaar97d62492012-11-15 21:28:22 +01004684" call Decho("execute the file handler (if any)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004685 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
4686" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
4687 let ret= netrwFileHandlers#Invoke(exten,fname)
4688
4689 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
4690" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004691" call Decho("exe sil !".viewer." ".viewopt.shellescape(fname,1).redir)
4692 exe "sil !".viewer." ".viewopt.shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004693 let ret= v:shell_error
4694
4695 elseif has("win32") || has("win64")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004696" call Decho("windows")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004697 if executable("start")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004698" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
4699 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004700 elseif executable("rundll32")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004701" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
4702 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004703 else
4704 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
4705 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004706 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
4707 let ret= v:shell_error
4708
Bram Moolenaar97d62492012-11-15 21:28:22 +01004709 elseif has("win32unix")
4710 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
4711" call Decho("cygwin: winfname<".shellescape(winfname,1).">")
4712 if executable("start")
4713" call Decho('exe sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
4714 exe 'sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
4715 elseif executable("rundll32")
4716" call Decho('exe sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
4717 exe 'sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1)
4718 else
4719 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
4720 endif
4721 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
4722 let ret= v:shell_error
4723
4724 elseif has("unix") && executable("xdg-open") && !s:haskdeinit
4725" call Decho("unix and xdg-open")
4726" call Decho("exe sil !xdg-open ".shellescape(fname,1)." ".redir)
4727 exe "sil !xdg-open ".shellescape(fname,1).redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004728 let ret= v:shell_error
4729
4730 elseif has("unix") && executable("kfmclient") && s:haskdeinit
Bram Moolenaar97d62492012-11-15 21:28:22 +01004731" call Decho("unix and kfmclient")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004732" call Decho("exe sil !kfmclient exec ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004733 exe "sil !kfmclient exec ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004734 let ret= v:shell_error
4735
4736 elseif has("macunix") && executable("open")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004737" call Decho("macunix and open")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004738" call Decho("exe sil !open ".shellescape(fname,1)." ".redir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004739 exe "sil !open ".shellescape(fname,1)." ".redir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740 let ret= v:shell_error
4741
4742 else
4743 " netrwFileHandlers#Invoke() always returns 0
4744 let ret= netrwFileHandlers#Invoke(exten,fname)
4745 endif
4746
4747 " if unsuccessful, attempt netrwFileHandlers#Invoke()
4748 if ret
4749 let ret= netrwFileHandlers#Invoke(exten,fname)
4750 endif
4751
Bram Moolenaarc236c162008-07-13 17:41:49 +00004752 " restoring redraw! after external file handlers
4753 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00004754
4755 " cleanup: remove temporary file,
4756 " delete current buffer if success with handler,
4757 " return to prior buffer (directory listing)
4758 " Feb 12, 2008: had to de-activiate removal of
4759 " temporary file because it wasn't getting seen.
4760" if a:remote == 1 && fname != a:fname
Bram Moolenaar97d62492012-11-15 21:28:22 +01004761"" call Decho("deleting temporary file<".fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004762" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004763" endif
4764
4765 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02004766 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00004767 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004768 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004769 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004770 exe "sil! keepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004771" redraw!
4772 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004773 call netrw#RestorePosn(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004774 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004775
4776" call Dret("NetrwBrowseX")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777endfun
4778
4779" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004780" s:NetrwChgPerm: (implements "gp") change file permission {{{2
4781fun! s:NetrwChgPerm(islocal,curdir)
4782" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004783 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004784 call inputsave()
4785 let newperm= input("Enter new permission: ")
4786 call inputrestore()
4787 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'')
4788 let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'')
4789" call Decho("chgperm<".chgperm.">")
4790 call system(chgperm)
4791 if v:shell_error != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02004792 keepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793 endif
4794 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02004795 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004796 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004797 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004798" call Dret("s:NetrwChgPerm")
4799endfun
4800
4801" ---------------------------------------------------------------------
4802" s:NetrwClearExplore: clear explore variables (if any) {{{2
4803fun! s:NetrwClearExplore()
4804" call Dfunc("s:NetrwClearExplore()")
4805 2match none
4806 if exists("s:explore_match") |unlet s:explore_match |endif
4807 if exists("s:explore_indx") |unlet s:explore_indx |endif
4808 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
4809 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
4810 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
4811 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
4812 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
4813 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
4814 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
4815" redraw!
4816 echo " "
4817 echo " "
4818" call Dret("s:NetrwClearExplore")
4819endfun
4820
4821" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004822" s:NetrwExploreListUniq: {{{2
4823fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02004824" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004825
4826 " this assumes that the list is already sorted
4827 let newexplist= []
4828 for member in a:explist
4829 if !exists("uniqmember") || member != uniqmember
4830 let uniqmember = member
4831 let newexplist = newexplist + [ member ]
4832 endif
4833 endfor
4834
Bram Moolenaar15146672011-10-20 22:22:38 +02004835" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004836 return newexplist
4837endfun
4838
4839" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02004840" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
4841fun! s:NetrwForceChgDir(islocal,newdir)
4842" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004843 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02004844 if a:newdir !~ '/$'
4845 " ok, looks like force is needed to get directory-style treatment
4846 if a:newdir =~ '@$'
4847 let newdir= substitute(a:newdir,'@$','/','')
4848 elseif a:newdir =~ '[*=|\\]$'
4849 let newdir= substitute(a:newdir,'.$','/','')
4850 else
4851 let newdir= a:newdir.'/'
4852 endif
4853" call Decho("adjusting newdir<".newdir."> due to gd")
4854 else
4855 " should already be getting treatment as a directory
4856 let newdir= a:newdir
4857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004858 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02004859 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004860 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02004861" call Dret("s:NetrwForceChgDir")
4862endfun
4863
4864" ---------------------------------------------------------------------
4865" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
4866fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02004867" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02004868 if a:newfile =~ '[/@*=|\\]$'
4869 let newfile= substitute(a:newfile,'.$','','')
4870 else
4871 let newfile= a:newfile
4872 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004873 if a:islocal
4874 call s:NetrwBrowseChgDir(a:islocal,newfile)
4875 else
4876 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
4877 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02004878" call Dret("s:NetrwForceFile")
4879endfun
4880
4881" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
4883" and switches the hiding mode. The actual hiding is done by
4884" s:NetrwListHide().
4885" g:netrw_hide= 0: show all
4886" 1: show not-hidden files
4887" 2: show hidden files only
4888fun! s:NetrwHide(islocal)
4889" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004890 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01004891 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892
4893 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01004894" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">")
4896
4897 " hide the files in the markfile list
4898 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02004899" 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 +00004900 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
4901 " remove fname from hiding list
4902 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
4903 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
4904 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
4905" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">")
4906 else
4907 " append fname to hiding list
4908 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
4909 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
4910 else
4911 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
4912 endif
4913" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">")
4914 endif
4915 endfor
Bram Moolenaaradc21822011-04-01 18:03:16 +02004916 keepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917 let g:netrw_hide= 1
4918
4919 else
4920
4921 " switch between show-all/show-not-hidden/show-hidden
4922 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004923 exe "keepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02004925 keepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004926 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927" call Dret("NetrwHide")
4928 return
4929 endif
4930 endif
4931
Bram Moolenaaradc21822011-04-01 18:03:16 +02004932 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01004933 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004936endfun
4937
4938" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004939" s:NetrwHidden: invoked by "gh" {{{2
4940fun! s:NetrwHidden(islocal)
4941" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004942 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 " save current position
Bram Moolenaara6878372014-03-22 21:02:50 +01004944 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004945
4946 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
4947 " remove pattern from hiding list
4948 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004949 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004950 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
4951 else
4952 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
4953 endif
4954
4955 " refresh screen and return to saved position
Bram Moolenaaradc21822011-04-01 18:03:16 +02004956 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01004957 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959" call Dret("s:NetrwHidden")
4960endfun
4961
4962" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004963" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
4964fun! s:NetrwHome()
4965 if exists("g:netrw_home")
4966 let home= g:netrw_home
4967 else
4968 " go to vim plugin home
4969 for home in split(&rtp,',') + ['']
4970 if isdirectory(home) && filewritable(home) | break | endif
4971 let basehome= substitute(home,'[/\\]\.vim$','','')
4972 if isdirectory(basehome) && filewritable(basehome)
4973 let home= basehome."/.vim"
4974 break
4975 endif
4976 endfor
4977 if home == ""
4978 " just pick the first directory
4979 let home= substitute(&rtp,',.*$','','')
4980 endif
4981 if (has("win32") || has("win95") || has("win64") || has("win16"))
4982 let home= substitute(home,'/','\\','g')
4983 endif
4984 endif
4985 " insure that the home directory exists
Bram Moolenaarff034192013-04-24 18:51:19 +02004986 if g:netrw_dirhistmax > 0 && !isdirectory(home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004987 if exists("g:netrw_mkdir")
4988 call system(g:netrw_mkdir." ".shellescape(home))
4989 else
4990 call mkdir(home)
4991 endif
4992 endif
4993 let g:netrw_home= home
4994 return home
4995endfun
4996
4997" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
4999fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005000 if exists("s:netrwdrag")
5001 return
5002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005003" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005004
Bram Moolenaar97d62492012-11-15 21:28:22 +01005005 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005006 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005007 while getchar(0) != 0
5008 "clear the input stream
5009 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005010 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005011 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005012 let mouse_lnum = v:mouse_lnum
5013 let wlastline = line('w$')
5014 let lastline = line('$')
5015" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr())
5016" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0))
5017 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5018 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005019 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005020" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5021 return
5022 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005023 " NOTE: following test is preventing leftmouse selection/deselection of directories and files in treelist mode (Dec 04, 2013)
5024 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
5025 " without this test.
5026" if v:mouse_col != col('.')
5027" let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005028" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005029" return
5030" endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005031
Bram Moolenaar446cb832008-06-24 21:56:24 +00005032 if a:islocal
5033 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005034 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005035 endif
5036 else
5037 if exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005038 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005039 endif
5040 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005041 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042" call Dret("s:NetrwLeftmouse")
5043endfun
5044
5045" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005046" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5047fun! s:NetrwSLeftmouse(islocal)
5048" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
5049
5050 let s:ngw= s:NetrwGetWord()
5051 call s:NetrwMarkFile(a:islocal,s:ngw)
5052
5053" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005054endfun
5055
5056" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005057" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5058" Used to mark multiple files.
5059fun! s:NetrwSLeftdrag(islocal)
5060" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5061 if !exists("s:netrwdrag")
5062 let s:netrwdrag = winnr()
5063 if a:islocal
5064 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005065 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005066 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005067 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005068 endif
5069 let ngw = s:NetrwGetWord()
5070 if !exists("s:ngw") || s:ngw != ngw
5071 call s:NetrwMarkFile(a:islocal,ngw)
5072 endif
5073 let s:ngw= ngw
5074" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5075endfun
5076
5077" ---------------------------------------------------------------------
5078" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5079fun! s:NetrwSLeftrelease(islocal)
5080" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5081 if exists("s:netrwdrag")
5082 nunmap <s-leftrelease>
5083 let ngw = s:NetrwGetWord()
5084 if !exists("s:ngw") || s:ngw != ngw
5085 call s:NetrwMarkFile(a:islocal,ngw)
5086 endif
5087 if exists("s:ngw")
5088 unlet s:ngw
5089 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005090 unlet s:netrwdrag
5091 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005092" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005093endfun
5094
5095" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
5097" separated patterns given in g:netrw_list_hide
5098fun! s:NetrwListHide()
Bram Moolenaaradc21822011-04-01 18:03:16 +02005099" call Dfunc("NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005100 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101
5102 " find a character not in the "hide" string to use as a separator for :g and :v commands
5103 " How-it-works: take the hiding command, convert it into a range. Duplicate
5104 " characters don't matter. Remove all such characters from the '/~...90'
5105 " string. Use the first character left as a separator character.
5106 let listhide= g:netrw_list_hide
5107 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
5108" call Decho("sep=".sep)
5109
5110 while listhide != ""
5111 if listhide =~ ','
5112 let hide = substitute(listhide,',.*$','','e')
5113 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5114 else
5115 let hide = listhide
5116 let listhide = ""
5117 endif
5118
5119 " Prune the list by hiding any files which match
5120 if g:netrw_hide == 1
5121" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005122 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 elseif g:netrw_hide == 2
5124" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005125 exe 'sil! keepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 endif
5127 endwhile
5128 if g:netrw_hide == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01005129 exe 'sil! keepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
5130 exe 'sil! keepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 endif
5132
Bram Moolenaaradc21822011-04-01 18:03:16 +02005133 " remove any blank lines that have somehow remained.
5134 " This seems to happen under Windows.
5135 exe 'sil! keepj 1,$g@^\s*$@d'
5136
Bram Moolenaar97d62492012-11-15 21:28:22 +01005137 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138" call Dret("NetrwListHide")
5139endfun
5140
5141" ---------------------------------------------------------------------
5142" NetrwHideEdit: allows user to edit the file/directory hiding list
5143fun! s:NetrwHideEdit(islocal)
5144" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5145
Bram Moolenaar97d62492012-11-15 21:28:22 +01005146 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 " save current cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005148 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149
5150 " get new hiding list from user
5151 call inputsave()
5152 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5153 call inputrestore()
5154 let g:netrw_list_hide= newhide
5155" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
5156
5157 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02005158 sil keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159
5160 " restore cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005161 call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005162 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163
5164" call Dret("NetrwHideEdit")
5165endfun
5166
5167" ---------------------------------------------------------------------
5168" NetSortSequence: allows user to edit the sorting sequence
5169fun! s:NetSortSequence(islocal)
5170" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
5171
Bram Moolenaar97d62492012-11-15 21:28:22 +01005172 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01005173 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174 call inputsave()
5175 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
5176 call inputrestore()
5177
5178 " refresh the listing
5179 let g:netrw_sort_sequence= newsortseq
Bram Moolenaaradc21822011-04-01 18:03:16 +02005180 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005181 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005183
5184" call Dret("NetSortSequence")
5185endfun
5186
5187" ---------------------------------------------------------------------
5188" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
5189fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01005190" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005191
Bram Moolenaar97d62492012-11-15 21:28:22 +01005192 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193 " get name of new directory from user. A bare <CR> will skip.
5194 " if its currently a directory, also request will be skipped, but with
5195 " a message.
5196 call inputsave()
5197 let newdirname= input("Please give directory name: ")
5198 call inputrestore()
5199" call Decho("newdirname<".newdirname.">")
5200
5201 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005202 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005203" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204 return
5205 endif
5206
5207 if a:usrhost == ""
5208" call Decho("local mkdir")
5209
5210 " Local mkdir:
5211 " sanity checks
5212 let fullnewdir= b:netrw_curdir.'/'.newdirname
5213" call Decho("fullnewdir<".fullnewdir.">")
5214 if isdirectory(fullnewdir)
5215 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005216 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005217 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005218 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005219" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005220 return
5221 endif
5222 if s:FileReadable(fullnewdir)
5223 if !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005224 keepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005225 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005226 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005227" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005228 return
5229 endif
5230
5231 " requested new local directory is neither a pre-existing file or
5232 " directory, so make it!
5233 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005234 if has("unix")
5235 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5236 else
5237 call mkdir(fullnewdir,"p")
5238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005239 else
5240 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005242" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005243" call Decho("exe sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
5244 exe "sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005245 if v:shell_error != 0
5246 let @@= ykeep
5247 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 +01005248" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005249 return
5250 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005251 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01005252" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir)
5253 call s:NetrwLcd(netrw_origdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005254 endif
5255 endif
5256
5257 if v:shell_error == 0
5258 " refresh listing
5259" call Decho("refresh listing")
Bram Moolenaara6878372014-03-22 21:02:50 +01005260 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005261 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005262 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005263 elseif !exists("g:netrw_quiet")
5264 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5265 endif
5266" redraw!
5267
5268 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005269 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005270" call Decho("remote mkdir")
5271 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5272 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaaradc21822011-04-01 18:03:16 +02005273" call Decho("exe sil! !".mkdircmd." ".shellescape(newdirname,1))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005274 exe "sil! !".mkdircmd." ".shellescape(newdirname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005275 if v:shell_error == 0
5276 " refresh listing
Bram Moolenaara6878372014-03-22 21:02:50 +01005277 let svpos= netrw#SavePosn()
Bram Moolenaaradc21822011-04-01 18:03:16 +02005278 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005280 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005281 keepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005282 endif
5283" redraw!
5284
5285 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005286 " Remote mkdir: using ftp+.netrc
5287 let svpos= netrw#SavePosn()
5288" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5289 if exists("b:netrw_fname")
5290" call Decho("b:netrw_fname<".b:netrw_fname.">")
5291 let remotepath= b:netrw_fname
5292 else
5293 let remotepath= ""
5294 endif
5295 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar15146672011-10-20 22:22:38 +02005296 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005297 keepj call netrw#RestorePosn(svpos)
5298
Bram Moolenaar446cb832008-06-24 21:56:24 +00005299 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005300 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
5301 let svpos= netrw#SavePosn()
5302" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5303 if exists("b:netrw_fname")
5304" call Decho("b:netrw_fname<".b:netrw_fname.">")
5305 let remotepath= b:netrw_fname
5306 else
5307 let remotepath= ""
5308 endif
5309 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar15146672011-10-20 22:22:38 +02005310 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005311 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005312 endif
5313
Bram Moolenaar97d62492012-11-15 21:28:22 +01005314 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005315" call Dret("s:NetrwMakeDir")
5316endfun
5317
5318" ---------------------------------------------------------------------
5319" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
5320fun! s:TreeSqueezeDir(islocal)
5321" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
5322 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5323 " its a tree-listing style
5324 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5325 let iline = line(".") - 1
5326 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
5327" call Decho("curdepth=".curdepth)
5328" call Decho("stopline#".stopline)
5329" call Decho("starting with line#".line(".").": ".getline('.'))
5330 while iline > stopline
5331 " find a line that has less depth
5332 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5333" call Decho("considering line#".line(".").": ".getline('.'))
5334 if depth < curdepth
5335 break
5336 endif
5337 norm! k
5338 endwhile
5339" call Decho("squeezing at line#".line(".").": ".getline('.'))
5340 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
5341 endif
5342" call Dret("s:TreeSqueezeDir")
5343endfun
5344
5345" ---------------------------------------------------------------------
5346" s:NetrwMaps: {{{2
5347fun! s:NetrwMaps(islocal)
5348" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
5349
5350 if g:netrw_mousemaps && g:netrw_retmap
5351" call Decho("set up Rexplore 2-leftmouse")
5352 if !hasmapto("<Plug>NetrwReturn")
5353 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
5354" call Decho("making map for 2-leftmouse")
5355 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
5356 elseif maparg("<c-leftmouse>","n") == ""
5357" call Decho("making map for c-leftmouse")
5358 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
5359 endif
5360 endif
5361 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
5362" call Decho("made <Plug>NetrwReturn map")
5363 endif
5364
5365 if a:islocal
5366" call Decho("make local maps")
5367 " local normal-mode maps
5368 nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr>
5369 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr>
5370 nnoremap <buffer> <silent> c :call <SID>NetrwLcd(b:netrw_curdir)<cr>
5371 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
5372 nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5373 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(1)<cr>
5374 nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>
5375 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(1)<cr>
5376 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5377 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
5378 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
5379 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr>
5380 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5381 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
5382 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr>
5383 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5384 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5385 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5386 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5387 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5388 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5389 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
5390 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5391 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5392 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5393 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5394 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5395 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5396 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5397 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5398 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
5399 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1)<cr>
5400 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5401 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5402 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr>
5403 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr>
5404 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5405 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr>
5406 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5407 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5408 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5409 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>
5410 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr>
5411 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
5412 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr>
5413 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5414 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5415 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5416 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5417 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr>
5418 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
5419 nnoremap <buffer> <silent> X :call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
5420 " local insert-mode maps
5421 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr>
5422 inoremap <buffer> <silent> c <c-o>:exe "keepjumps lcd ".fnameescape(b:netrw_curdir)<cr>
5423 inoremap <buffer> <silent> c <c-o>:call <SID>NetrwLcd(b:netrw_curdir)<cr>
5424 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
5425 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr>
5426 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(1)<cr>
5427 inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5428 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(1)<cr>
5429 inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>
5430 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5431 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr>
5432 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5433 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
5434 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr>
5435 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5436 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5437 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5438 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5439 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5440 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5441 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5442 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5443 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5444 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5445 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5446 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5447 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5448 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5449 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr>
5450 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1)<cr>
5451 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5452 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5453 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr>
5454 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr>
5455 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5456 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5457 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5458 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5459 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5460 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>
5461 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr>
5462 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr>
5463 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr>
5464 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5465 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5466 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5467 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5468 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr>
5469 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
5470 if !hasmapto('<Plug>NetrwHideEdit')
5471 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5472 imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5473 endif
5474 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
5475 if !hasmapto('<Plug>NetrwRefresh')
5476 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5477 imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5478 endif
5479 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
5480 if s:didstarstar || !mapcheck("<s-down>","n")
5481 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
5482 inoremap <buffer> <silent> <s-down> :Nexplore<cr>
5483 endif
5484 if s:didstarstar || !mapcheck("<s-up>","n")
5485 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
5486 inoremap <buffer> <silent> <s-up> :Pexplore<cr>
5487 endif
5488 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
5489 if g:netrw_mousemaps == 1
5490 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
5491 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
5492 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
5493 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
5494 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
5495 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
5496 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
5497 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
5498 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
5499 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
5500 imap <buffer> <leftmouse> <Plug>ILeftmouse
5501 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr>
5502 imap <buffer> <middlemouse> <Plug>IMiddlemouse
5503 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5504 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
5505 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5506 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5507 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5508 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5509 endif
5510 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5511 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5512 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5513 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>'
5514 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5515 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5516 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5517 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5518 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5519 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5520 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>'
5521 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
5522
5523 else " remote
5524" call Decho("make remote maps")
5525 call s:RemotePathAnalysis(b:netrw_curdir)
5526 " remote normal-mode maps
5527 nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
5528 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(0)<cr>
5529 nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5530 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(0)<cr>
5531 nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr>
5532 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5533 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
5534 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
5535 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
5536 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5537 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
5538 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
5539 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
5540 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
5541 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
5542 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
5543 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
5544 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
5545 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
5546 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
5547 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0)<cr>
5548 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
5549 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
5550 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5551 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
5552 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
5553 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr>
5554 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
5555 nnoremap <buffer> <silent> C :let g:netrw_chgwin= winnr()<cr>
5556 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr>
5557 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
5558 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr>
5559 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr>
5560 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5561 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr>
5562 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5563 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5564 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
5565 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
5566 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>
5567 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr>
5568 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
5569 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr>
5570 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5571 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5572 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
5573 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
5574 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr>
5575 nnoremap <buffer> <silent> x :call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
5576 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr>
5577 " remote insert-mode maps
5578 inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
5579 inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5580 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(0)<cr>
5581 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(0)<cr>
5582 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr>
5583 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5584 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
5585 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
5586 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
5587 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5588 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
5589 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
5590 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr>
5591 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
5592 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
5593 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr>
5594 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
5595 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr>
5596 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr>
5597 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0)<cr>
5598 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
5599 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
5600 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5601 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr>
5602 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
5603 inoremap <buffer> <silent> C <c-o>:let g:netrw_chgwin= winnr()<cr>
5604 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr>
5605 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
5606 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr>
5607 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr>
5608 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5609 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
5610 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5611 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5612 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
5613 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
5614 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>
5615 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr>
5616 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr>
5617 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr>
5618 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5619 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5620 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
5621 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
5622 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr>
5623 inoremap <buffer> <silent> x <c-o>:call netrw#NetrwBrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
5624 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr>
5625 if !hasmapto('<Plug>NetrwHideEdit')
5626 nmap <buffer> <c-h> <Plug>NetrwHideEdit
5627 imap <buffer> <c-h> <Plug>NetrwHideEdit
5628 endif
5629 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
5630 if !hasmapto('<Plug>NetrwRefresh')
5631 nmap <buffer> <c-l> <Plug>NetrwRefresh
5632 imap <buffer> <c-l> <Plug>NetrwRefresh
5633 endif
5634
5635 let mapsafepath = escape(s:path, s:netrw_map_escape)
5636 let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape)
5637
5638 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
5639 if g:netrw_mousemaps == 1
5640 nmap <leftmouse> <Plug>NetrwLeftmouse
5641 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
5642 nmap <buffer> <leftdrag> <Plug>NetrwLeftdrag
5643 nno <buffer> <silent> <Plug>NetrwLeftdrag :call <SID>NetrwLeftdrag(0)<cr>
5644 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
5645 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
5646 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
5647 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
5648 nmap <middlemouse> <Plug>NetrwMiddlemouse
5649 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
5650 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
5651 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
5652 imap <buffer> <leftmouse> <Plug>ILeftmouse
5653 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr>
5654 imap <buffer> <middlemouse> <Plug>IMiddlemouse
5655 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
5656 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
5657 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
5658 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5659 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5660 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5661 endif
5662 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5663 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
5664 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5665 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5666 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5667 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5668 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5669 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5670 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
5671 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5672 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
5673 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
5674 inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr>
5675 endif
5676
5677 keepj call s:SetRexDir(a:islocal,b:netrw_curdir)
5678
5679" call Dret("s:NetrwMaps")
5680endfun
5681
5682" ---------------------------------------------------------------------
5683" s:NetrwCommands: sets up commands available only in the netrw buffer windows {{{2
5684fun! s:NetrwCommands(islocal)
5685" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
5686
5687 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
5688 if a:islocal
5689 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
5690 else
5691 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
5692 endif
5693 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
5694
5695" call Dret("s:NetrwCommands")
5696endfun
5697
5698" ---------------------------------------------------------------------
5699" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
5700" glob()ing only works with local files
5701fun! s:NetrwMarkFiles(islocal,...)
5702" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
5703 let i = 1
5704 while i <= a:0
5705 if a:islocal
5706 let mffiles= glob(a:{i},0,1)
5707 else
5708 let mffiles= [a:{i}]
5709 endif
5710" call Decho("mffiles".string(mffiles))
5711 for mffile in mffiles
5712" call Decho("mffile<".mffile.">")
5713 call s:NetrwMarkFile(a:islocal,mffile)
5714 endfor
5715 let i= i + 1
5716 endwhile
5717" call Dret("s:NetrwMarkFiles")
5718endfun
5719
5720" ---------------------------------------------------------------------
5721" s:NetrwMarkTarget: {{{2
5722fun! s:NetrwMarkTarget(...)
5723" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
5724 if a:0 == 0 || (a:0 == 1 && a:1 == "")
5725 let tgt= b:netrw_curdir
5726 else
5727 let tgt= a:1
5728 endif
5729" call Decho("tgt<".tgt.">")
5730 let s:netrwmftgt = tgt
5731 let s:netrwmftgt_islocal = tgt !~ '^\a\+://'
5732 let curislocal = b:netrw_curdir !~ '^\a\+://'
5733 let svpos = netrw#SavePosn()
5734 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
5735 call netrw#RestorePosn(svpos)
5736" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005737endfun
5738
5739" ---------------------------------------------------------------------
5740" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
5741" mark and unmark files. If a markfile list exists,
5742" then the rename and delete functions will use it instead
5743" of whatever may happen to be under the cursor at that
5744" moment. When the mouse and gui are available,
5745" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00005746"
5747" Creates two lists
5748" s:netrwmarkfilelist -- holds complete paths to all marked files
5749" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
5750"
5751" Creates a marked file match string
5752" s:netrwmarfilemtch_# -- used with 2match to display marked files
5753"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005754" Creates a buffer version of islocal
5755" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00005756fun! s:NetrwMarkFile(islocal,fname)
5757" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +02005758
5759 " sanity check
5760 if empty(a:fname)
5761" call Dret("s:NetrwMarkFile : emtpy fname")
5762 return
5763 endif
5764
Bram Moolenaar97d62492012-11-15 21:28:22 +01005765 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005766 let curbufnr= bufnr("%")
5767 let curdir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01005768 if a:fname =~ '^\a'
5769 let leader= '\<'
5770 else
5771 let leader= ''
5772 endif
5773 if a:fname =~ '\a$'
5774 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
5775 else
5776 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
5777 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005778
Bram Moolenaar446cb832008-06-24 21:56:24 +00005779 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005780 " markfile list pre-exists
Bram Moolenaar446cb832008-06-24 21:56:24 +00005781" call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
5782" call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">")
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005783 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00005784
5785 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005786 " append filename to buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00005787" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
5788 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01005789 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005790
5791 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00005792 " remove filename from buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00005793" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
5794 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
5795 if s:netrwmarkfilelist_{curbufnr} == []
5796 " local markfilelist is empty; remove it entirely
Bram Moolenaar5c736222010-01-06 20:54:52 +01005797" call Decho("markfile list now empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005798 call s:NetrwUnmarkList(curbufnr,curdir)
5799 else
5800 " rebuild match list to display markings correctly
5801" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr)
5802 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01005803 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804 for fname in s:netrwmarkfilelist_{curbufnr}
5805 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01005806 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005807 else
Bram Moolenaara6878372014-03-22 21:02:50 +01005808 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005809 endif
5810 let first= 0
5811 endfor
Bram Moolenaar15146672011-10-20 22:22:38 +02005812" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005813 endif
5814 endif
5815
5816 else
5817 " initialize new markfilelist
5818
5819" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr)
5820 let s:netrwmarkfilelist_{curbufnr}= []
5821 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
5822" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
5823
5824 " build initial markfile matching pattern
5825 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01005826 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005827 else
Bram Moolenaara6878372014-03-22 21:02:50 +01005828 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005829 endif
5830" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
5831 endif
5832
5833 " handle global markfilelist
5834 if exists("s:netrwmarkfilelist")
5835 let dname= s:ComposePath(b:netrw_curdir,a:fname)
5836 if index(s:netrwmarkfilelist,dname) == -1
5837 " append new filename to global markfilelist
5838 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
5839" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">")
5840 else
5841 " remove new filename from global markfilelist
5842" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")")
5843 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
5844" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">")
5845 if s:netrwmarkfilelist == []
5846 unlet s:netrwmarkfilelist
5847 endif
5848 endif
5849 else
5850 " initialize new global-directory markfilelist
5851 let s:netrwmarkfilelist= []
5852 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
5853" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">")
5854 endif
5855
5856 " set up 2match'ing to netrwmarkfilemtch list
5857 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
5858" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005859 if exists("g:did_drchip_netrwlist_syntax")
5860 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
5861 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862 else
5863" call Decho("2match none")
5864 2match none
5865 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005866 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005867" 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 +00005868endfun
5869
5870" ---------------------------------------------------------------------
5871" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
5872" compress/decompress files using the programs
5873" in g:netrw_compress and g:netrw_uncompress,
5874" using g:netrw_compress_suffix to know which to
5875" do. By default:
5876" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005877" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005878fun! s:NetrwMarkFileCompress(islocal)
5879" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01005880 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005881 let curdir = b:netrw_curdir
5882 let curbufnr = bufnr("%")
5883
Bram Moolenaarff034192013-04-24 18:51:19 +02005884 " sanity check
5885 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
5886 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
5887" call Dret("s:NetrwMarkFileCompress")
5888 return
5889 endif
5890" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
5891
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02005893
5894 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02005896 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
5897" call Decho("extracted sfx<".sfx.">")
5898 if exists("g:netrw_decompress['".sfx."']")
5899 " fname has a suffix indicating that its compressed; apply associated decompression routine
5900 let exe= g:netrw_decompress[sfx]
5901" call Decho("fname<".fname."> is compressed so decompress with <".exe.">")
5902 let exe= netrw#WinPath(exe)
5903 if a:islocal
5904 if g:netrw_keepdir
5905 let fname= shellescape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005906 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005907 else
5908 let fname= shellescape(b:netrw_curdir.fname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005910 if executable(exe)
5911 if a:islocal
5912 call system(exe." ".fname)
5913 else
5914 keepj call s:RemoteSystem(exe." ".fname)
5915 endif
5916 else
5917 keepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
5918 endif
5919 endif
5920 unlet sfx
5921
Bram Moolenaar446cb832008-06-24 21:56:24 +00005922 if exists("exe")
5923 unlet exe
5924 elseif a:islocal
5925 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01005926 call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927 else
5928 " fname not a compressed file, so compress it
Bram Moolenaaradc21822011-04-01 18:03:16 +02005929 keepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005931 endfor " for every file in the marked list
5932
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005934 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005935 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936 endif
5937" call Dret("s:NetrwMarkFileCompress")
5938endfun
5939
5940" ---------------------------------------------------------------------
5941" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
5942" If no marked files, then set up directory as the
5943" target. Currently does not support copying entire
5944" directories. Uses the local-buffer marked file list.
5945" Returns 1=success (used by NetrwMarkFileMove())
5946" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02005947fun! s:NetrwMarkFileCopy(islocal,...)
5948" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
5949
5950 if !exists("b:netrw_curdir")
5951 let b:netrw_curdir= getcwd()
5952" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
5953 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005954 let curdir = b:netrw_curdir
5955 let curbufnr = bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956
Bram Moolenaarff034192013-04-24 18:51:19 +02005957 " sanity check
5958 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
5959 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
5960" call Dret("s:NetrwMarkFileCopy")
5961 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00005962 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005963" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
5964
Bram Moolenaar446cb832008-06-24 21:56:24 +00005965 if !exists("s:netrwmftgt")
Bram Moolenaar251e1912011-06-19 05:09:16 +02005966 keepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967" call Dret("s:NetrwMarkFileCopy 0")
5968 return 0
5969 endif
5970" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971
5972 if a:islocal && s:netrwmftgt_islocal
5973 " Copy marked files, local directory to local directory
5974" call Decho("copy from local to local")
Bram Moolenaarff034192013-04-24 18:51:19 +02005975 if !executable(g:netrw_localcopycmd) && g:netrw_localcopycmd !~ '\<cmd\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
5977" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
5978 return
5979 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02005980
5981 " copy marked files while within the same directory (ie. allow renaming)
5982 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
5983 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
5984 " only one marked file
5985 let args = shellescape(b:netrw_curdir."/".s:netrwmarkfilelist_{bufnr('%')}[0])
5986 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
5987 elseif a:0 == 1
5988 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
5989 let args = shellescape(b:netrw_curdir."/".a:1)
5990 let oldname = a:1
5991 else
5992 " copy multiple marked files inside the same directory
5993 let s:recursive= 1
5994 for oldname in s:netrwmarkfilelist_{bufnr("%")}
5995 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
5996 if ret == 0
5997 break
5998 endif
5999 endfor
6000 unlet s:recursive
6001 call s:NetrwUnmarkList(curbufnr,curdir)
6002" call Dret("s:NetrwMarkFileCopy ".ret)
6003 return ret
6004 endif
6005
6006 call inputsave()
6007 let newname= input("Copy ".oldname." to : ",oldname,"file")
6008 call inputrestore()
6009 if newname == ""
6010" call Dret("s:NetrwMarkFileCopy 0")
6011 return 0
6012 endif
6013 let args= shellescape(oldname)
6014 let tgt = shellescape(s:netrwmftgt.'/'.newname)
6015 else
6016 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)"))
6017 let tgt = shellescape(s:netrwmftgt)
6018 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006019 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6020 let args= substitute(args,'/','\\','g')
6021 let tgt = substitute(tgt, '/','\\','g')
6022 endif
6023 if g:netrw_localcopycmd =~ '\s'
6024 let copycmd = substitute(g:netrw_localcopycmd,'\s.*$','','')
6025 let copycmdargs = substitute(g:netrw_localcopycmd,'^.\{-}\(\s.*\)$','\1','')
6026 let copycmd = netrw#WinPath(copycmd).copycmdargs
6027 else
6028 let copycmd = netrw#WinPath(g:netrw_localcopycmd)
6029 endif
6030" call Decho("args <".args.">")
6031" call Decho("tgt <".tgt.">")
6032" call Decho("copycmd<".copycmd.">")
6033" call Decho("system(".copycmd." ".args." ".tgt.")")
6034 call system(copycmd." ".args." ".tgt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006035 if v:shell_error != 0
Bram Moolenaarff034192013-04-24 18:51:19 +02006036 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 +01006037" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt))
6038 return 0
6039 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040
6041 elseif a:islocal && !s:netrwmftgt_islocal
6042 " Copy marked files, local directory to remote directory
6043" call Decho("copy from local to remote")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006044 keepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045
6046 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006047 " Copy marked files, remote directory to local directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048" call Decho("copy from remote to local")
Bram Moolenaara6878372014-03-22 21:02:50 +01006049 keepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006050
6051 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006052 " Copy marked files, remote directory to remote directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006053" call Decho("copy from remote to remote")
6054 let curdir = getcwd()
6055 let tmpdir = s:GetTempfile("")
6056 if tmpdir !~ '/'
6057 let tmpdir= curdir."/".tmpdir
6058 endif
6059 if exists("*mkdir")
6060 call mkdir(tmpdir)
6061 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006062 exe "sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006063 if v:shell_error != 0
6064 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
6065" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1) )
6066 return
6067 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006068 endif
6069 if isdirectory(tmpdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01006070 call s:NetrwLcd(tmpdir)
6071 keepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006072 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaaradc21822011-04-01 18:03:16 +02006073 keepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006074 if getcwd() == tmpdir
6075 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006076 keepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006077 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +01006078 call s:NetrwLcd(curdir)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02006079 exe "sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006080 if v:shell_error != 0
6081 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
6082" call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1) )
6083 return
6084 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006085 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006086 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006087 endif
6088 endif
6089 endif
6090
6091 " -------
6092 " cleanup
6093 " -------
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006094" call Decho("cleanup")
6095 if !exists("s:recursive")
6096 " remove markings from local buffer
6097 call s:NetrwUnmarkList(curbufnr,curdir)
6098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006099
6100 " refresh buffers
6101 if !s:netrwmftgt_islocal
6102 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6103 endif
6104 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006105 keepj call s:NetrwRefreshDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006106 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006107 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006108 keepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006109 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006110
6111" call Dret("s:NetrwMarkFileCopy 1")
6112 return 1
6113endfun
6114
6115" ---------------------------------------------------------------------
6116" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6117" invoke vim's diff mode on the marked files.
6118" Either two or three files can be so handled.
6119" Uses the global marked file list.
6120fun! s:NetrwMarkFileDiff(islocal)
6121" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6122 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006123
Bram Moolenaarff034192013-04-24 18:51:19 +02006124 " sanity check
6125 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6126 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6127" call Dret("s:NetrwMarkFileDiff")
6128 return
6129 endif
6130" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6131
Bram Moolenaara6878372014-03-22 21:02:50 +01006132 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006133 let cnt = 0
6134 let curdir = b:netrw_curdir
6135 for fname in s:netrwmarkfilelist
6136 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006137 if cnt == 1
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006138" call Decho("diffthis: fname<".fname.">")
6139 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006140 diffthis
6141 elseif cnt == 2 || cnt == 3
6142 vsplit
6143 wincmd l
6144" call Decho("diffthis: ".fname)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006145 exe "e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006146 diffthis
6147 else
6148 break
6149 endif
6150 endfor
6151 call s:NetrwUnmarkList(curbufnr,curdir)
6152 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006153
Bram Moolenaar446cb832008-06-24 21:56:24 +00006154" call Dret("s:NetrwMarkFileDiff")
6155endfun
6156
6157" ---------------------------------------------------------------------
6158" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6159" Uses global markfilelist
6160fun! s:NetrwMarkFileEdit(islocal)
6161" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6162
6163 let curdir = b:netrw_curdir
6164 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006165
6166 " sanity check
6167 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6168 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6169" call Dret("s:NetrwMarkFileEdit")
6170 return
6171 endif
6172" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6173
Bram Moolenaar446cb832008-06-24 21:56:24 +00006174 if exists("s:netrwmarkfilelist_{curbufnr}")
6175 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006176 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006177 " unmark markedfile list
6178" call s:NetrwUnmarkList(curbufnr,curdir)
6179 call s:NetrwUnmarkAll()
Bram Moolenaaradc21822011-04-01 18:03:16 +02006180" call Decho("exe sil args ".flist)
6181 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006183 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006184
6185" call Dret("s:NetrwMarkFileEdit")
6186endfun
6187
6188" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02006189" s:NetrwMarkFileQFEL: convert a quickfix-error list into a marked file list {{{2
6190fun! s:NetrwMarkFileQFEL(islocal,qfel)
6191" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6192 call s:NetrwUnmarkAll()
6193 let curbufnr= bufnr("%")
6194
6195 if !empty(a:qfel)
6196 for entry in a:qfel
6197 let bufnmbr= entry["bufnr"]
6198" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"])
6199 if !exists("s:netrwmarkfilelist_{curbufnr}")
6200" call Decho("case: no marked file list")
6201 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6202 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6203 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6204 " So, this test lets two or more hits on the same pattern to be ignored.
6205" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list")
6206 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6207 else
6208" call Decho("case: ".bufname(bufnmbr)." already in marked file list")
6209 endif
6210 endfor
6211 echo "(use me to edit marked files)"
6212 else
6213 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6214 endif
6215
6216" call Dret("s:NetrwMarkFileQFEL")
6217endfun
6218
6219" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02006220" s:NetrwMarkFileExe: (invoked by mx) execute arbitrary system command on marked files, one at a time {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221" Uses the local marked-file list.
6222fun! s:NetrwMarkFileExe(islocal)
6223" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006224 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006225 let curdir = b:netrw_curdir
6226 let curbufnr = bufnr("%")
6227
Bram Moolenaarff034192013-04-24 18:51:19 +02006228 " sanity check
6229 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6230 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6231" call Dret("s:NetrwMarkFileExe")
6232 return
6233 endif
6234" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6235
Bram Moolenaar446cb832008-06-24 21:56:24 +00006236 if exists("s:netrwmarkfilelist_{curbufnr}")
6237 " get the command
6238 call inputsave()
6239 let cmd= input("Enter command: ","","file")
6240 call inputrestore()
6241" call Decho("cmd<".cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02006242 if cmd == ""
6243" " call Dret("s:NetrwMarkFileExe : early exit, empty command")
6244 return
6245 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006246
6247 " apply command to marked files. Substitute: filename -> %
6248 " If no %, then append a space and the filename to the command
6249 for fname in s:netrwmarkfilelist_{curbufnr}
6250 if a:islocal
6251 if g:netrw_keepdir
Bram Moolenaar5c736222010-01-06 20:54:52 +01006252 let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006253 endif
6254 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01006255 let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 endif
6257 if cmd =~ '%'
6258 let xcmd= substitute(cmd,'%',fname,'g')
6259 else
6260 let xcmd= cmd.' '.fname
6261 endif
6262 if a:islocal
6263" call Decho("local: xcmd<".xcmd.">")
6264 let ret= system(xcmd)
6265 else
6266" call Decho("remote: xcmd<".xcmd.">")
6267 let ret= s:RemoteSystem(xcmd)
6268 endif
6269 if v:shell_error < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02006270 keepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271 break
6272 else
6273 echo ret
6274 endif
6275 endfor
6276
6277 " unmark marked file list
6278 call s:NetrwUnmarkList(curbufnr,curdir)
6279
6280 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02006281 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006282 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006284 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 endif
6286
6287" call Dret("s:NetrwMarkFileExe")
6288endfun
6289
6290" ---------------------------------------------------------------------
6291" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6292" as the marked file(s) (toggles suffix presence)
6293" Uses the local marked file list.
6294fun! s:NetrwMarkHideSfx(islocal)
6295" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006296 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297 let curbufnr = bufnr("%")
6298
6299 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6300 if exists("s:netrwmarkfilelist_{curbufnr}")
6301
6302 for fname in s:netrwmarkfilelist_{curbufnr}
6303" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6304 " construct suffix pattern
6305 if fname =~ '\.'
6306 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6307 else
6308 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6309 endif
6310 " determine if its in the hiding list or not
6311 let inhidelist= 0
6312 if g:netrw_list_hide != ""
6313 let itemnum = 0
6314 let hidelist= split(g:netrw_list_hide,',')
6315 for hidepat in hidelist
6316 if sfxpat == hidepat
6317 let inhidelist= 1
6318 break
6319 endif
6320 let itemnum= itemnum + 1
6321 endfor
6322 endif
6323" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6324 if inhidelist
6325 " remove sfxpat from list
6326 call remove(hidelist,itemnum)
6327 let g:netrw_list_hide= join(hidelist,",")
6328 elseif g:netrw_list_hide != ""
6329 " append sfxpat to non-empty list
6330 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6331 else
6332 " set hiding list to sfxpat
6333 let g:netrw_list_hide= sfxpat
6334 endif
6335 endfor
6336
6337 " refresh the listing
Bram Moolenaaradc21822011-04-01 18:03:16 +02006338 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006339 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02006341 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 endif
6343
6344" call Dret("s:NetrwMarkHideSfx")
6345endfun
6346
6347" ---------------------------------------------------------------------
Bram Moolenaar15146672011-10-20 22:22:38 +02006348" s:NetrwMarkFileVimCmd: (invoked by mX) execute arbitrary vim command on marked files, one at a time {{{2
6349" Uses the local marked-file list.
6350fun! s:NetrwMarkFileVimCmd(islocal)
6351" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006352 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006353 let curdir = b:netrw_curdir
6354 let curbufnr = bufnr("%")
6355
Bram Moolenaarff034192013-04-24 18:51:19 +02006356 " sanity check
6357 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6358 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6359" call Dret("s:NetrwMarkFileVimCmd")
6360 return
6361 endif
6362" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6363
Bram Moolenaar15146672011-10-20 22:22:38 +02006364 if exists("s:netrwmarkfilelist_{curbufnr}")
6365 " get the command
6366 call inputsave()
6367 let cmd= input("Enter vim command: ","","file")
6368 call inputrestore()
6369" call Decho("cmd<".cmd.">")
6370 if cmd == ""
6371" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
6372 return
6373 endif
6374
6375 " apply command to marked files. Substitute: filename -> %
6376 " If no %, then append a space and the filename to the command
6377 for fname in s:netrwmarkfilelist_{curbufnr}
6378" call Decho("fname<".fname.">")
6379 if a:islocal
6380 1split
6381 exe "sil! keepalt e ".fnameescape(fname)
6382" call Decho("local<".fname.">: exe ".cmd)
6383 exe cmd
6384 exe "sil! keepalt wq!"
6385 else
Bram Moolenaar15146672011-10-20 22:22:38 +02006386" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET")
6387 echo "sorry, \"mX\" not supported yet for remote files"
6388 endif
6389 endfor
6390
6391 " unmark marked file list
6392 call s:NetrwUnmarkList(curbufnr,curdir)
6393
6394 " refresh the listing
6395 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006396 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02006397 else
6398 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
6399 endif
6400
6401" call Dret("s:NetrwMarkFileVimCmd")
6402endfun
6403
6404" ---------------------------------------------------------------------
6405" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6406" as the marked file(s) (toggles suffix presence)
6407" Uses the local marked file list.
6408fun! s:NetrwMarkHideSfx(islocal)
6409" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006411 let curbufnr = bufnr("%")
6412
6413 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6414 if exists("s:netrwmarkfilelist_{curbufnr}")
6415
6416 for fname in s:netrwmarkfilelist_{curbufnr}
6417" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6418 " construct suffix pattern
6419 if fname =~ '\.'
6420 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6421 else
6422 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6423 endif
6424 " determine if its in the hiding list or not
6425 let inhidelist= 0
6426 if g:netrw_list_hide != ""
6427 let itemnum = 0
6428 let hidelist= split(g:netrw_list_hide,',')
6429 for hidepat in hidelist
6430 if sfxpat == hidepat
6431 let inhidelist= 1
6432 break
6433 endif
6434 let itemnum= itemnum + 1
6435 endfor
6436 endif
6437" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6438 if inhidelist
6439 " remove sfxpat from list
6440 call remove(hidelist,itemnum)
6441 let g:netrw_list_hide= join(hidelist,",")
6442 elseif g:netrw_list_hide != ""
6443 " append sfxpat to non-empty list
6444 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6445 else
6446 " set hiding list to sfxpat
6447 let g:netrw_list_hide= sfxpat
6448 endif
6449 endfor
6450
6451 " refresh the listing
6452 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006453 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02006454 else
6455 keepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
6456 endif
6457
6458" call Dret("s:NetrwMarkHideSfx")
6459endfun
6460
6461" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006462" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
6463" Uses the global markfilelist
6464fun! s:NetrwMarkFileGrep(islocal)
6465" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006466 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006467 let curbufnr = bufnr("%")
6468
6469 if exists("s:netrwmarkfilelist")
6470" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006471 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006472 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02006473 else
6474" call Decho('no marked files, using "*"')
6475 let netrwmarkfilelist= "*"
6476 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006477
Bram Moolenaarff034192013-04-24 18:51:19 +02006478 " ask user for pattern
6479 call inputsave()
6480 let pat= input("Enter pattern: ","")
6481 call inputrestore()
6482 let patbang = ""
6483 if pat =~ '^!'
6484 let patbang = "!"
6485 let pat= strpart(pat,2)
6486 endif
6487 if pat =~ '^\i'
6488 let pat = escape(pat,'/')
6489 let pat = '/'.pat.'/'
6490 else
6491 let nonisi = pat[0]
6492 endif
6493
6494 " use vimgrep for both local and remote
6495" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist)
6496 try
6497 exe "keepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
6498 catch /^Vim\%((\a\+)\)\=:E480/
6499 keepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
6500" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
6501 return
6502 endtry
6503 echo "(use :cn, :cp to navigate, :Rex to return)"
6504
6505 2match none
Bram Moolenaara6878372014-03-22 21:02:50 +01006506 keepj call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02006507
6508 if exists("nonisi")
6509 " original, user-supplied pattern did not begin with a character from isident
6510" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg")
6511 if pat =~ nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
6512 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00006513 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006514 endif
6515
6516" call Dret("s:NetrwMarkFileGrep")
6517endfun
6518
6519" ---------------------------------------------------------------------
6520" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
6521" uses the global marked file list
6522" s:netrwmfloc= 0: target directory is remote
6523" = 1: target directory is local
6524fun! s:NetrwMarkFileMove(islocal)
6525" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
6526 let curdir = b:netrw_curdir
6527 let curbufnr = bufnr("%")
6528
6529 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02006530 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaaradc21822011-04-01 18:03:16 +02006531 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006532" call Dret("s:NetrwMarkFileMove")
6533 return
6534 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006535" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6536
Bram Moolenaar446cb832008-06-24 21:56:24 +00006537 if !exists("s:netrwmftgt")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006538 keepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006539" call Dret("s:NetrwMarkFileCopy 0")
6540 return 0
6541 endif
6542" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
6543
6544 if a:islocal && s:netrwmftgt_islocal
6545 " move: local -> local
6546" call Decho("move from local to local")
Bram Moolenaara6878372014-03-22 21:02:50 +01006547" call Decho("local to local move")
Bram Moolenaarff034192013-04-24 18:51:19 +02006548 if !executable(g:netrw_localmovecmd) && g:netrw_localmovecmd !~ '\<cmd\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01006549 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
6550" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
6551 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006552 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006553 let tgt = shellescape(s:netrwmftgt)
6554" call Decho("tgt<".tgt.">")
6555 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6556 let tgt = substitute(tgt, '/','\\','g')
6557" call Decho("windows exception: tgt<".tgt.">")
6558 if g:netrw_localmovecmd =~ '\s'
6559 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
6560 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
6561 let movecmd = netrw#WinPath(movecmd).movecmdargs
6562" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)")
6563 else
6564 let movecmd = netrw#WinPath(movecmd)
6565" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)")
6566 endif
6567 else
6568 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
6569" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)")
6570 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006571 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02006572" call Decho("system(".movecmd." ".shellescape(fname)." ".tgt.")")
6573 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6574 let fname= substitute(fname,'/','\\','g')
6575 endif
6576 let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".tgt)
6577 if v:shell_error != 0
6578 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 +01006579 break
6580 endif
6581 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006582
6583 elseif a:islocal && !s:netrwmftgt_islocal
6584 " move: local -> remote
6585" call Decho("move from local to remote")
6586" call Decho("copy")
6587 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006588 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006589" call Decho("remove")
6590 for fname in mflist
6591 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6592 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
6593 endfor
6594 unlet mflist
6595
6596 elseif !a:islocal && s:netrwmftgt_islocal
6597 " move: remote -> local
6598" call Decho("move from remote to local")
6599" call Decho("copy")
6600 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006601 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006602" call Decho("remove")
6603 for fname in mflist
6604 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6605 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
6606 endfor
6607 unlet mflist
6608
6609 elseif !a:islocal && !s:netrwmftgt_islocal
6610 " move: remote -> remote
6611" call Decho("move from remote to remote")
6612" call Decho("copy")
6613 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaaradc21822011-04-01 18:03:16 +02006614 keepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006615" call Decho("remove")
6616 for fname in mflist
6617 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
6618 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
6619 endfor
6620 unlet mflist
6621 endif
6622
6623 " -------
6624 " cleanup
6625 " -------
6626" call Decho("cleanup")
6627
6628 " remove markings from local buffer
6629 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
6630
6631 " refresh buffers
6632 if !s:netrwmftgt_islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006633" call Decho("refresh netrwmftgt<".s:netrwmftgt.">")
6634 keepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006635 endif
6636 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02006637" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">")
6638 keepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006639 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006640 if g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02006641" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh")
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 keepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006643 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006644
6645" call Dret("s:NetrwMarkFileMove")
6646endfun
6647
6648" ---------------------------------------------------------------------
6649" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
6650" using the hardcopy command. Local marked-file list only.
6651fun! s:NetrwMarkFilePrint(islocal)
6652" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
6653 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006654
6655 " sanity check
6656 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6657 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6658" call Dret("s:NetrwMarkFilePrint")
6659 return
6660 endif
6661" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006662 if exists("s:netrwmarkfilelist_{curbufnr}")
6663 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
6664 let curdir = b:netrw_curdir
6665 call s:NetrwUnmarkList(curbufnr,curdir)
6666 for fname in netrwmarkfilelist
6667 if a:islocal
6668 if g:netrw_keepdir
6669 let fname= s:ComposePath(curdir,fname)
6670 endif
6671 else
6672 let fname= curdir.fname
6673 endif
6674 1split
6675 " the autocmds will handle both local and remote files
Bram Moolenaaradc21822011-04-01 18:03:16 +02006676" call Decho("exe sil e ".escape(fname,' '))
6677 exe "sil e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006678" call Decho("hardcopy")
6679 hardcopy
6680 q
6681 endfor
6682 2match none
6683 endif
6684" call Dret("s:NetrwMarkFilePrint")
6685endfun
6686
6687" ---------------------------------------------------------------------
6688" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
6689" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02006690" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00006691fun! s:NetrwMarkFileRegexp(islocal)
6692" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
6693
6694 " get the regular expression
6695 call inputsave()
6696 let regexp= input("Enter regexp: ","","file")
6697 call inputrestore()
6698
6699 if a:islocal
6700 " get the matching list of files using local glob()
6701" call Decho("handle local regexp")
Bram Moolenaarff034192013-04-24 18:51:19 +02006702 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
6703 let files = glob(s:ComposePath(dirname,regexp))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006704" call Decho("files<".files.">")
6705 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006706
6707 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01006708 for fname in filelist
6709" call Decho("fname<".fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006710 keepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006711 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006712
6713 else
6714" call Decho("handle remote regexp")
6715
6716 " convert displayed listing into a filelist
6717 let eikeep = &ei
6718 let areg = @a
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006719 sil keepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01006720 setl ei=all ma
6721" call Decho("setl ei=all ma")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006722 1split
Bram Moolenaaradc21822011-04-01 18:03:16 +02006723 keepj call s:NetrwEnew()
6724 keepj call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006725 sil keepj norm! "ap
6726 keepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006727 let bannercnt= search('^" =====','W')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006728 exe "sil keepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01006729 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00006730 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006731 sil keepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01006732 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006733 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006734 sil keepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01006735 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006736 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8d043172014-01-23 14:24:41 +01006737 exe 'sil keepj %s/^'.s:treedepthstring.' //e'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006738 sil! keepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01006739 call histdel("/",-1)
6740 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006741 endif
6742 " convert regexp into the more usual glob-style format
6743 let regexp= substitute(regexp,'\*','.*','g')
6744" call Decho("regexp<".regexp.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006745 exe "sil! keepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01006746 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006747 let filelist= getline(1,line("$"))
6748 q!
6749 for filename in filelist
Bram Moolenaaradc21822011-04-01 18:03:16 +02006750 keepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006751 endfor
6752 unlet filelist
6753 let @a = areg
6754 let &ei = eikeep
6755 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006756 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006757
6758" call Dret("s:NetrwMarkFileRegexp")
6759endfun
6760
6761" ---------------------------------------------------------------------
6762" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
6763" Uses the local marked file list.
6764fun! s:NetrwMarkFileSource(islocal)
6765" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
6766 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006767
6768 " sanity check
6769 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6770 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6771" call Dret("s:NetrwMarkFileSource")
6772 return
6773 endif
6774" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006775 if exists("s:netrwmarkfilelist_{curbufnr}")
6776 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
6777 let curdir = b:netrw_curdir
6778 call s:NetrwUnmarkList(curbufnr,curdir)
6779 for fname in netrwmarkfilelist
6780 if a:islocal
6781 if g:netrw_keepdir
6782 let fname= s:ComposePath(curdir,fname)
6783 endif
6784 else
6785 let fname= curdir.fname
6786 endif
6787 " the autocmds will handle sourcing both local and remote files
Bram Moolenaarc236c162008-07-13 17:41:49 +00006788" call Decho("exe so ".fnameescape(fname))
6789 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006790 endfor
6791 2match none
6792 endif
6793" call Dret("s:NetrwMarkFileSource")
6794endfun
6795
6796" ---------------------------------------------------------------------
6797" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
6798" Uses the global markfilelist
6799fun! s:NetrwMarkFileTag(islocal)
6800" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006801 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006802 let curdir = b:netrw_curdir
6803 let curbufnr = bufnr("%")
6804
Bram Moolenaarff034192013-04-24 18:51:19 +02006805 " sanity check
6806 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6807 keepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6808" call Dret("s:NetrwMarkFileTag")
6809 return
6810 endif
6811" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6812
Bram Moolenaar446cb832008-06-24 21:56:24 +00006813 if exists("s:netrwmarkfilelist")
6814" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006815 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006816 call s:NetrwUnmarkAll()
6817
6818 if a:islocal
6819 if executable(g:netrw_ctags)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006820" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")")
6821 call system(g:netrw_ctags." ".netrwmarkfilelist)
6822 else
6823 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
6824 endif
6825 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00006826 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006828 let curdir= b:netrw_curdir
6829 1split
6830 e tags
6831 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
6832" call Decho("curdir<".curdir."> path<".path.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006833 exe 'keepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01006834 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006835 wq!
6836 endif
6837 2match none
6838 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006839 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006840 endif
6841
6842" call Dret("s:NetrwMarkFileTag")
6843endfun
6844
6845" ---------------------------------------------------------------------
6846" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
6847" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02006848" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006849" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02006850" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00006851fun! s:NetrwMarkFileTgt(islocal)
6852" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006853 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 let curdir = b:netrw_curdir
6855 let hadtgt = exists("s:netrwmftgt")
6856 if !exists("w:netrw_bannercnt")
6857 let w:netrw_bannercnt= b:netrw_bannercnt
6858 endif
6859
6860 " set up target
6861 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02006862 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
6863 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
6864" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target")
6865 unlet s:netrwmftgt s:netrwmftgt_islocal
6866 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006867 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02006868 endif
6869 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006870 call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02006871" call Dret("s:NetrwMarkFileTgt : removed target")
6872 return
6873 else
6874 let s:netrwmftgt= b:netrw_curdir
6875" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">")
6876 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877
6878 else
6879 " get word under cursor.
6880 " * If directory, use it for the target.
6881 " * If file, use b:netrw_curdir for the target
6882 let curword= s:NetrwGetWord()
6883 let tgtdir = s:ComposePath(curdir,curword)
6884 if a:islocal && isdirectory(tgtdir)
6885 let s:netrwmftgt = tgtdir
6886" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">")
6887 elseif !a:islocal && tgtdir =~ '/$'
6888 let s:netrwmftgt = tgtdir
6889" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">")
6890 else
6891 let s:netrwmftgt = curdir
6892" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">")
6893 endif
6894 endif
6895 if a:islocal
6896 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
6897 let s:netrwmftgt= simplify(s:netrwmftgt)
6898" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">")
6899 endif
6900 if g:netrw_cygwin
6901 let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','')
6902 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
6903 endif
6904 let s:netrwmftgt_islocal= a:islocal
6905
Bram Moolenaar5c736222010-01-06 20:54:52 +01006906 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006907 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 endif
6909 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01006910 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 if !hadtgt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006912 sil! keepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913 endif
6914
6915" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
6916endfun
6917
6918" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00006919" s:NetrwOpenFile: query user for a filename and open it {{{2
6920fun! s:NetrwOpenFile(islocal)
6921" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006922 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00006923 call inputsave()
6924 let fname= input("Enter filename: ")
6925 call inputrestore()
6926 if fname !~ '[/\\]'
6927 if exists("b:netrw_curdir")
6928 if exists("g:netrw_quiet")
6929 let netrw_quiet_keep = g:netrw_quiet
6930 endif
6931 let g:netrw_quiet = 1
6932 if b:netrw_curdir =~ '/$'
6933 exe "e ".fnameescape(b:netrw_curdir.fname)
6934 else
6935 exe "e ".fnameescape(b:netrw_curdir."/".fname)
6936 endif
6937 if exists("netrw_quiet_keep")
6938 let g:netrw_quiet= netrw_quiet_keep
6939 else
6940 unlet g:netrw_quiet
6941 endif
6942 endif
6943 else
6944 exe "e ".fnameescape(fname)
6945 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006946 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00006947" call Dret("s:NetrwOpenFile")
6948endfun
6949
6950" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951" 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 +02006952" User access provided by the <mu> mapping. (see :help netrw-mu)
6953" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954fun! s:NetrwUnmarkList(curbufnr,curdir)
6955" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
6956
6957 " remove all files in local marked-file list from global list
6958 if exists("s:netrwmarkfilelist_{a:curbufnr}")
6959 for mfile in s:netrwmarkfilelist_{a:curbufnr}
6960 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
6961 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
6962 call remove(s:netrwmarkfilelist,idx) " remove from global list
6963 endfor
6964 if s:netrwmarkfilelist == []
6965 unlet s:netrwmarkfilelist
6966 endif
6967
6968 " getting rid of the local marked-file lists is easy
6969 unlet s:netrwmarkfilelist_{a:curbufnr}
6970 endif
6971 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
6972 unlet s:netrwmarkfilemtch_{a:curbufnr}
6973 endif
6974 2match none
6975" call Dret("s:NetrwUnmarkList")
6976endfun
6977
6978" ---------------------------------------------------------------------
6979" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
6980fun! s:NetrwUnmarkAll()
6981" call Dfunc("s:NetrwUnmarkAll()")
6982 if exists("s:netrwmarkfilelist")
6983 unlet s:netrwmarkfilelist
6984 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006985 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006986 2match none
6987" call Dret("s:NetrwUnmarkAll")
6988endfun
6989
6990" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02006991" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00006992fun! s:NetrwUnmarkAll2()
6993" call Dfunc("s:NetrwUnmarkAll2()")
6994 redir => netrwmarkfilelist_let
6995 let
6996 redir END
6997 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
6998 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
6999 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7000 for flist in netrwmarkfilelist_list
7001 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7002 unlet s:netrwmarkfilelist_{curbufnr}
7003 unlet s:netrwmarkfilemtch_{curbufnr}
7004 endfor
7005" call Dret("s:NetrwUnmarkAll2")
7006endfun
7007
7008" ---------------------------------------------------------------------
7009" s:NetrwUnMarkFile: {{{2
7010fun! s:NetrwUnMarkFile(islocal)
7011" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007012 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007013 let curbufnr = bufnr("%")
7014
7015 " unmark marked file list (although I expect s:NetrwUpload()
7016 " to do it, I'm just making sure)
7017 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7018" call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%"))
7019 unlet s:netrwmarkfilelist
7020 unlet s:netrwmarkfilelist_{curbufnr}
7021 unlet s:netrwmarkfilemtch_{curbufnr}
7022 2match none
7023 endif
7024
7025" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007026 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007027" call Dret("s:NetrwUnMarkFile")
7028endfun
7029
7030" ---------------------------------------------------------------------
7031" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7032fun! s:NetrwMenu(domenu)
7033
7034 if !exists("g:NetrwMenuPriority")
7035 let g:NetrwMenuPriority= 80
7036 endif
7037
Bram Moolenaaradc21822011-04-01 18:03:16 +02007038 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007039" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7040
7041 if !exists("s:netrw_menu_enabled") && a:domenu
7042" call Decho("initialize menu")
7043 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007044 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7045 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7046 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7047 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7048 if g:netrw_dirhistmax > 0
7049 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7050 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7051 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7052 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7053 else
7054 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7055 endif
7056 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7057 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7058 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7059 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7060 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7061 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7062 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7063 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7064 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7065 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7066 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7067 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7068 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7069 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7070 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
7071 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7072 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7073 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7074 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7075 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7076 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7077 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7078 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7079 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7080 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7081 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7082 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7083 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7084 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7085 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7086 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7087 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7088 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7089 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7090 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7091 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7092 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7093 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7094 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7095 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7096 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7097 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7098 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7099 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7100 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>'
7101 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>'
7102 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>'
7103 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7104 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>'
7105 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>'
7106 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>'
7107 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7108 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007110 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7111 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112
7113 elseif !a:domenu
7114 let s:netrwcnt = 0
7115 let curwin = winnr()
7116 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
7117 exe curwin."wincmd w"
7118
7119 if s:netrwcnt <= 1
7120" call Decho("clear menus")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007121 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaaradc21822011-04-01 18:03:16 +02007122" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007123 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007124 endif
7125 endif
7126" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007127 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128 endif
7129
7130endfun
7131
7132" ---------------------------------------------------------------------
7133" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7134" Used by the O maps (as <SID>NetrwObtain())
7135fun! s:NetrwObtain(islocal)
7136" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7137
Bram Moolenaar97d62492012-11-15 21:28:22 +01007138 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007140 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007141 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7143 else
Bram Moolenaara6878372014-03-22 21:02:50 +01007144 call netrw#Obtain(a:islocal,expand("<cWORD>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007145 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007146 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147
7148" call Dret("NetrwObtain")
7149endfun
7150
7151" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007152" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7153" If there's only one window, then the window will first be split.
7154" Returns:
7155" choice = 0 : didn't have to choose
7156" choice = 1 : saved modified file in window first
7157" choice = 2 : didn't save modified file, opened window
7158" choice = 3 : cancel open
7159fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007160" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007161
Bram Moolenaar97d62492012-11-15 21:28:22 +01007162 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007163 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01007164 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007165
7166 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01007167 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007168 let lastwinnr = winnr("$")
7169 let curword = s:NetrwGetWord()
7170 let choice = 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01007171 let s:treedir = s:NetrwTreeDir()
Bram Moolenaara6878372014-03-22 21:02:50 +01007172 let curdir = s:treedir
7173" call Decho("winnr($)#".lastwinnr." curword<".curword.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007174
Bram Moolenaar8d043172014-01-23 14:24:41 +01007175 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007176 if lastwinnr == 1
7177 " if only one window, open a new one first
Bram Moolenaara6878372014-03-22 21:02:50 +01007178" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007179 if g:netrw_preview
Bram Moolenaar15146672011-10-20 22:22:38 +02007180 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007181" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007182 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007183 else
Bram Moolenaar15146672011-10-20 22:22:38 +02007184 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007185" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007186 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007187 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007188 let didsplit = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007189" call Decho("did split")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007190
7191 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007192 keepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007193 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01007194 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00007195 wincmd p
Bram Moolenaara6878372014-03-22 21:02:50 +01007196" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007197
7198 " prevwinnr: the window number of the "prev" window
7199 " prevbufnr: the buffer number of the buffer in the "prev" window
7200 " bnrcnt : the qty of windows open on the "prev" buffer
7201 let prevwinnr = winnr()
7202 let prevbufnr = bufnr("%")
7203 let prevbufname = bufname("%")
7204 let prevmod = &mod
7205 let bnrcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02007206 keepj call s:RestoreBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01007207" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007208
7209 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00007210 " and it doesn't appear in any other extant window, then ask the
7211 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01007212 if prevmod
Bram Moolenaara6878372014-03-22 21:02:50 +01007213" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01007214 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01007215" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007216 exe prevwinnr."wincmd w"
7217
7218 if bnrcnt == 1 && &hidden == 0
7219 " only one copy of the modified buffer in a window, and
7220 " hidden not set, so overwriting will lose the modified file. Ask first...
7221 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
7222" call Decho("(NetrwPrevWinOpen) prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr())
7223 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224
7225 if choice == 1
7226 " Yes -- write file & then browse
7227 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007228 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00007229 if v:errmsg != ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01007230 call netrw#ErrorMsg(s:ERROR,"unable to write <".prevbufname.">!",30)
7231 exe origwin."wincmd w"
7232 let &ei = eikeep
7233 let @@ = ykeep
7234" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007235 return choice
7236 endif
7237
7238 elseif choice == 2
7239 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara6878372014-03-22 21:02:50 +01007240" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007241 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 else
7244 " Cancel -- don't do this
Bram Moolenaara6878372014-03-22 21:02:50 +01007245" call Decho("cancel, don't browse, switch to win#".origwin)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007246 exe origwin."wincmd w"
7247 let &ei= eikeep
7248 let @@ = ykeep
7249" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250 return choice
7251 endif
7252 endif
7253 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007254 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255 endif
7256
7257 " restore b:netrw_curdir (window split/enew may have lost it)
7258 let b:netrw_curdir= curdir
7259 if a:islocal < 2
7260 if a:islocal
7261 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
7262 else
7263 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
7264 endif
7265 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007266 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01007267" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268 return choice
7269endfun
7270
7271" ---------------------------------------------------------------------
7272" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
7273" Always assumed to be local -> remote
7274" call s:NetrwUpload(filename, target)
7275" call s:NetrwUpload(filename, target, fromdirectory)
7276fun! s:NetrwUpload(fname,tgt,...)
7277" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
7278
7279 if a:tgt =~ '^\a\+://'
7280 let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','')
7281 else
7282 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
7283 endif
7284" call Decho("tgtdir<".tgtdir.">")
7285
7286 if a:0 > 0
7287 let fromdir= a:1
7288 else
7289 let fromdir= getcwd()
7290 endif
7291" call Decho("fromdir<".fromdir.">")
7292
7293 if type(a:fname) == 1
7294 " handle uploading a single file using NetWrite
7295" call Decho("handle uploading a single file via NetWrite")
7296 1split
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007297" call Decho("exe e ".fnameescape(a:fname))
7298 exe "e ".fnameescape(a:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007299" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines")
7300 if a:tgt =~ '/$'
7301 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00007302" call Decho("exe w! ".fnameescape(wfname))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007303 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007304 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007305" call Decho("writing local->remote: exe w ".fnameescape(a:tgt))
7306 exe "w ".fnameescape(a:tgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007307" call Decho("done writing local->remote")
7308 endif
7309 q!
7310
7311 elseif type(a:fname) == 3
7312 " handle uploading a list of files via scp
7313" call Decho("handle uploading a list of files via scp")
7314 let curdir= getcwd()
7315 if a:tgt =~ '^scp:'
Bram Moolenaara6878372014-03-22 21:02:50 +01007316 call s:NetrwLcd(fromdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007317 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
7318 let args = join(map(filelist,"shellescape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007319 if exists("g:netrw_port") && g:netrw_port != ""
7320 let useport= " ".g:netrw_scpport." ".g:netrw_port
7321 else
7322 let useport= ""
7323 endif
7324 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
7325 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00007326" call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1))
7327 exe s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1)
Bram Moolenaara6878372014-03-22 21:02:50 +01007328 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329
7330 elseif a:tgt =~ '^ftp:'
7331 call s:NetrwMethod(a:tgt)
7332
7333 if b:netrw_method == 2
7334 " handle uploading a list of files via ftp+.netrc
7335 let netrw_fname = b:netrw_fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007336 sil keepj new
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337" call Decho("filter input window#".winnr())
7338
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007339 keepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00007340" call Decho("filter input: ".getline('$'))
7341
7342 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007343 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007344" call Decho("filter input: ".getline('$'))
7345 endif
7346
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007347 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007348" call Decho("filter input: ".getline('$'))
7349
Bram Moolenaaradc21822011-04-01 18:03:16 +02007350 if tgtdir == ""
7351 let tgtdir= '/'
7352 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007353 keepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007354" call Decho("filter input: ".getline('$'))
7355
7356 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007357 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358" call Decho("filter input: ".getline('$'))
7359 endfor
7360
7361 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007362" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
7363 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 +00007364 else
7365" call Decho("filter input window#".winnr())
Bram Moolenaaradc21822011-04-01 18:03:16 +02007366" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
7367 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007368 endif
7369 " 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 +02007370 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007371 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7373 call netrw#ErrorMsg(s:ERROR,getline(1),14)
7374 else
7375 bw!|q
7376 endif
7377
7378 elseif b:netrw_method == 3
7379 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
7380 let netrw_fname= b:netrw_fname
Bram Moolenaaradc21822011-04-01 18:03:16 +02007381 keepj call s:SaveBufVars()|sil keepj new|keepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007383 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384
7385 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007386 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387" call Decho("filter input: ".getline('$'))
7388 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007389 keepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390" call Decho("filter input: ".getline('$'))
7391 endif
7392
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007393 if exists("g:netrw_uid") && g:netrw_uid != ""
7394 if exists("g:netrw_ftp") && g:netrw_ftp == 1
7395 keepj put =g:netrw_uid
7396" call Decho("filter input: ".getline('$'))
7397 if exists("s:netrw_passwd")
7398 keepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
7399 endif
7400" call Decho("filter input: ".getline('$'))
7401 elseif exists("s:netrw_passwd")
7402 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
7403" call Decho("filter input: ".getline('$'))
7404 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 endif
7406
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007407 keepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408" call Decho("filter input: ".getline('$'))
7409
7410 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007411 keepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007412" call Decho("filter input: ".getline('$'))
7413 endif
7414
7415 if exists("g:netrw_ftpextracmd")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007416 keepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417" call Decho("filter input: ".getline('$'))
7418 endif
7419
7420 for fname in a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007421 keepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007422" call Decho("filter input: ".getline('$'))
7423 endfor
7424
7425 " perform ftp:
7426 " -i : turns off interactive prompting from ftp
7427 " -n unix : DON'T use <.netrc>, even though it exists
7428 " -n win32: quit being obnoxious about password
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007429 keepj norm! 1Gdd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007430" call Decho("executing: ".s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
7431 exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00007432 " 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 +02007433 sil keepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007434 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007435 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7436 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02007437 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00007438 call netrw#ErrorMsg(s:ERROR,getline(1),15)
7439 let &debug = debugkeep
7440 let mod = 1
7441 else
7442 bw!|q
7443 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007444 elseif !exists("b:netrw_method") || b:netrw_method < 0
7445" call Dfunc("netrw#NetrwUpload : unsupported method")
7446 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007447 endif
7448 else
7449 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
7450 endif
7451 endif
7452
7453" call Dret("s:NetrwUpload")
7454endfun
7455
7456" ---------------------------------------------------------------------
7457" s:NetrwPreview: {{{2
7458fun! s:NetrwPreview(path) range
7459" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007460 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02007461 keepj call s:NetrwOptionSave("s:")
7462 keepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007463 if has("quickfix")
7464 if !isdirectory(a:path)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007465 if g:netrw_preview && !g:netrw_alto
Bram Moolenaar15146672011-10-20 22:22:38 +02007466 let pvhkeep = &pvh
7467 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
7468 let &pvh = winwidth(0) - winsz
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007469 endif
7470 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
7471 if exists("pvhkeep")
7472 let &pvh= pvhkeep
7473 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007474 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007475 keepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007476 endif
7477 elseif !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007478 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 +00007479 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007480 keepj call s:NetrwOptionRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007481 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007482" call Dret("NetrwPreview")
7483endfun
7484
7485" ---------------------------------------------------------------------
7486" s:NetrwRefresh: {{{2
7487fun! s:NetrwRefresh(islocal,dirname)
7488" call Dfunc("NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
7489 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaar97d62492012-11-15 21:28:22 +01007490 " (defunct) NetrwBrowseChgDir() may clear the display; hence a NetrwSavePosn() may not work if its placed here.
7491 " (defunct) Also, NetrwBrowseChgDir() now does a NetrwSavePosn() itself.
Bram Moolenaarff034192013-04-24 18:51:19 +02007492 setl ma noro
7493" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007494" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007495 let ykeep = @@
Bram Moolenaara6878372014-03-22 21:02:50 +01007496 let screenposn = netrw#SavePosn()
Bram Moolenaarff034192013-04-24 18:51:19 +02007497" call Decho("clearing buffer prior to refresh")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007498 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00007499 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02007500 keepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007501 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007502 keepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01007504 keepj call netrw#RestorePosn(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007505
7506 " restore file marks
7507 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
7508" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
7509 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
7510 else
7511" call Decho("2match none")
7512 2match none
7513 endif
7514
Bram Moolenaar97d62492012-11-15 21:28:22 +01007515" restore
7516 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517" call Dret("NetrwRefresh")
7518endfun
7519
7520" ---------------------------------------------------------------------
7521" s:NetrwRefreshDir: refreshes a directory by name {{{2
7522" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01007523" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007524fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007525" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007526 if g:netrw_fastbrowse == 0
7527 " slowest mode (keep buffers refreshed, local or remote)
7528" call Decho("slowest mode: keep buffers refreshed, local or remote")
7529 let tgtwin= bufwinnr(a:dirname)
7530" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin)
7531
7532 if tgtwin > 0
7533 " tgtwin is being displayed, so refresh it
7534 let curwin= winnr()
7535" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")")
7536 exe tgtwin."wincmd w"
Bram Moolenaaradc21822011-04-01 18:03:16 +02007537 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538 exe curwin."wincmd w"
7539
7540 elseif bufnr(a:dirname) > 0
7541 let bn= bufnr(a:dirname)
7542" call Decho("bd bufnr(".a:dirname.")=".bn)
Bram Moolenaaradc21822011-04-01 18:03:16 +02007543 exe "sil bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544 endif
7545
7546 elseif g:netrw_fastbrowse <= 1
7547" call Decho("medium-speed mode: refresh local buffers only")
Bram Moolenaara6878372014-03-22 21:02:50 +01007548 keepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007549 endif
7550" call Dret("s:NetrwRefreshDir")
7551endfun
7552
7553" ---------------------------------------------------------------------
7554" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
7555" What this function does is to compute a priority for the patterns
7556" in the g:netrw_sort_sequence. It applies a substitute to any
7557" "files" that satisfy each pattern, putting the priority / in
7558" front. An "*" pattern handles the default priority.
7559fun! s:NetrwSetSort()
7560" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007561 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007562 if w:netrw_liststyle == s:LONGLIST
7563 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
7564 else
7565 let seqlist = g:netrw_sort_sequence
7566 endif
7567 " sanity check -- insure that * appears somewhere
7568 if seqlist == ""
7569 let seqlist= '*'
7570 elseif seqlist !~ '\*'
7571 let seqlist= seqlist.',*'
7572 endif
7573 let priority = 1
7574 while seqlist != ""
7575 if seqlist =~ ','
7576 let seq = substitute(seqlist,',.*$','','e')
7577 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
7578 else
7579 let seq = seqlist
7580 let seqlist = ""
7581 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007582 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01007583 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007584 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01007585 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007586 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01007587 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 endif
7589" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
7590
7591 " sanity check
7592 if w:netrw_bannercnt > line("$")
7593 " apparently no files were left after a Hiding pattern was used
7594" call Dret("SetSort : no files left after hiding")
7595 return
7596 endif
7597 if seq == '*'
7598 let starpriority= spriority
7599 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007600 exe 'sil keepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007601 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 " sometimes multiple sorting patterns will match the same file or directory.
7603 " The following substitute is intended to remove the excess matches.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007604 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 +02007605 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007606 endif
7607 let priority = priority + 1
7608 endwhile
7609 if exists("starpriority")
Bram Moolenaara6878372014-03-22 21:02:50 +01007610 exe 'sil keepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02007611 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 endif
7613
7614 " Following line associated with priority -- items that satisfy a priority
7615 " pattern get prefixed by ###/ which permits easy sorting by priority.
7616 " Sometimes files can satisfy multiple priority patterns -- only the latest
7617 " priority pattern needs to be retained. So, at this point, these excess
7618 " priority prefixes need to be removed, but not directories that happen to
7619 " be just digits themselves.
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007620 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 +02007621 keepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007623
7624" call Dret("SetSort")
7625endfun
7626
Bram Moolenaarff034192013-04-24 18:51:19 +02007627" ---------------------------------------------------------------------
7628" s:NetrwSetTgt: sets the target to the specified choice index {{{2
7629" Implements [count]Tb (bookhist<b>)
7630" [count]Th (bookhist<h>)
7631" See :help netrw-qb for how to make the choice.
7632fun! s:NetrwSetTgt(bookhist,choice)
7633" call Dfunc("s:NetrwSetTgt(bookhist<".a:bookhist."> choice#".a:choice.")")
7634
7635 if a:bookhist == 'b'
7636 " supports choosing a bookmark as a target using a qb-generated list
7637 let choice= a:choice - 1
7638 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01007639 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02007640 else
7641 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
7642 endif
7643
7644 elseif a:bookhist == 'h'
7645 " supports choosing a history stack entry as a target using a qb-generated list
7646 let choice= (a:choice % g:netrw_dirhistmax) + 1
7647 if exists("g:netrw_dirhist_".choice)
7648 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01007649 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02007650 else
7651 echomsg "Sorry, history#".a:choice." not available!"
7652 endif
7653 endif
7654
7655" call Dret("s:NetrwSetTgt")
7656endfun
7657
Bram Moolenaar446cb832008-06-24 21:56:24 +00007658" =====================================================================
7659" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
7660fun! s:NetrwSortStyle(islocal)
7661" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007662 keepj call s:NetrwSaveWordPosn()
Bram Moolenaara6878372014-03-22 21:02:50 +01007663 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007664
7665 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 +02007666 keepj norm! 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02007667 keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007668 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007669
7670" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
7671endfun
7672
7673" ---------------------------------------------------------------------
7674" s:NetrwSplit: mode {{{2
7675" =0 : net and o
7676" =1 : net and t
7677" =2 : net and v
7678" =3 : local and o
7679" =4 : local and t
7680" =5 : local and v
7681fun! s:NetrwSplit(mode)
7682" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
7683
Bram Moolenaar97d62492012-11-15 21:28:22 +01007684 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007685 call s:SaveWinVars()
7686
7687 if a:mode == 0
7688 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02007689 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
7690" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007691 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007692 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007693 keepj call s:RestoreWinVars()
7694 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007695 unlet s:didsplit
7696
7697 elseif a:mode == 1
7698 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01007699 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007700" call Decho("tabnew")
7701 tabnew
7702 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007703 keepj call s:RestoreWinVars()
7704 keepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007705 unlet s:didsplit
7706
7707 elseif a:mode == 2
7708 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02007709 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
7710" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007711 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007712 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007713 keepj call s:RestoreWinVars()
7714 keepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007715 unlet s:didsplit
7716
7717 elseif a:mode == 3
7718 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02007719 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
7720" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007721 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007723 keepj call s:RestoreWinVars()
7724 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007725 unlet s:didsplit
7726
7727 elseif a:mode == 4
7728 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00007729 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007730 let eikeep = &ei
7731 let netrw_winnr = winnr()
7732 let netrw_line = line(".")
7733 let netrw_col = virtcol(".")
7734 keepj norm! H0
7735 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01007736 setl ei=all
Bram Moolenaar8d043172014-01-23 14:24:41 +01007737 exe "keepj norm! ".netrw_hline."G0z\<CR>"
7738 exe "keepj norm! ".netrw_line."G0".netrw_col."\<bar>"
7739 let &ei= eikeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01007740 let netrw_curdir= s:NetrwTreeDir()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741" call Decho("tabnew")
7742 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01007743 let b:netrw_curdir = netrw_curdir
7744 let s:didsplit = 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007745 keepj call s:RestoreWinVars()
7746 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01007747 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01007748 setl ei=all
Bram Moolenaar8d043172014-01-23 14:24:41 +01007749 exe "keepj norm! ".netrw_hline."G0z\<CR>"
7750 exe "keepj norm! ".netrw_line."G0".netrw_col."\<bar>"
7751 let &ei= eikeep
7752 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007753 unlet s:didsplit
7754
7755 elseif a:mode == 5
7756 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02007757 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
7758" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02007759 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007760 let s:didsplit= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007761 keepj call s:RestoreWinVars()
7762 keepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007763 unlet s:didsplit
7764
7765 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02007766 keepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007767 endif
7768
Bram Moolenaar97d62492012-11-15 21:28:22 +01007769 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007770" call Dret("s:NetrwSplit")
7771endfun
7772
7773" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007774" s:NetrwTgtMenu: {{{2
7775fun! s:NetrwTgtMenu()
7776 if !exists("s:netrw_menucnt")
7777 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007779" call Dfunc("s:NetrwTgtMenu()")
7780
7781 " the following test assures that gvim is running, has menus available, and has menus enabled.
7782 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
7783 if exists("g:NetrwTopLvlMenu")
7784" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
7785 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
7786 endif
7787 if !exists("s:netrw_initbookhist")
7788 call s:NetrwBookHistRead()
7789 endif
7790
7791 " target bookmarked places
7792 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
7793" call Decho("installing bookmarks as easy targets")
7794 let cnt= 1
7795 for bmd in g:netrw_bookmarklist
7796 let ebmd= escape(bmd,g:netrw_menu_escape)
7797 " show bookmarks for goto menu
7798" call Decho("menu: Targets: ".bmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01007799 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 +02007800 let cnt= cnt + 1
7801 endfor
7802 endif
7803
7804 " target directory browsing history
7805 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
7806" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")")
7807 let histcnt = 1
7808 while histcnt <= g:netrw_dirhistmax
7809 let priority = g:netrw_dirhist_cnt + histcnt
7810 if exists("g:netrw_dirhist_{histcnt}")
7811 let histentry = g:netrw_dirhist_{histcnt}
7812 let ehistentry = escape(histentry,g:netrw_menu_escape)
7813" call Decho("menu: Targets: ".histentry)
Bram Moolenaara6878372014-03-22 21:02:50 +01007814 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 +02007815 endif
7816 let histcnt = histcnt + 1
7817 endwhile
7818 endif
7819 endif
7820" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821endfun
7822
7823" ---------------------------------------------------------------------
7824" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
7825" (full path directory with trailing slash returned)
7826fun! s:NetrwTreeDir()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007827" 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 +00007828
Bram Moolenaar8d043172014-01-23 14:24:41 +01007829 if exists("s:treedir")
7830 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
7831 let treedir= s:treedir
7832 unlet s:treedir
7833" call Dret("s:NetrwTreeDir ".treedir)
7834 return treedir
7835 endif
7836 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
7837 let b:netrw_curdir= getcwd()
7838 endif
7839 let treedir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01007840" call Decho("set initial treedir<".treedir.">")
7841 let s:treecurpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842
7843 if w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01007844" call Decho("w:netrw_liststyle is TREELIST:")
7845" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007846
7847 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007848 if getline('.') =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01007849" call Decho("extract tree subdirectory from current line")
7850 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01007851" call Decho("treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 else
Bram Moolenaara6878372014-03-22 21:02:50 +01007853" call Decho("do not extract tree subdirectory from current line and set treedir to empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854 let treedir= ""
7855 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856
7857 " detect user attempting to close treeroot
Bram Moolenaara6878372014-03-22 21:02:50 +01007858" call Decho("win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
7859" call Decho("getline(".line(".").")<".getline('.').'> '.((getline('.') =~ '^'.s:treedepthstring)? '=~' : '!~').' ^'.s:treedepthstring)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007860 if getline('.') !~ '^'.s:treedepthstring && getline('.') != '..'
7861" call Decho("user may have attempted to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862 " now force a refresh
Bram Moolenaara6878372014-03-22 21:02:50 +01007863" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007864 sil! keepj %d
Bram Moolenaar8d043172014-01-23 14:24:41 +01007865" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01007867" else " Decho
7868" call Decho("user did not attempt to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 endif
7870
Bram Moolenaara6878372014-03-22 21:02:50 +01007871 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007873
7874 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00007875 let treedir= substitute(treedir,'//$','/','')
7876
Bram Moolenaar8d043172014-01-23 14:24:41 +01007877" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007878 return treedir
7879endfun
7880
7881" ---------------------------------------------------------------------
7882" s:NetrwTreeDisplay: recursive tree display {{{2
7883fun! s:NetrwTreeDisplay(dir,depth)
7884" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
7885
7886 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02007887 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888
7889 " install ../ and shortdir
7890 if a:depth == ""
7891 call setline(line("$")+1,'../')
7892" call Decho("setline#".line("$")." ../ (depth is zero)")
7893 endif
7894 if a:dir =~ '^\a\+://'
7895 if a:dir == w:netrw_treetop
7896 let shortdir= a:dir
7897 else
7898 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
7899 endif
7900 call setline(line("$")+1,a:depth.shortdir)
7901 else
7902 let shortdir= substitute(a:dir,'^.*/','','e')
7903 call setline(line("$")+1,a:depth.shortdir.'/')
7904 endif
7905" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">")
7906
7907 " append a / to dir if its missing one
7908 let dir= a:dir
7909 if dir !~ '/$'
7910 let dir= dir.'/'
7911 endif
7912
7913 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007914 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915
7916" call Decho("display subtrees with depth<".depth."> and current leaves")
7917 for entry in w:netrw_treedict[a:dir]
7918 let direntry= substitute(dir.entry,'/$','','e')
7919" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">")
7920 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
7921" call Decho("<".direntry."> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007922 keepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007923 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
7924" call Decho("<".direntry."/> is a key in treedict - display subtree for it")
Bram Moolenaaradc21822011-04-01 18:03:16 +02007925 keepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007926 else
7927" call Decho("<".entry."> is not a key in treedict (no subtree)")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007928 sil! keepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007929 endif
7930 endfor
Bram Moolenaar8d043172014-01-23 14:24:41 +01007931
Bram Moolenaar446cb832008-06-24 21:56:24 +00007932" call Dret("NetrwTreeDisplay")
7933endfun
7934
7935" ---------------------------------------------------------------------
7936" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
7937fun! s:NetrwTreeListing(dirname)
7938 if w:netrw_liststyle == s:TREELIST
7939" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01007940" call Decho("curdir<".a:dirname.">")
7941" 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"))
7942" 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 +00007943
7944 " update the treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01007945" call Decho("update the treetop")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 if !exists("w:netrw_treetop")
7947 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01007948" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007949 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
7950 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01007951" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 endif
7953
7954 " insure that we have at least an empty treedict
7955 if !exists("w:netrw_treedict")
7956 let w:netrw_treedict= {}
7957 endif
7958
7959 " update the directory listing for the current directory
Bram Moolenaara6878372014-03-22 21:02:50 +01007960" call Decho("updating dictionary with ".a:dirname.":[..directory listing..]")
7961" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007962 exe "sil! keepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007963 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +01007964" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007965 exe "sil! keepj ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007966
7967 " if past banner, record word
7968 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
7969 let fname= expand("<cword>")
7970 else
7971 let fname= ""
7972 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01007973" call Decho("fname<".fname.">")
7974" 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 +00007975
7976 " display from treetop on down
Bram Moolenaaradc21822011-04-01 18:03:16 +02007977 keepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007978" call Decho("s:NetrwTreeDisplay) setl noma nomod ro")
7979
7980 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
7981 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01007982" call Decho("deleting blank line")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007983 1d
7984 endwhile
7985
7986 setl noma nomod ro
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987
7988" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007989 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990 endif
7991endfun
7992
7993" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01007994" s:NetrwTreePath: returns path to current file in tree listing {{{2
7995" Normally, treetop is w:netrw_treetop, but a
7996" user of the function ( netrw#SetTreetop() )
7997" wipes that out prior to calling this function
7998fun! s:NetrwTreePath(treetop)
7999" call Dfunc("s:NetrwTreePath() line#".line(".")."<".getline(".").">")
8000 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
8001" call Decho("(s:NetrwTreePath) depth<".depth."> 1st subst")
8002 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8003" call Decho("(s:NetrwTreePath) depth<".depth."> 2nd subst (first depth removed)")
8004 if getline('.') =~ '/$'
8005" call Decho("extract tree directory from current line")
8006 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8007" call Decho("(s:NetrwTreePath) treedir<".treedir.">")
8008 else
8009" call Decho("(s:NetrwTreePath) do not extract tree directory from current line and set treedir to empty")
8010 let treedir= ""
8011 endif
8012 " construct treedir by searching backwards at correct depth
8013" call Decho("(s:NetrwTreePath) construct treedir by searching backwards for correct depth")
8014" call Decho("(s:NetrwTreePath) initial treedir<".treedir."> depth<".depth.">")
8015 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
8016 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
8017 let treedir= dirname.treedir
8018 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8019" call Decho("(s:NetrwTreePath) constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">")
8020 endwhile
8021 if a:treetop =~ '/$'
8022 let treedir= a:treetop.treedir
8023 else
8024 let treedir= a:treetop.'/'.treedir
8025 endif
8026 let treedir= substitute(treedir,'//$','/','')
8027" call Dret("s:NetrwTreePath <".treedir.">")
8028 return treedir
8029endfun
8030
8031" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032" s:NetrwWideListing: {{{2
8033fun! s:NetrwWideListing()
8034
8035 if w:netrw_liststyle == s:WIDELIST
8036" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
8037 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008038 " cpf: characters per filename
8039 " fpl: filenames per line
8040 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02008041 setl ma noro
8042" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 let b:netrw_cpf= 0
8044 if line("$") >= w:netrw_bannercnt
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008045 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 +02008046 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 else
8048" call Dret("NetrwWideListing")
8049 return
8050 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008051 let b:netrw_cpf= b:netrw_cpf + 2
8052" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053
8054 " determine qty files per line (fpl)
8055 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
8056 if w:netrw_fpl <= 0
8057 let w:netrw_fpl= 1
8058 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008059" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060
8061 " make wide display
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008062 exe 'sil keepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008063 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
8065 let newcolstart = w:netrw_bannercnt + fpc
8066 let newcolend = newcolstart + fpc - 1
8067" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008068 if has("clipboard")
8069 sil! let keepregstar = @*
8070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 while line("$") >= newcolstart
8072 if newcolend > line("$") | let newcolend= line("$") | endif
8073 let newcolqty= newcolend - newcolstart
8074 exe newcolstart
8075 if newcolqty == 0
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008076 exe "sil! keepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008077 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008078 exe "sil! keepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008080 exe "sil! keepj ".newcolstart.','.newcolend.'d'
8081 exe 'sil! keepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01008083 if has("clipboard")
8084 sil! let @*= keepregstar
8085 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008086 exe "sil! keepj ".w:netrw_bannercnt.',$s/\s\+$//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008087 keepj call histdel("/",-1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008088 exe "nmap <buffer> <silent> w /^\\\\|\\s\\s\\zs\\S/\<cr>"
8089 exe "nmap <buffer> <silent> b ?^\\\\|\\s\\s\\zs\\S?\<cr>"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008090" call Decho("NetrwWideListing) setl noma nomod ro")
8091 setl noma nomod ro
8092" 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 +00008093" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008094 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008095 else
8096 if hasmapto("w","n")
8097 sil! nunmap <buffer> w
8098 endif
8099 if hasmapto("b","n")
8100 sil! nunmap <buffer> b
8101 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008102 endif
8103
8104endfun
8105
8106" ---------------------------------------------------------------------
8107" s:PerformListing: {{{2
8108fun! s:PerformListing(islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008109" call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01008110" 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 +00008111
Bram Moolenaar15146672011-10-20 22:22:38 +02008112 " set up syntax highlighting {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008113" call Decho("set up syntax highlighting")
Bram Moolenaar15146672011-10-20 22:22:38 +02008114 if has("syntax")
8115 if !exists("g:syntax_on") || !g:syntax_on
Bram Moolenaara6878372014-03-22 21:02:50 +01008116" call Decho("but g:syntax_on".(exists("g:syntax_on")? "=".g:syntax_on : "<doesn't exist>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008117 setl ft=
Bram Moolenaar15146672011-10-20 22:22:38 +02008118 elseif &ft != "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008119" call Decho("setl ft=netrw")
Bram Moolenaarff034192013-04-24 18:51:19 +02008120 setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02008121 endif
8122 endif
8123
Bram Moolenaaradc21822011-04-01 18:03:16 +02008124 keepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01008125 setl noro ma
8126" call Decho("setl noro ma bh=".&bh)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127
8128" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008129" call Decho("(netrw) Processing your browsing request...")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130" endif " Decho
8131
8132" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
8133 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
8134 " force a refresh for tree listings
Bram Moolenaara6878372014-03-22 21:02:50 +01008135" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008136 sil! keepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137 endif
8138
8139 " save current directory on directory history list
Bram Moolenaaradc21822011-04-01 18:03:16 +02008140 keepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141
8142 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008143 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008144" call Decho("set up banner")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008145 keepj call setline(1,'" ============================================================================')
8146 keepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008147 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
8148 keepj call setline(3,'" '.substitute(b:netrw_curdir,'/','\\','g'))
8149 else
8150 keepj call setline(3,'" '.b:netrw_curdir)
8151 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008152 let w:netrw_bannercnt= 3
Bram Moolenaaradc21822011-04-01 18:03:16 +02008153 keepj exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008154 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008155 keepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01008156 let w:netrw_bannercnt= 1
8157 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008158" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159
8160 let sortby= g:netrw_sort_by
8161 if g:netrw_sort_direction =~ "^r"
8162 let sortby= sortby." reversed"
8163 endif
8164
8165 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008166 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008167" call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008168 if g:netrw_sort_by =~ "^n"
Bram Moolenaara6878372014-03-22 21:02:50 +01008169" call Decho("directories will be sorted by name")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008170 " sorted by name
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008171 keepj put ='\" Sorted by '.sortby
8172 keepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01008173 let w:netrw_bannercnt= w:netrw_bannercnt + 2
8174 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008175" call Decho("directories will be sorted by size or time")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008176 " sorted by size or date
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008177 keepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01008178 let w:netrw_bannercnt= w:netrw_bannercnt + 1
8179 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008180 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01008181" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008182" 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 +00008183 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184
8185 " show copy/move target, if any
Bram Moolenaar5c736222010-01-06 20:54:52 +01008186 if g:netrw_banner
8187 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara6878372014-03-22 21:02:50 +01008188" call Decho("show copy/move target<".s:netrwmftgt.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008189 keepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01008190 if s:netrwmftgt_islocal
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008191 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008192 else
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008193 sil! keepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008194 endif
8195 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008197" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008199 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201
8202 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008203 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008204" 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 +01008205 if g:netrw_list_hide != "" && g:netrw_hide
8206 if g:netrw_hide == 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008207 keepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008208 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008209 keepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008210 endif
8211 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008212 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008213 exe "keepjumps ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008214
8215" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
8216 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
8217" call Decho("quickhelp =".quickhelp)
8218 keepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
8219" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
8220 keepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01008221 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01008222" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008223" 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 +00008224 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225
8226 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01008227 if g:netrw_banner
8228 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008229 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008230" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008231" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008232" 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 +01008233 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235 " get list of files
Bram Moolenaara6878372014-03-22 21:02:50 +01008236" call Decho("Get list of files - islocal=".a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02008238 keepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008239 else " remote
Bram Moolenaara6878372014-03-22 21:02:50 +01008240 keepj let badresult= s:NetrwRemoteListing()
8241 if badresult
8242" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
8243" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
8244 return
8245 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008246 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008247
8248 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008249 if !exists("w:netrw_bannercnt")
8250 let w:netrw_bannercnt= 0
8251 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008252" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)")
8253" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
8254
Bram Moolenaar5c736222010-01-06 20:54:52 +01008255 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008256" call Decho("manipulate directory listing (hide)")
8257" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008259 keepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008260 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008261 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008262" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008263
8264 if g:netrw_sort_by =~ "^n"
8265 " sort by name
Bram Moolenaaradc21822011-04-01 18:03:16 +02008266 keepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008267
Bram Moolenaar5c736222010-01-06 20:54:52 +01008268 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008269" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008270 if g:netrw_sort_direction =~ 'n'
8271 " normal direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008272 exe 'sil keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008273 else
8274 " reverse direction sorting
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008275 exe 'sil keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008276 endif
8277 endif
8278 " remove priority pattern prefix
Bram Moolenaara6878372014-03-22 21:02:50 +01008279" call Decho("remove priority pattern prefix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008280 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008281 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008282
8283 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01008284 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008285" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286 if g:netrw_sort_direction =~ 'n'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008287" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008288 exe 'sil! keepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008289 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02008290" call Decho('exe sil keepjumps '.w:netrw_bannercnt.',$sort!')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008291 exe 'sil! keepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008292 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008293 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008294 keepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008295 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008296 endif
8297
8298 elseif g:netrw_sort_direction =~ 'r'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008299" call Decho('(s:PerformListing) reverse the sorted listing')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008300 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008301 exe 'sil! keepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008302 call histdel("/",-1)
8303 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008304 endif
8305 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008306" 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 +00008307
8308 " convert to wide/tree listing {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008309" call Decho("modify display if wide/tree listing style")
8310" 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 +02008311 keepj call s:NetrwWideListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01008312" 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 +02008313 keepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01008314" 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 +00008315
Bram Moolenaar5c736222010-01-06 20:54:52 +01008316 if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008317 " place cursor on the top-left corner of the file listing
Bram Moolenaara6878372014-03-22 21:02:50 +01008318" call Decho("place cursor on top-left corner of file listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008319 exe 'sil! keepj '.w:netrw_bannercnt
8320 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008321 endif
8322
8323 " record previous current directory
8324 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01008325" call Decho("record netrw_prvdir<".w:netrw_prvdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326
8327 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008328" 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 +02008329 keepj call s:SetBufWinVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01008330" 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 +02008331 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008332" 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 +00008333
8334 " set display to netrw display settings
Bram Moolenaara6878372014-03-22 21:02:50 +01008335" call Decho("set display to netrw display settings (".g:netrw_bufsettings.")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008336 exe "setl ".g:netrw_bufsettings
Bram Moolenaara6878372014-03-22 21:02:50 +01008337" 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 +01008338 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara6878372014-03-22 21:02:50 +01008339" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008340 exe "setl ts=".(g:netrw_maxfilenamelen+1)
8341 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008342
Bram Moolenaar8d043172014-01-23 14:24:41 +01008343 if exists("s:treecurpos")
Bram Moolenaara6878372014-03-22 21:02:50 +01008344" 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)")
8345 keepj call netrw#RestorePosn(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008346 unlet s:treecurpos
8347 endif
8348
Bram Moolenaara6878372014-03-22 21:02:50 +01008349" 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 +00008350" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
8351endfun
8352
8353" ---------------------------------------------------------------------
8354" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008355fun! s:SetupNetrwStatusLine(statline)
8356" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
8357
8358 if !exists("s:netrw_setup_statline")
8359 let s:netrw_setup_statline= 1
8360" call Decho("do first-time status line setup")
8361
8362 if !exists("s:netrw_users_stl")
8363 let s:netrw_users_stl= &stl
8364 endif
8365 if !exists("s:netrw_users_ls")
8366 let s:netrw_users_ls= &laststatus
8367 endif
8368
8369 " set up User9 highlighting as needed
8370 let keepa= @a
8371 redir @a
8372 try
8373 hi User9
8374 catch /^Vim\%((\a\+)\)\=:E411/
8375 if &bg == "dark"
8376 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
8377 else
8378 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
8379 endif
8380 endtry
8381 redir END
8382 let @a= keepa
8383 endif
8384
8385 " set up status line (may use User9 highlighting)
8386 " insure that windows have a statusline
8387 " make sure statusline is displayed
8388 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02008389 setl laststatus=2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008390" call Decho("stl=".&stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008391 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00008392
8393" call Dret("SetupNetrwStatusLine : stl=".&stl)
8394endfun
8395
8396" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008397" Remote Directory Browsing Support: {{{1
8398" ===========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00008399
8400" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01008401" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
8402" This function assumes that a long listing will be received. Size, time,
8403" and reverse sorts will be requested of the server but not otherwise
8404" enforced here.
8405fun! s:NetrwRemoteFtpCmd(path,listcmd)
8406" 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 : "???")))
8407" call Decho("line($)=".line("$")." w:netrw_bannercnt=".w:netrw_bannercnt)
8408 " sanity check: {{{3
8409 if !exists("w:netrw_method")
8410 if exists("b:netrw_method")
8411 let w:netrw_method= b:netrw_method
8412 else
8413 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
8414" call Dret("NetrwRemoteFtpCmd")
8415 return
8416 endif
8417 endif
8418
8419 " WinXX ftp uses unix style input, so set ff to unix " {{{3
8420 let ffkeep= &ff
8421 setl ma ff=unix noro
8422" call Decho("setl ma ff=unix noro")
8423
8424 " clear off any older non-banner lines " {{{3
8425 " note that w:netrw_bannercnt indexes the line after the banner
8426" call Decho('exe sil! keepjumps '.w:netrw_bannercnt.",$d (clear off old non-banner lines)")
8427 exe "sil! keepjumps ".w:netrw_bannercnt.",$d"
8428
8429 ".........................................
8430 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
8431 " ftp + <.netrc>: Method #2
8432 if a:path != ""
8433 keepj put ='cd \"'.a:path.'\"'
8434 endif
8435 if exists("g:netrw_ftpextracmd")
8436 keepj put =g:netrw_ftpextracmd
8437" call Decho("filter input: ".getline('.'))
8438 endif
8439 keepj call setline(line("$")+1,a:listcmd)
8440" exe "keepjumps ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
8441 if exists("g:netrw_port") && g:netrw_port != ""
8442" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
8443 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
8444 else
8445" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
8446 exe s:netrw_silentxfer." keepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
8447 endif
8448
8449 ".........................................
8450 elseif w:netrw_method == 3 " {{{3
8451 " ftp + machine,id,passwd,filename: Method #3
8452 setl ff=unix
8453 if exists("g:netrw_port") && g:netrw_port != ""
8454 keepj put ='open '.g:netrw_machine.' '.g:netrw_port
8455 else
8456 keepj put ='open '.g:netrw_machine
8457 endif
8458
8459 " handle userid and password
8460 let host= substitute(g:netrw_machine,'\..*$','','')
8461" call Decho("host<".host.">")
8462 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
8463 call NetUserPass("ftp:".host)
8464 endif
8465 if exists("g:netrw_uid") && g:netrw_uid != ""
8466 if exists("g:netrw_ftp") && g:netrw_ftp == 1
8467 keepj put =g:netrw_uid
8468 if exists("s:netrw_passwd") && s:netrw_passwd != ""
8469 keepj put ='\"'.s:netrw_passwd.'\"'
8470 endif
8471 elseif exists("s:netrw_passwd")
8472 keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
8473 endif
8474 endif
8475
8476 if a:path != ""
8477 keepj put ='cd \"'.a:path.'\"'
8478 endif
8479 if exists("g:netrw_ftpextracmd")
8480 keepj put =g:netrw_ftpextracmd
8481" call Decho("filter input: ".getline('.'))
8482 endif
8483 keepj call setline(line("$")+1,a:listcmd)
8484
8485 " perform ftp:
8486 " -i : turns off interactive prompting from ftp
8487 " -n unix : DON'T use <.netrc>, even though it exists
8488 " -n win32: quit being obnoxious about password
8489 if exists("w:netrw_bannercnt")
8490" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
8491" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
8492 exe s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
8493" else " Decho
8494" call Decho("WARNING: w:netrw_bannercnt doesn't exist!")
8495" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline(".")) " COMBAK
8496 endif
8497
8498 ".........................................
8499 elseif w:netrw_method == 9 " {{{3
8500 " sftp username@machine: Method #9
8501 " s:netrw_sftp_cmd
8502 setl ff=unix
8503
8504 " restore settings
8505 let &ff= ffkeep
8506" call Dret("NetrwRemoteFtpCmd")
8507 return
8508
8509 ".........................................
8510 else " {{{3
8511 keepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
8512 endif
8513
8514 " cleanup for Windows " {{{3
8515 if has("win32") || has("win95") || has("win64") || has("win16")
8516 sil! keepj %s/\r$//e
8517 keepj call histdel("/",-1)
8518 endif
8519 if a:listcmd == "dir"
8520 " infer directory/link based on the file permission string
8521 sil! keepj g/d\%([-r][-w][-x]\)\{3}/keepj s@$@/@e
8522 sil! keepj g/l\%([-r][-w][-x]\)\{3}/keepj s/$/@/e
8523 keepj call histdel("/",-1)
8524 keepj call histdel("/",-1)
8525 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
8526 exe "sil! keepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
8527 keepj call histdel("/",-1)
8528 endif
8529 endif
8530
8531 " ftp's listing doesn't seem to include ./ or ../ " {{{3
8532 if !search('^\.\/$\|\s\.\/$','wn')
8533 exe 'keepj '.w:netrw_bannercnt
8534 keepj put ='./'
8535 endif
8536 if !search('^\.\.\/$\|\s\.\.\/$','wn')
8537 exe 'keepj '.w:netrw_bannercnt
8538 keepj put ='../'
8539 endif
8540
8541 " restore settings " {{{3
8542 let &ff= ffkeep
8543" call Dret("NetrwRemoteFtpCmd")
8544endfun
8545
8546" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008547" s:NetrwRemoteListing: {{{2
8548fun! s:NetrwRemoteListing()
8549" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00008550
Bram Moolenaara6878372014-03-22 21:02:50 +01008551 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
8552 let w:netrw_bannercnt= s:bannercnt
8553 endif
8554 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
8555 let w:netrw_bannercnt= s:bannercnt
8556 endif
8557
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008559
Bram Moolenaar446cb832008-06-24 21:56:24 +00008560 " sanity check:
8561 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008562" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 if !executable("ftp")
Bram Moolenaara6878372014-03-22 21:02:50 +01008564" call Decho("ftp is not executable")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565 if !exists("g:netrw_quiet")
8566 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
8567 endif
8568 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008569" call Dret("s:NetrwRemoteListing -1")
8570 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00008571 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572
Bram Moolenaar8d043172014-01-23 14:24:41 +01008573 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara6878372014-03-22 21:02:50 +01008574" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008575 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008576 if g:netrw_list_cmd == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01008577 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 +00008578 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02008579 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 +00008580 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008581 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008582
Bram Moolenaaradc21822011-04-01 18:03:16 +02008583 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008584" call Dret("s:NetrwRemoteListing -1")
8585 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586 endif " (remote handling sanity check)
Bram Moolenaara6878372014-03-22 21:02:50 +01008587" call Decho("passed remote listing sanity checks")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008588
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589 if exists("b:netrw_method")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008590" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 let w:netrw_method= b:netrw_method
8592 endif
8593
Bram Moolenaar8d043172014-01-23 14:24:41 +01008594 if s:method == "ftp" || s:method == "sftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008595 " use ftp to get remote file listing {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596" call Decho("use ftp to get remote file listing")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008597 let s:method = "ftp"
8598 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 if g:netrw_sort_by =~ '^t'
8600 let listcmd= g:netrw_ftp_timelist_cmd
8601 elseif g:netrw_sort_by =~ '^s'
8602 let listcmd= g:netrw_ftp_sizelist_cmd
8603 endif
8604" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)")
8605 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008606" exe "sil! keepalt keepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
Bram Moolenaara6878372014-03-22 21:02:50 +01008608 " report on missing file or directory messages
8609 if search('[Nn]o such file or directory\|Failed to change directory')
8610 let mesg= getline(".")
8611 if exists("w:netrw_bannercnt")
8612 setl ma
8613 exe w:netrw_bannercnt.",$d"
8614 setl noma
8615 endif
8616 keepj call s:NetrwOptionRestore("w:")
8617 call netrw#ErrorMsg(s:WARNING,mesg,96)
8618" call Dret("s:NetrwRemoteListing : -1")
8619 return -1
8620 endif
8621
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
8623 " shorten the listing
8624" call Decho("generate short listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008625 exe "sil! keepalt keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626
8627 " cleanup
8628 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008629 exe "sil! keepalt keepj g/".g:netrw_ftp_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008630 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008632 sil! keepj %s/\r$//e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008633 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008634
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008635 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008637 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01008638 let line2= search('\.\.\/\%(\s\|$\)','cnW')
8639" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 if line2 == 0
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008641" call Decho("netrw is putting ../ into listing")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008642 sil! keepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008644 exe "sil! keepj ".line1
8645 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008646
8647" call Decho("line1=".line1." line2=".line2." line(.)=".line("."))
8648 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
8649" call Decho("M$ ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008650 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 +02008651 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652 else " normal ftp cleanup
8653" call Decho("normal ftp cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008654 exe 'sil! keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
8655 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
8656 exe "sil! keepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008657 keepj call histdel("/",-1)
8658 keepj call histdel("/",-1)
8659 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 endif
8661 endif
8662
8663 else
8664 " use ssh to get remote file listing {{{3
8665" call Decho("use ssh to get remote file listing: s:path<".s:path.">")
8666 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
8667" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)")
8668 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaaradc21822011-04-01 18:03:16 +02008669" call Decho("1: exe sil r! ".shellescape(listcmd.s:path, 1))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008670 exe "sil! keepj r! ".listcmd.shellescape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008672 sil! keepj g/^Listing directory/keepj d
8673 sil! keepj g/^d[-rwx][-rwx][-rwx]/keepj s+$+/+e
8674 sil! keepj g/^l[-rwx][-rwx][-rwx]/keepj s+$+@+e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008675 keepj call histdel("/",-1)
8676 keepj call histdel("/",-1)
8677 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008679 sil! keepj g/^[dlsp-][-rwx][-rwx][-rwx]/keepj s/^.*\s\(\S\+\)$/\1/e
Bram Moolenaaradc21822011-04-01 18:03:16 +02008680 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 endif
8682 else
8683 if s:path == ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008684" call Decho("2: exe sil r! ".listcmd)
Bram Moolenaar15146672011-10-20 22:22:38 +02008685 exe "sil! keepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00008686 else
Bram Moolenaar251e1912011-06-19 05:09:16 +02008687" call Decho("3: exe sil r! ".listcmd.' '.shellescape(fnameescape(s:path),1))
Bram Moolenaar15146672011-10-20 22:22:38 +02008688 exe "sil! keepj keepalt r! ".listcmd.' '.shellescape(fnameescape(s:path),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008689" call Decho("listcmd<".listcmd."> path<".s:path.">")
8690 endif
8691 endif
8692
8693 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01008694 if g:netrw_ssh_browse_reject != ""
8695" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/keepjumps d")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008696 exe "sil! g/".g:netrw_ssh_browse_reject."/keepj d"
Bram Moolenaaradc21822011-04-01 18:03:16 +02008697 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 endif
8699 endif
8700
8701 if w:netrw_liststyle == s:LONGLIST
8702 " do a long listing; these substitutions need to be done prior to sorting {{{3
8703" call Decho("fix long listing:")
8704
8705 if s:method == "ftp"
8706 " cleanup
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008707 exe "sil! keepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708 while getline('.') =~ g:netrw_ftp_browse_reject
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008709 sil! keepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008711 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 let line1= line(".")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008713 sil! keepj 1
8714 sil! keepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 let line2= line(".")
8716 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717 if b:netrw_curdir != '/'
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008718 exe 'sil! keepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 endif
8720 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008721 exe "sil! keepj ".line1
8722 sil! keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008723 endif
8724
8725 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
8726" call Decho("M$ ftp site listing cleanup")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008727 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 +00008728 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
8729" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008730 exe 'sil keepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
8731 exe 'sil keepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
8732 exe 'sil keepj '.w:netrw_bannercnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02008733 keepj call histdel("/",-1)
8734 keepj call histdel("/",-1)
8735 keepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 endif
8737 endif
8738
8739" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008740" exe "keepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008741" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008742
8743" call Dret("s:NetrwRemoteListing 0")
8744 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008745endfun
8746
Bram Moolenaar446cb832008-06-24 21:56:24 +00008747" ---------------------------------------------------------------------
8748" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
8749fun! s:NetrwRemoteRm(usrhost,path) range
8750" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
8751" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaara6878372014-03-22 21:02:50 +01008752 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008753
8754 let all= 0
8755 if exists("s:netrwmarkfilelist_{bufnr('%')}")
8756 " remove all marked files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008757" call Decho("remove all marked files with bufnr#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008758 for fname in s:netrwmarkfilelist_{bufnr("%")}
8759 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
8760 if ok =~ 'q\%[uit]'
8761 break
8762 elseif ok =~ 'a\%[ll]'
8763 let all= 1
8764 endif
8765 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01008766 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767
8768 else
8769 " remove files specified by range
Bram Moolenaar5c736222010-01-06 20:54:52 +01008770" call Decho("remove files specified by range")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771
8772 " preparation for removing multiple files/directories
8773 let ctr= a:firstline
8774
8775 " remove multiple files and directories
8776 while ctr <= a:lastline
Bram Moolenaar15146672011-10-20 22:22:38 +02008777 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
8779 if ok =~ 'q\%[uit]'
8780 break
8781 elseif ok =~ 'a\%[ll]'
8782 let all= 1
8783 endif
8784 let ctr= ctr + 1
8785 endwhile
8786 endif
8787
8788 " refresh the (remote) directory listing
8789" call Decho("refresh remote directory listing")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008790 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01008791 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792
8793" call Dret("s:NetrwRemoteRm")
8794endfun
8795
8796" ---------------------------------------------------------------------
8797" s:NetrwRemoteRmFile: {{{2
8798fun! s:NetrwRemoteRmFile(path,rmfile,all)
8799" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
8800
8801 let all= a:all
8802 let ok = ""
8803
8804 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
8805 " attempt to remove file
8806" call Decho("attempt to remove file (all=".all.")")
8807 if !all
8808 echohl Statement
8809" call Decho("case all=0:")
8810 call inputsave()
8811 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8812 call inputrestore()
8813 echohl NONE
8814 if ok == ""
8815 let ok="no"
8816 endif
8817 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8818 if ok =~ 'a\%[ll]'
8819 let all= 1
8820 endif
8821 endif
8822
8823 if all || ok =~ 'y\%[es]' || ok == ""
8824" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""))
8825 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
8826" call Decho("case ftp:")
8827 let path= a:path
8828 if path =~ '^\a\+://'
8829 let path= substitute(path,'^\a\+://[^/]\+/','','')
8830 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008831 sil! keepj .,$d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
8833 else
8834" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">")
8835 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
8836" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
8837 if !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008838 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008839 let ok="q"
8840 else
8841 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
8842" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
8843" call Decho("remotedir<".remotedir.">")
8844" call Decho("rmfile<".a:rmfile.">")
8845 if remotedir != ""
8846 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile))
8847 else
8848 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile))
8849 endif
8850" call Decho("call system(".netrw_rm_cmd.")")
8851 let ret= system(netrw_rm_cmd)
8852 if ret != 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02008853 keepj call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 endif
8855" call Decho("returned=".ret." errcode=".v:shell_error)
8856 endif
8857 endif
8858 elseif ok =~ 'q\%[uit]'
8859" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860 endif
8861
8862 else
8863 " attempt to remove directory
8864" call Decho("attempt to remove directory")
8865 if !all
8866 call inputsave()
8867 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
8868 call inputrestore()
8869 if ok == ""
8870 let ok="no"
8871 endif
8872 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
8873 if ok =~ 'a\%[ll]'
8874 let all= 1
8875 endif
8876 endif
8877
8878 if all || ok =~ 'y\%[es]' || ok == ""
8879 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02008880 keepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881 else
8882 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008883 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008884" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
Bram Moolenaarc236c162008-07-13 17:41:49 +00008885 let ret= system(netrw_rmdir_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886" call Decho("returned=".ret." errcode=".v:shell_error)
8887
8888 if v:shell_error != 0
Bram Moolenaarc236c162008-07-13 17:41:49 +00008889" call Decho("v:shell_error not 0")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008890 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 +00008891" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
8892 let ret= system(netrw_rmf_cmd)
8893" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894
8895 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaaradc21822011-04-01 18:03:16 +02008896 keepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898 endif
8899 endif
8900
8901 elseif ok =~ 'q\%[uit]'
Bram Moolenaarff034192013-04-24 18:51:19 +02008902" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 endif
8904 endif
8905
8906" call Dret("s:NetrwRemoteRmFile ".ok)
8907 return ok
8908endfun
8909
8910" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008911" s:NetrwRemoteRename: rename a remote file or directory {{{2
8912fun! s:NetrwRemoteRename(usrhost,path) range
8913" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
8914
8915 " preparation for removing multiple files/directories
Bram Moolenaara6878372014-03-22 21:02:50 +01008916 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008917 let ctr = a:firstline
8918 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
8919
8920 " rename files given by the markfilelist
8921 if exists("s:netrwmarkfilelist_{bufnr('%')}")
8922 for oldname in s:netrwmarkfilelist_{bufnr("%")}
8923" call Decho("oldname<".oldname.">")
8924 if exists("subfrom")
8925 let newname= substitute(oldname,subfrom,subto,'')
8926" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
8927 else
8928 call inputsave()
8929 let newname= input("Moving ".oldname." to : ",oldname)
8930 call inputrestore()
8931 if newname =~ '^s/'
8932 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
8933 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
8934 let newname = substitute(oldname,subfrom,subto,'')
8935" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
8936 endif
8937 endif
8938
8939 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaaradc21822011-04-01 18:03:16 +02008940 keepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008942 let oldname= shellescape(a:path.oldname)
8943 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008944" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
8945 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008946 endif
8947
8948 endfor
8949 call s:NetrwUnMarkFile(1)
8950
8951 else
8952
8953 " attempt to rename files/directories
8954 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008955 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008956
8957 let oldname= s:NetrwGetWord()
8958" call Decho("oldname<".oldname.">")
8959
8960 call inputsave()
8961 let newname= input("Moving ".oldname." to : ",oldname)
8962 call inputrestore()
8963
8964 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
8965 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
8966 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008967 let oldname= shellescape(a:path.oldname)
8968 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008969" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
8970 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008971 endif
8972
8973 let ctr= ctr + 1
8974 endwhile
8975 endif
8976
8977 " refresh the directory
Bram Moolenaaradc21822011-04-01 18:03:16 +02008978 keepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01008979 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008980
8981" call Dret("NetrwRemoteRename")
8982endfun
8983
8984" ---------------------------------------------------------------------
8985" Local Directory Browsing Support: {{{1
8986" ==========================================
8987
8988" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01008989" netrw#FileUrlRead: handles reading file://* files {{{2
8990" Should accept: file://localhost/etc/fstab
8991" file:///etc/fstab
8992" file:///c:/WINDOWS/clock.avi
8993" file:///c|/WINDOWS/clock.avi
8994" file://localhost/c:/WINDOWS/clock.avi
8995" file://localhost/c|/WINDOWS/clock.avi
8996" file://c:/foo.txt
8997" file:///c:/foo.txt
8998" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
8999fun! netrw#FileUrlRead(fname)
9000" call Dfunc("netrw#FileUrlRead(fname<".a:fname.">)")
9001 let fname = a:fname
9002 if fname =~ '^file://localhost/'
9003" call Decho('converting file://localhost/ -to- file:///')
9004 let fname= substitute(fname,'^file://localhost/','file:///','')
9005" call Decho("fname<".fname.">")
9006 endif
9007 if (has("win32") || has("win95") || has("win64") || has("win16"))
9008 if fname =~ '^file:///\=\a[|:]/'
9009" call Decho('converting file:///\a|/ -to- file://\a:/')
9010 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
9011" call Decho("fname<".fname.">")
9012 endif
9013 endif
9014 let fname2396 = netrw#RFC2396(fname)
9015 let fname2396e= fnameescape(fname2396)
9016 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
9017 if (has("win32") || has("win95") || has("win64") || has("win16"))
9018" call Decho("windows exception for plainfname")
9019 if plainfname =~ '^/\+\a:'
9020" call Decho('removing leading "/"s')
9021 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
9022 endif
9023 endif
9024" call Decho("fname2396<".fname2396.">")
9025" call Decho("plainfname<".plainfname.">")
9026 exe "sil doau BufReadPre ".fname2396e
9027 exe 'keepj r '.plainfname
Bram Moolenaarff034192013-04-24 18:51:19 +02009028 exe 'sil! bdelete '.plainfname
9029 exe 'keepalt file! '.plainfname
Bram Moolenaar97d62492012-11-15 21:28:22 +01009030 keepj 1d
Bram Moolenaara6878372014-03-22 21:02:50 +01009031" call Decho("setl nomod")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009032 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01009033" 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 +01009034" call Dret("netrw#FileUrlRead")
9035 exe "sil doau BufReadPost ".fname2396e
9036endfun
9037
9038" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039" netrw#LocalBrowseCheck: {{{2
9040fun! netrw#LocalBrowseCheck(dirname)
9041 " unfortunate interaction -- split window debugging can't be
9042 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
9043 " event triggers another call to LocalBrowseCheck() when attempts
9044 " to write to the DBG buffer are made.
9045 " The &ft == "netrw" test was installed because the BufEnter event
9046 " would hit when re-entering netrw windows, creating unexpected
9047 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaara6878372014-03-22 21:02:50 +01009048" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">")
9049" call Decho("isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : "")))
9050" 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)
9051" call Dredir("ls!","ls!")
9052
Bram Moolenaar97d62492012-11-15 21:28:22 +01009053 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054 if isdirectory(a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009055" 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)
9056 let svposn= netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009057 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009058" call Decho("case 1 : ft=".&ft)
Bram Moolenaarff034192013-04-24 18:51:19 +02009059 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009060 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009061
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009063" call Decho("case 2 (ft≡netrw && line($)≡1)")
Bram Moolenaarff034192013-04-24 18:51:19 +02009064 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009065 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009066
Bram Moolenaar5c736222010-01-06 20:54:52 +01009067 elseif exists("s:treeforceredraw")
Bram Moolenaara6878372014-03-22 21:02:50 +01009068" call Decho("case 3 (treeforceredraw)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009069 unlet s:treeforceredraw
Bram Moolenaarff034192013-04-24 18:51:19 +02009070 sil! keepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009071 keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009073
Bram Moolenaara6878372014-03-22 21:02:50 +01009074" call Dret("netrw#LocalBrowseCheck")
9075 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009077
Bram Moolenaar97d62492012-11-15 21:28:22 +01009078 " following code wipes out currently unused netrw buffers
9079 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
9080 " AND IF the listing style is not a tree listing
9081 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01009082" call Decho("wiping out currently unused netrw buffers")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009083 let ibuf = 1
9084 let buflast = bufnr("$")
9085 while ibuf <= buflast
9086 if bufwinnr(ibuf) == -1 && isdirectory(bufname(ibuf))
Bram Moolenaarff034192013-04-24 18:51:19 +02009087 exe "sil! keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009088 endif
9089 let ibuf= ibuf + 1
9090 endwhile
9091 endif
9092 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009093" 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 +00009094 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +01009095" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009096endfun
9097
9098" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009099" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009100" performed any shell command. The idea is to cause all local-browsing
9101" buffers to be refreshed after a user has executed some shell command,
9102" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +01009103fun! s:LocalBrowseRefresh()
9104" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
9105" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'))
9106" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'))
9107
Bram Moolenaar446cb832008-06-24 21:56:24 +00009108 " determine which buffers currently reside in a tab
9109 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009110" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111 return
9112 endif
9113 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +01009114" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 return
9116 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009117 if exists("s:netrw_events") && s:netrw_events == 1
9118 " s:LocalFastBrowser gets called (indirectly) from a
9119 let s:netrw_events= 2
9120" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
9121 return
Bram Moolenaar5c736222010-01-06 20:54:52 +01009122 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009123 let itab = 1
9124 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +01009125 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009126 while itab <= tabpagenr("$")
9127 let buftablist = buftablist + tabpagebuflist()
9128 let itab = itab + 1
9129 tabn
9130 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009131" call Decho("buftablist".string(buftablist))
9132" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009133 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
9134 " | refresh any netrw window
9135 " | wipe out any non-displaying netrw buffer
9136 let curwin = winnr()
9137 let ibl = 0
9138 for ibuf in s:netrw_browselist
Bram Moolenaara6878372014-03-22 21:02:50 +01009139" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
9141 " wipe out any non-displaying netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009142" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009143 exe "sil! bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 call remove(s:netrw_browselist,ibl)
Bram Moolenaara6878372014-03-22 21:02:50 +01009145" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 continue
9147 elseif index(tabpagebuflist(),ibuf) != -1
9148 " refresh any netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009149" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01009151 if getline(".") =~ 'Quick Help'
9152 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
9153 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
9154 let g:netrw_quickhelp= g:netrw_quickhelp - 1
9155 endif
9156" call Decho("#3: quickhelp=".g:netrw_quickhelp)
Bram Moolenaaradc21822011-04-01 18:03:16 +02009157 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009158 endif
9159 let ibl= ibl + 1
9160 endfor
9161 exe curwin."wincmd w"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009162 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009163
Bram Moolenaara6878372014-03-22 21:02:50 +01009164" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165endfun
9166
9167" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009168" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
9169"
9170" g:netrw_ Directory Is
9171" fastbrowse Local Remote
9172" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
9173" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
9174" fast 2 H H
9175"
9176" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
9177" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +01009178" (re-using a buffer may not be as accurate)
9179"
9180" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
9181" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
9182" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
9183" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
9184" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009185fun! s:LocalFastBrowser()
Bram Moolenaara6878372014-03-22 21:02:50 +01009186" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
9187" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'))
9188" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "installed" : "not installed"))
9189" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "installed" : "not installed"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009190
9191 " initialize browselist, a list of buffer numbers that the local browser has used
9192 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009193" call Decho("initialize s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009194 let s:netrw_browselist= []
9195 endif
9196
9197 " append current buffer to fastbrowse list
9198 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara6878372014-03-22 21:02:50 +01009199" call Decho("appendng current buffer to browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009200 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009201" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009202 endif
9203
9204 " enable autocmd events to handle refreshing/removing local browser buffers
9205 " If local browse buffer is currently showing: refresh it
9206 " If local browse buffer is currently hidden : wipe it
9207 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
9208 " =1 : medium speed, re-use directory listing for remote only
9209 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +01009210 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
9211 let s:netrw_events= 1
9212 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009213 au!
9214 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009215" call Decho("installing autocmd: ShellCmdPost")
9216 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009217 else
Bram Moolenaara6878372014-03-22 21:02:50 +01009218" call Decho("installing autocmds: ShellCmdPost FocusGained")
9219 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009220 endif
9221 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +01009222
9223 " user must have changed fastbrowse to its fast setting, so remove
9224 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +01009225 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
9226" call Decho("remove AuNetrwEvent autcmd group")
9227 unlet s:netrw_events
9228 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009229 au!
9230 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +01009231 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009232 endif
9233
9234" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
9235endfun
9236
9237" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009238" s:LocalListing: does the job of "ls" for local directories {{{2
9239fun! s:LocalListing()
9240" call Dfunc("s:LocalListing()")
9241" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
9242" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
9243
9244" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif
9245" 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
9246" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9247
9248 " get the list of files contained in the current directory
9249 let dirname = b:netrw_curdir
9250 let dirnamelen = strlen(b:netrw_curdir)
9251 let filelist = glob(s:ComposePath(dirname,"*"),0,1)
9252 let filelist = filelist + glob(s:ComposePath(dirname,".*"),0,1)
9253" call Decho("filelist=".filelist)
9254
9255 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
9256" call Decho("filelist=".string(filelist))
9257 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
9258 " include ../ in the glob() entry if its missing
9259" call Decho("forcibly including on \"..\"")
9260 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
9261" call Decho("filelist=".string(filelist))
9262 endif
9263
9264" call Decho("before while: dirname<".dirname.">")
9265" call Decho("before while: dirnamelen<".dirnamelen.">")
9266" call Decho("before while: filelist=".string(filelist))
9267
9268 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
9269 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
9270 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
9271" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy))
9272" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen)
9273 endif
9274" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9275
9276 for filename in filelist
9277" call Decho(" ")
9278" call Decho("for filename in filelist: filename<".filename.">")
9279
9280 if getftype(filename) == "link"
9281 " indicate a symbolic link
9282" call Decho("indicate <".filename."> is a symbolic link with trailing @")
9283 let pfile= filename."@"
9284
9285 elseif getftype(filename) == "socket"
9286 " indicate a socket
9287" call Decho("indicate <".filename."> is a socket with trailing =")
9288 let pfile= filename."="
9289
9290 elseif getftype(filename) == "fifo"
9291 " indicate a fifo
9292" call Decho("indicate <".filename."> is a fifo with trailing |")
9293 let pfile= filename."|"
9294
9295 elseif isdirectory(filename)
9296 " indicate a directory
9297" call Decho("indicate <".filename."> is a directory with trailing /")
9298 let pfile= filename."/"
9299
9300 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename)
9301 if (has("win32") || has("win95") || has("win64") || has("win16"))
9302 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
9303 " indicate an executable
9304" call Decho("indicate <".filename."> is executable with trailing *")
9305 let pfile= filename."*"
9306 else
9307 " normal file
9308 let pfile= filename
9309 endif
9310 elseif executable(filename)
9311 " indicate an executable
9312" call Decho("indicate <".filename."> is executable with trailing *")
9313 let pfile= filename."*"
9314 else
9315 " normal file
9316 let pfile= filename
9317 endif
9318
9319 else
9320 " normal file
9321 let pfile= filename
9322 endif
9323" call Decho("pfile<".pfile."> (after *@/ appending)")
9324
9325 if pfile =~ '//$'
9326 let pfile= substitute(pfile,'//$','/','e')
9327" call Decho("change // to /: pfile<".pfile.">")
9328 endif
9329 let pfile= strpart(pfile,dirnamelen)
9330 let pfile= substitute(pfile,'^[/\\]','','e')
9331" call Decho("filename<".filename.">")
9332" call Decho("pfile <".pfile.">")
9333
9334 if w:netrw_liststyle == s:LONGLIST
9335 let sz = getfsize(filename)
9336 let fsz = strpart(" ",1,15-strlen(sz)).sz
9337 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
9338" call Decho("sz=".sz." fsz=".fsz)
9339 endif
9340
9341 if g:netrw_sort_by =~ "^t"
9342 " sort by time (handles time up to 1 quintillion seconds, US)
9343" call Decho("getftime(".filename.")=".getftime(filename))
9344 let t = getftime(filename)
9345 let ft = strpart("000000000000000000",1,18-strlen(t)).t
9346" call Decho("exe keepjumps put ='".ft.'/'.filename."'")
9347 let ftpfile= ft.'/'.pfile
9348 sil! keepj put=ftpfile
9349
9350 elseif g:netrw_sort_by =~ "^s"
9351 " sort by size (handles file sizes up to 1 quintillion bytes, US)
9352" call Decho("getfsize(".filename.")=".getfsize(filename))
9353 let sz = getfsize(filename)
9354 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
9355" call Decho("exe keepj put ='".fsz.'/'.filename."'")
9356 let fszpfile= fsz.'/'.pfile
9357 sil! keepj put =fszpfile
9358
9359 else
9360 " sort by name
9361" call Decho("exe keepjumps put ='".pfile."'")
9362 sil! keepj put=pfile
9363 endif
9364 endfor
9365
9366 " cleanup any windows mess at end-of-line
9367 sil! keepj g/^$/d
9368 sil! keepj %s/\r$//e
9369 call histdel("/",-1)
9370" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
9371 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9372
9373" call Dret("s:LocalListing")
9374endfun
9375
9376" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009377" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
9378fun! s:NetrwLocalExecute(cmd)
9379" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
9380 let ykeep= @@
9381 " sanity check
9382 if !executable(a:cmd)
9383 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
9384 let @@= ykeep
9385" call Dret("s:NetrwLocalExecute")
9386 return
9387 endif
9388
9389 let optargs= input(":!".a:cmd,"","file")
9390" call Decho("optargs<".optargs.">")
9391 let result= system(a:cmd.optargs)
Bram Moolenaara6878372014-03-22 21:02:50 +01009392" call Decho("result)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009393
9394 " strip any ansi escape sequences off
9395 let result = substitute(result,"\e\\[[0-9;]*m","","g")
9396
9397 " show user the result(s)
9398 echomsg result
9399 let @@= ykeep
9400
9401" call Dret("s:NetrwLocalExecute")
9402endfun
9403
9404" ---------------------------------------------------------------------
9405" s:NetrwLocalRename: rename a remote file or directory {{{2
9406fun! s:NetrwLocalRename(path) range
9407" call Dfunc("NetrwLocalRename(path<".a:path.">)")
9408
9409 " preparation for removing multiple files/directories
9410 let ykeep = @@
9411 let ctr = a:firstline
Bram Moolenaara6878372014-03-22 21:02:50 +01009412 let svpos = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009413
9414 " rename files given by the markfilelist
9415 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9416 for oldname in s:netrwmarkfilelist_{bufnr("%")}
9417" call Decho("oldname<".oldname.">")
9418 if exists("subfrom")
9419 let newname= substitute(oldname,subfrom,subto,'')
9420" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9421 else
9422 call inputsave()
9423 let newname= input("Moving ".oldname." to : ",oldname)
9424 call inputrestore()
9425 if newname =~ '^s/'
9426 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9427 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9428" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9429 let newname = substitute(oldname,subfrom,subto,'')
9430 endif
9431 endif
9432 call rename(oldname,newname)
9433 endfor
9434 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
9435
9436 else
9437
9438 " attempt to rename files/directories
9439 while ctr <= a:lastline
9440 exe "keepj ".ctr
9441
9442 " sanity checks
9443 if line(".") < w:netrw_bannercnt
9444 let ctr= ctr + 1
9445 continue
9446 endif
9447 let curword= s:NetrwGetWord()
9448 if curword == "./" || curword == "../"
9449 let ctr= ctr + 1
9450 continue
9451 endif
9452
9453 keepj norm! 0
9454 let oldname= s:ComposePath(a:path,curword)
9455" call Decho("oldname<".oldname.">")
9456
9457 call inputsave()
9458 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
9459 call inputrestore()
9460
9461 call rename(oldname,newname)
9462" call Decho("renaming <".oldname."> to <".newname.">")
9463
9464 let ctr= ctr + 1
9465 endwhile
9466 endif
9467
9468 " refresh the directory
9469" call Decho("refresh the directory listing")
9470 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009471 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009472 let @@= ykeep
9473
9474" call Dret("NetrwLocalRename")
9475endfun
9476
9477" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009478" s:NetrwLocalRm: {{{2
9479fun! s:NetrwLocalRm(path) range
9480" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
9481" call Decho("firstline=".a:firstline." lastline=".a:lastline)
9482
9483 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +01009484 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485 let ret = 0
9486 let all = 0
Bram Moolenaara6878372014-03-22 21:02:50 +01009487 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009488
9489 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9490 " remove all marked files
9491" call Decho("remove all marked files")
9492 for fname in s:netrwmarkfilelist_{bufnr("%")}
9493 let ok= s:NetrwLocalRmFile(a:path,fname,all)
9494 if ok =~ 'q\%[uit]' || ok == "no"
9495 break
9496 elseif ok =~ 'a\%[ll]'
9497 let all= 1
9498 endif
9499 endfor
9500 call s:NetrwUnMarkFile(1)
9501
9502 else
9503 " remove (multiple) files and directories
9504" call Decho("remove files in range [".a:firstline.",".a:lastline."]")
9505
9506 let ctr = a:firstline
9507 while ctr <= a:lastline
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009508 exe "keepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509
9510 " sanity checks
9511 if line(".") < w:netrw_bannercnt
9512 let ctr= ctr + 1
9513 continue
9514 endif
9515 let curword= s:NetrwGetWord()
9516 if curword == "./" || curword == "../"
9517 let ctr= ctr + 1
9518 continue
9519 endif
9520 let ok= s:NetrwLocalRmFile(a:path,curword,all)
9521 if ok =~ 'q\%[uit]' || ok == "no"
9522 break
9523 elseif ok =~ 'a\%[ll]'
9524 let all= 1
9525 endif
9526 let ctr= ctr + 1
9527 endwhile
9528 endif
9529
9530 " refresh the directory
9531" call Decho("bufname<".bufname("%").">")
9532 if bufname("%") != "NetrwMessage"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009533 keepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 keepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01009536 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009537
9538" call Dret("s:NetrwLocalRm")
9539endfun
9540
9541" ---------------------------------------------------------------------
9542" s:NetrwLocalRmFile: remove file fname given the path {{{2
9543" Give confirmation prompt unless all==1
9544fun! s:NetrwLocalRmFile(path,fname,all)
9545" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
9546
9547 let all= a:all
9548 let ok = ""
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009549 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550 let rmfile= s:ComposePath(a:path,a:fname)
9551" call Decho("rmfile<".rmfile.">")
9552
9553 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
9554 " attempt to remove file
9555" call Decho("attempt to remove file<".rmfile.">")
9556 if !all
9557 echohl Statement
9558 call inputsave()
9559 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9560 call inputrestore()
9561 echohl NONE
9562 if ok == ""
9563 let ok="no"
9564 endif
9565" call Decho("response: ok<".ok.">")
9566 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9567" call Decho("response: ok<".ok."> (after sub)")
9568 if ok =~ 'a\%[ll]'
9569 let all= 1
9570 endif
9571 endif
9572
9573 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00009574 let ret= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575" call Decho("errcode=".v:shell_error." ret=".ret)
9576 endif
9577
9578 else
9579 " attempt to remove directory
9580 if !all
9581 echohl Statement
9582 call inputsave()
9583 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9584 call inputrestore()
9585 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9586 if ok == ""
9587 let ok="no"
9588 endif
9589 if ok =~ 'a\%[ll]'
9590 let all= 1
9591 endif
9592 endif
9593 let rmfile= substitute(rmfile,'[\/]$','','e')
9594
9595 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009596" call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.shellescape(rmfile).')')
9597 call system(netrw#WinPath(g:netrw_localrmdir).' '.shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598" call Decho("v:shell_error=".v:shell_error)
9599
9600 if v:shell_error != 0
9601" call Decho("2nd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009602 let errcode= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009603" call Decho("errcode=".errcode)
9604
9605 if errcode != 0
9606 if has("unix")
9607" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009608 call system("rm ".shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009609 if v:shell_error != 0 && !exists("g:netrw_quiet")
9610 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
9611 let ok="no"
9612 endif
9613 elseif !exists("g:netrw_quiet")
9614 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
9615 let ok="no"
9616 endif
9617 endif
9618 endif
9619 endif
9620 endif
9621
9622" call Dret("s:NetrwLocalRmFile ".ok)
9623 return ok
9624endfun
9625
9626" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009627" Support Functions: {{{1
9628
Bram Moolenaar488c6512005-08-11 20:09:58 +00009629" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009630" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
9631" 0: marked file list of current buffer
9632" 1: marked file target
9633fun! netrw#Access(ilist)
9634 if a:ilist == 0
9635 if exists("s:netrwmarkfilelist_".bufnr('%'))
9636 return s:netrwmarkfilelist_{bufnr('%')}
9637 else
9638 return "no-list-buf#".bufnr('%')
9639 endif
9640 elseif a:ilist == 1
9641 return s:netrwmftgt
9642endfun
9643
9644" ------------------------------------------------------------------------
9645" netrw#RestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2
9646fun! netrw#RestorePosn(...)
9647" 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))
9648 let eikeep= &ei
9649 setl ei=all
9650 if expand("%") == "NetrwMessage"
9651 if exists("s:winBeforeErr")
9652 exe s:winBeforeErr."wincmd w"
9653 endif
9654 endif
9655
9656 if a:0 > 0
9657 exe "keepj ".a:1
9658 endif
9659
9660 " restore window
9661 if exists("w:netrw_winnr")
9662" call Decho("restore window: exe sil! ".w:netrw_winnr."wincmd w")
9663 exe "sil! ".w:netrw_winnr."wincmd w"
9664 endif
9665 if v:shell_error == 0
9666 " as suggested by Bram M: redraw on no error
9667 " allows protocol error messages to remain visible
9668" redraw!
9669 endif
9670
9671 " restore top-of-screen line
9672 if exists("w:netrw_hline")
9673" call Decho("restore topofscreen: exe keepj norm! ".w:netrw_hline."G0z")
9674 exe "keepj norm! ".w:netrw_hline."G0z\<CR>"
9675 endif
9676
9677 " restore position
9678 if exists("w:netrw_line") && exists("w:netrw_col")
9679" call Decho("restore posn: exe keepj norm! ".w:netrw_line."G0".w:netrw_col."|")
9680 exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
9681 endif
9682
9683 let &ei= eikeep
9684" call Dret("netrw#RestorePosn : line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
9685endfun
9686
9687" ---------------------------------------------------------------------
9688" netrw#RFC2396: converts %xx into characters {{{2
9689fun! netrw#RFC2396(fname)
9690" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
9691 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
9692" call Dret("netrw#RFC2396 ".fname)
9693 return fname
9694endfun
9695
9696" ---------------------------------------------------------------------
9697" netrw#SavePosn: saves position of cursor on screen {{{2
9698fun! netrw#SavePosn()
9699" call Dfunc("netrw#SavePosn() line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
9700 " Save current line and column
9701 let w:netrw_winnr= winnr()
9702 let w:netrw_line = line(".")
9703 let w:netrw_col = virtcol(".")
9704" call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col)
9705
9706 " Save top-of-screen line
9707 keepj norm! H0
9708 let w:netrw_hline= line(".")
9709
9710 " set up string holding position parameters
9711 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
9712
9713 keepj call netrw#RestorePosn()
9714" 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"))
9715 return ret
9716endfun
9717
9718" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009719" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
9720fun! netrw#WinPath(path)
9721" call Dfunc("netrw#WinPath(path<".a:path.">)")
9722 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
9723 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +01009724 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009725 " remove trailing slash (Win95)
9726 let path = substitute(path, '\(\\\|/\)$', '', 'g')
9727 " remove escaped spaces
9728 let path = substitute(path, '\ ', ' ', 'g')
9729 " convert slashes to backslashes
9730 let path = substitute(path, '/', '\', 'g')
9731 else
9732 let path= a:path
9733 endif
9734" call Dret("netrw#WinPath <".path.">")
9735 return path
9736endfun
9737
9738" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009739" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
9740fun! s:ComposePath(base,subdir)
9741" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
9742
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009743 if has("amiga")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009744" call Decho("amiga")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009745 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +00009746 if ec != '/' && ec != ':'
9747 let ret = a:base . "/" . a:subdir
9748 else
9749 let ret = a:base . a:subdir
9750 endif
9751
9752 elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
9753" call Decho("windows")
9754 let ret= a:subdir
9755
Bram Moolenaar5c736222010-01-06 20:54:52 +01009756 elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
9757" call Decho("windows")
9758 if a:base =~ '[/\\]$'
9759 let ret= a:base.a:subdir
9760 else
9761 let ret= a:base."/".a:subdir
9762 endif
9763
Bram Moolenaarc236c162008-07-13 17:41:49 +00009764 elseif a:base =~ '^\a\+://'
9765" call Decho("remote linux/macos")
9766 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
9767 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
9768 if a:subdir == '../'
9769 if curpath =~ '[^/]/[^/]\+/$'
9770 let curpath= substitute(curpath,'[^/]\+/$','','')
9771 else
9772 let curpath=""
9773 endif
9774 let ret= urlbase.curpath
9775 else
9776 let ret= urlbase.curpath.a:subdir
9777 endif
9778" call Decho("urlbase<".urlbase.">")
9779" call Decho("curpath<".curpath.">")
9780" call Decho("ret<".ret.">")
9781
9782 else
9783" call Decho("local linux/macos")
9784 let ret = substitute(a:base."/".a:subdir,"//","/","g")
9785 if a:base =~ '^//'
9786 " keeping initial '//' for the benefit of network share listing support
9787 let ret= '/'.ret
9788 endif
9789 let ret= simplify(ret)
9790 endif
9791
9792" call Dret("s:ComposePath ".ret)
9793 return ret
9794endfun
9795
9796" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00009797" s:FileReadable: o/s independent filereadable {{{2
9798fun! s:FileReadable(fname)
9799" call Dfunc("s:FileReadable(fname<".a:fname.">)")
9800
9801 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01009802 let ret= filereadable(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/',''))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009803 else
9804 let ret= filereadable(a:fname)
9805 endif
9806
9807" call Dret("s:FileReadable ".ret)
9808 return ret
9809endfun
9810
9811" ---------------------------------------------------------------------
9812" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
9813" Places correct suffix on end of temporary filename,
9814" using the suffix provided with fname
9815fun! s:GetTempfile(fname)
9816" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
9817
9818 if !exists("b:netrw_tmpfile")
9819 " get a brand new temporary filename
9820 let tmpfile= tempname()
9821" call Decho("tmpfile<".tmpfile."> : from tempname()")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822
Bram Moolenaarc236c162008-07-13 17:41:49 +00009823 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009824" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825
Bram Moolenaar9964e462007-05-05 17:54:07 +00009826 " sanity check -- does the temporary file's directory exist?
9827 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaara6878372014-03-22 21:02:50 +01009828" 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 +02009829 keepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009830" call Dret("s:GetTempfile getcwd<".getcwd().">")
9831 return ""
9832 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833
Bram Moolenaar9964e462007-05-05 17:54:07 +00009834 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar5c736222010-01-06 20:54:52 +01009835 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#NetrwBrowseX()
Bram Moolenaar9964e462007-05-05 17:54:07 +00009836" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837
Bram Moolenaar9964e462007-05-05 17:54:07 +00009838 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009840 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009841 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 if !exists("+shellslash") || !&ssl
9843 let tmpfile = substitute(tmpfile,'/','\','g')
9844 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00009845 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +00009847 endif
9848 let b:netrw_tmpfile= tmpfile
9849" call Decho("o/s dependent fixed tempname<".tmpfile.">")
9850 else
9851 " re-use temporary filename
9852 let tmpfile= b:netrw_tmpfile
9853" call Decho("tmpfile<".tmpfile."> re-using")
9854 endif
9855
9856 " use fname's suffix for the temporary file
9857 if a:fname != ""
9858 if a:fname =~ '\.[^./]\+$'
9859" call Decho("using fname<".a:fname.">'s suffix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009860 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00009861 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009862 elseif a:fname =~ '.txz$'
9863 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009864 else
9865 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
9866 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00009867" call Decho("suffix<".suffix.">")
9868 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
9869" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)")
9870 let tmpfile .= suffix
9871" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
9872 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
9873 endif
9874 endif
9875
Bram Moolenaara6878372014-03-22 21:02:50 +01009876" 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 +00009877" call Dret("s:GetTempfile <".tmpfile.">")
9878 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +00009880
9881" ---------------------------------------------------------------------
9882" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +00009883" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +00009884fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00009886 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user.s:machine,'')
9887 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00009888 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009889 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00009890 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +00009891 else
9892 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
9893 endif
9894" call Dret("s:MakeSshCmd <".sshcmd.">")
9895 return sshcmd
9896endfun
9897
9898" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009899" s:NetrwBMShow: {{{2
9900fun! s:NetrwBMShow()
9901" call Dfunc("s:NetrwBMShow()")
9902 redir => bmshowraw
9903 menu
9904 redir END
9905 let bmshowlist = split(bmshowraw,'\n')
9906 if bmshowlist != []
9907 let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"')
9908 if bmshowfuncs != []
9909 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
9910 if bmshowfunc =~ '^call.*BMShow()'
Bram Moolenaaradc21822011-04-01 18:03:16 +02009911 exe "sil! keepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +00009912 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009914 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00009915" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
9916endfun
9917
9918" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02009919" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
9920fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009921 if !exists("w:netrw_liststyle")
9922 let w:netrw_liststyle= g:netrw_liststyle
9923 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02009924" 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 +02009925
9926 if &ft != "netrw"
9927 " if the current window isn't a netrw directory listing window, then use user cursorline/column
9928 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaar15146672011-10-20 22:22:38 +02009929" call Decho("case ft!=netrw: use user cul,cuc")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009930 let &l:cursorline = s:netrw_usercul
9931 let &l:cursorcolumn = s:netrw_usercuc
9932
9933 elseif g:netrw_cursor == 4
9934 " all styles: cursorline, cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +02009935" call Decho("case g:netrw_cursor==4: setl cul cuc")
9936 setl cursorline
9937 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +02009938
9939 elseif g:netrw_cursor == 3
9940 " thin-long-tree: cursorline, user's cursorcolumn
9941 " wide : cursorline, cursorcolumn
9942 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +02009943" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc")
Bram Moolenaar15146672011-10-20 22:22:38 +02009944 setl cursorline
9945 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +02009946 else
Bram Moolenaarff034192013-04-24 18:51:19 +02009947" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)")
Bram Moolenaar15146672011-10-20 22:22:38 +02009948 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02009949 let &l:cursorcolumn = s:netrw_usercuc
9950 endif
9951
9952 elseif g:netrw_cursor == 2
9953 " thin-long-tree: cursorline, user's cursorcolumn
9954 " wide : cursorline, user's cursorcolumn
Bram Moolenaarff034192013-04-24 18:51:19 +02009955" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009956 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +02009957 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02009958
9959 elseif g:netrw_cursor == 1
9960 " thin-long-tree: user's cursorline, user's cursorcolumn
9961 " wide : cursorline, user's cursorcolumn
9962 let &l:cursorcolumn = s:netrw_usercuc
9963 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +02009964" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009965 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +02009966 else
Bram Moolenaar15146672011-10-20 22:22:38 +02009967" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009968 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009969 endif
9970
9971 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02009972 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +02009973" call Decho("default: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02009974 let &l:cursorline = s:netrw_usercul
9975 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009976 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02009977
9978" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009979endfun
9980
9981" ---------------------------------------------------------------------
9982" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
9983fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009984" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02009985 if exists("s:netrw_usercul")
9986 let &l:cursorline = s:netrw_usercul
9987 endif
9988 if exists("s:netrw_usercuc")
9989 let &l:cursorcolumn = s:netrw_usercuc
9990 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009991" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
9992endfun
9993
9994" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00009995" s:NetrwDelete: Deletes a file. {{{2
9996" Uses Steve Hall's idea to insure that Windows paths stay
9997" acceptable. No effect on Unix paths.
9998" Examples of use: let result= s:NetrwDelete(path)
9999fun! s:NetrwDelete(path)
10000" call Dfunc("s:NetrwDelete(path<".a:path.">)")
10001
Bram Moolenaar5c736222010-01-06 20:54:52 +010010002 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010003 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
10004 if exists("+shellslash")
10005 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020010006 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000010007 let result = delete(path)
10008 let &shellslash = sskeep
10009 else
10010" call Decho("exe let result= ".a:cmd."('".path."')")
10011 let result= delete(path)
10012 endif
10013 else
10014" call Decho("let result= delete(".path.")")
10015 let result= delete(path)
10016 endif
10017 if result < 0
Bram Moolenaaradc21822011-04-01 18:03:16 +020010018 keepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010019 endif
10020
10021" call Dret("s:NetrwDelete ".result)
10022 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023endfun
10024
10025" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010026" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010010027fun! s:NetrwEnew(...)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010028" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010029" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010030
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 " grab a function-local-variable copy of buffer variables
Bram Moolenaara6878372014-03-22 21:02:50 +010010032" call Decho("make function-local copy of netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010033 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
10034 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
10035 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
10036 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
10037 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
10038 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
10039 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
10040 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
10041 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
10042 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
10043 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
10044 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
10045 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
10046 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
10047 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
10048 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
10049
Bram Moolenaaradc21822011-04-01 18:03:16 +020010050 keepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010051" call Decho("generate a buffer with keepjumps keepalt enew!")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010052 let netrw_keepdiff= &l:diff
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010053 keepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010054 let &l:diff= netrw_keepdiff
Bram Moolenaara6878372014-03-22 21:02:50 +010010055" call Decho("bufnr($)=".bufnr("$")." winnr($)=".winnr("$"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020010056 keepj call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010057
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara6878372014-03-22 21:02:50 +010010059" call Decho("copy function-local variables back to buffer netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010060 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
10061 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
10062 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
10063 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
10064 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
10065 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
10066 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
10067 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
10068 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
10069 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
10070 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
10071 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
10072 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
10073 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
10074 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
10075 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
10076
Bram Moolenaar5c736222010-01-06 20:54:52 +010010077 if a:0 > 0
10078 let b:netrw_curdir= a:1
10079 if b:netrw_curdir =~ '/$'
10080 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10081 file NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +010010082 setl bt=nowrite noswf bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020010083 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
10084 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010010085 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010086 exe "sil! keepalt file ".fnameescape(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010087 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010088 endif
10089 endif
10090
Bram Moolenaar8d043172014-01-23 14:24:41 +010010091" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010092endfun
10093
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010094" ---------------------------------------------------------------------
10095" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
10096fun! s:NetrwInsureWinVars()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010097" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010098 if !exists("w:netrw_liststyle")
10099 let curbuf = bufnr("%")
10100 let curwin = winnr()
10101 let iwin = 1
10102 while iwin <= winnr("$")
10103 exe iwin."wincmd w"
10104 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
10105 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
10106 let winvars= w:
10107 break
10108 endif
10109 let iwin= iwin + 1
10110 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020010111 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010112 if exists("winvars")
10113" call Decho("copying w#".iwin." window variables to w#".curwin)
10114 for k in keys(winvars)
10115 let w:{k}= winvars[k]
10116 endfor
10117 endif
10118 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010119" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010120endfun
10121
Bram Moolenaara6878372014-03-22 21:02:50 +010010122" ---------------------------------------------------------------------
10123" s:NetrwLcd: handles changing the (local) directory {{{2
10124fun! s:NetrwLcd(newdir)
10125" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
10126
10127 try
10128 exe 'keepj sil lcd '.fnameescape(a:newdir)
10129 catch /^Vim\%((\a\+)\)\=:E344/
10130 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
10131 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
10132 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
10133 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
10134 " forward slashes by earlier code; so check for both.
10135 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
10136 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
10137 let dirname = '\'
10138 exe 'keepj sil lcd '.fnameescape(dirname)
10139 endif
10140 endif
10141 catch /^Vim\%((\a\+)\)\=:E472/
10142 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
10143 if exists("w:netrw_prvdir")
10144 let a:newdir= w:netrw_prvdir
10145 else
10146 call s:NetrwOptionRestore("w:")
10147" call Decho("setl noma nomod nowrap")
10148 setl noma nomod nowrap
10149" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
10150 let a:newdir= dirname
10151" call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
10152 return
10153 endif
10154 endtry
10155
10156" call Dret("s:NetrwLcd")
10157endfun
10158
Bram Moolenaar9964e462007-05-05 17:54:07 +000010159" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
10161" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
10162fun! s:NetrwSaveWordPosn()
10163" call Dfunc("NetrwSaveWordPosn()")
10164 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
10165" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
10166endfun
10167
10168" ---------------------------------------------------------------------
10169" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
10170" changed sorting, etc. Also see s:NetrwSaveWordPosn().
10171fun! s:NetrwRestoreWordPosn()
10172" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010173 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010174" call Dret("NetrwRestoreWordPosn")
10175endfun
10176
10177" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010178" s:RestoreBufVars: {{{2
10179fun! s:RestoreBufVars()
10180" call Dfunc("s:RestoreBufVars()")
10181
10182 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
10183 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
10184 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
10185 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
10186 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
10187 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
10188
10189" call Dret("s:RestoreBufVars")
10190endfun
10191
10192" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010193" s:RemotePathAnalysis: {{{2
10194fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020010195" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010196
Bram Moolenaara6878372014-03-22 21:02:50 +010010197 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010010198 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010199 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010010200 let s:user = substitute(a:dirname,dirpat,'\3','')
10201 let s:machine = substitute(a:dirname,dirpat,'\4','')
10202 let s:port = substitute(a:dirname,dirpat,'\5','')
10203 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010204 let s:fname = substitute(a:dirname,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010010205 if s:machine =~ '@'
10206 let dirpat = '^\(.*\)@\(.\{-}\)$'
10207 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
10208 let s:machine = substitute(s:machine,dirpat,'\2','')
10209 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010210
10211" call Decho("set up s:method <".s:method .">")
10212" call Decho("set up s:user <".s:user .">")
10213" call Decho("set up s:machine<".s:machine.">")
10214" call Decho("set up s:port <".s:port.">")
10215" call Decho("set up s:path <".s:path .">")
10216" call Decho("set up s:fname <".s:fname .">")
10217
10218" call Dret("s:RemotePathAnalysis")
10219endfun
10220
10221" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010222" s:RemoteSystem: runs a command on a remote host using ssh {{{2
10223" Returns status
10224" Runs system() on
10225" [cd REMOTEDIRPATH;] a:cmd
10226" Note that it doesn't do shellescape(a:cmd)!
10227fun! s:RemoteSystem(cmd)
10228" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
10229 if !executable(g:netrw_ssh_cmd)
Bram Moolenaaradc21822011-04-01 18:03:16 +020010230 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 +000010231 elseif !exists("b:netrw_curdir")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010232 keepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010233 else
10234 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
10235 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
10236 if remotedir != ""
10237 let cmd= cmd.' cd '.shellescape(remotedir).";"
10238 else
10239 let cmd= cmd.' '
10240 endif
10241 let cmd= cmd.a:cmd
10242" call Decho("call system(".cmd.")")
10243 let ret= system(cmd)
10244 endif
10245" call Dret("s:RemoteSystem ".ret)
10246 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000010247endfun
10248
10249" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010250" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010251fun! s:RestoreWinVars()
10252" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000010253 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010254 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
10255 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
10256 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
10257 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
10258 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
10259 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
10260 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
10261 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
10262 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
10263 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
10264 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
10265 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000010266 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
10267 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010268 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
10269 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
10270 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
10271" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000010272endfun
10273
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010274" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010275" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
10276"
10277" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
10278" is true) and a command, :Rexplore, which call this function.
10279"
10280" s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir()
10281fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020010282 if exists("s:netrwdrag")
10283 return
10284 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020010285" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +010010286" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">")
10287
10288 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
10289" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">")
10290 exe "e ".w:netrw_rexfile
10291 unlet w:netrw_rexfile
10292" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020010293 return
10294 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010295
10296 " record current file so :Rex can return to it from netrw
10297 let w:netrw_rexfile= expand("%")
10298
10299 if !exists("w:netrw_rexlocal")
10300" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft.")")
10301 return
10302 endif
10303" 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 +020010304 if w:netrw_rexlocal
10305 keepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010306 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020010307 keepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020010309 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010010310 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020010311 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010312 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010313" call Decho("restore posn, then unlet s:rexposn_".bufnr('%'))
10314 keepj call netrw#RestorePosn(s:rexposn_{bufnr('%')})
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010315 unlet s:rexposn_{bufnr('%')}
10316 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010317" call Decho("s:rexposn_".bufnr('%')." doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010318 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010319
Bram Moolenaar5c736222010-01-06 20:54:52 +010010320 if exists("s:explore_match")
10321 exe "2match netrwMarkFile /".s:explore_match."/"
10322 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010323
10324" 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)
10325" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010326endfun
10327
10328" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010010329" s:SaveBufVars: save selected b: variables to s: variables {{{2
10330" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000010331fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010332" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010333
10334 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
10335 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
10336 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
10337 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
10338 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
10339 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
10340
10341" call Dret("s:SaveBufVars")
10342endfun
10343
10344" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010345" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010346fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010347" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000010348 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
10349 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
10350 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
10351 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
10352 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
10353 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
10354 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
10355 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
10356 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
10357 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
10358 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
10359 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
10360 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
10361 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
10362 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
10363 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
10364 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
10365 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
10366" call Dret("s:SaveWinVars")
10367endfun
10368
10369" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010371" To allow separate windows to have their own activities, such as
10372" Explore **/pattern, several variables have been made window-oriented.
10373" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010374" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010375" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010376fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010010377" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000010378 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
10379 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
10380 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
10381 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
10382 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
10383 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
10384 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
10385 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
10386 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
10387 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
10388" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010389endfun
10390
10391" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392" s:SetRexDir: set directory for :Rexplore {{{2
10393fun! s:SetRexDir(islocal,dirname)
10394" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010395 let w:netrw_rexdir = a:dirname
10396 let w:netrw_rexlocal = a:islocal
Bram Moolenaar97d62492012-11-15 21:28:22 +010010397" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398endfun
10399
10400" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010010401" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
10402" Solution from Nicolai Weibull, vim docs (:help strlen()),
10403" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010405" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
10406
10407 if v:version >= 703 && exists("*strdisplaywidth")
10408 let ret= strdisplaywidth(a:x)
10409
10410 elseif type(g:Align_xstrlen) == 1
10411 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
10412 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
10413
10414 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 " number of codepoints (Latin a + combining circumflex is two codepoints)
10416 " (comment from TM, solution from NW)
10417 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010418
10419 elseif g:Align_xstrlen == 2
10420 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
10422 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010423 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
10424
10425 elseif g:Align_xstrlen == 3
10426 " virtual length (counting, for instance, tabs as anything between 1 and
10427 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428 " preceded by lam, one otherwise, etc.)
10429 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010430 let modkeep= &l:mod
10431 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 call setline(line("."),a:x)
10433 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010434 d
Bram Moolenaarff034192013-04-24 18:51:19 +020010435 keepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010010436 let &l:mod= modkeep
10437
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438 else
10439 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010010440 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010442" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 return ret
10444endfun
10445
10446" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447" s:TreeListMove: {{{2
10448fun! s:TreeListMove(dir)
10449" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
10450 let curline = getline('.')
10451 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
10452 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
10453 let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010010454 let indentm1 = substitute(curindent,'^'.s:treedepthstring.' ','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455" call Decho("prvline <".prvline."> #".line(".")-1)
10456" call Decho("curline <".curline."> #".line("."))
10457" call Decho("nxtline <".nxtline."> #".line(".")+1)
10458" call Decho("curindent<".curindent.">")
10459" call Decho("indentm1 <".indentm1.">")
10460
10461 if curline !~ '/$'
10462" call Decho('regfile')
10463 if a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010464 keepj norm! 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010465 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000010466" call Decho("regfile srch back: ".nl)
10467 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010468 keepj norm! $
Bram Moolenaar8d043172014-01-23 14:24:41 +010010469 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470" call Decho("regfile srch fwd: ".nl)
10471 endif
10472
10473 elseif a:dir == '[' && prvline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010474 keepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 let curline= line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010476 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','bWe') " search backwards From directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477" call Decho("dir srch back ind: ".nl)
10478 if nl != 0
10479 if line(".") == curline-1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010480 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481" call Decho("dir srch back ind-1: ".nl)
10482 endif
10483 endif
10484
10485 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010486 keepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 let curline = line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010488 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','We') " search forwards from directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489" call Decho("dir srch fwd ind: ".nl)
10490 if nl != 0
10491 if line(".") == curline+1
Bram Moolenaar8d043172014-01-23 14:24:41 +010010492 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493" call Decho("dir srch fwd ind-1: ".nl)
10494 endif
10495 endif
10496
10497 endif
10498
10499" call Dret("s:TreeListMove")
10500endfun
10501
10502" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010503" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
10504" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
10505" can't be called except via emenu. But due to locale, that menu line may not be called
10506" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
10507fun! s:UpdateBuffersMenu()
10508" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010509 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000010510 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020010511 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000010512 catch /^Vim\%((\a\+)\)\=:E/
10513 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +020010514 sil keepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000010515 endtry
10516 endif
10517" call Dret("s:UpdateBuffersMenu")
10518endfun
10519
10520" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020010522" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010523fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000010524" call Dfunc("s:UseBufWinVars()")
10525 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010526 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
10527 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
10528 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
10529 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
10530 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
10531 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
10532 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
10533 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
10534 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 +000010535" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000010536endfun
10537
Bram Moolenaar1afcace2005-11-25 19:54:28 +000010538" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010539" Settings Restoration: {{{1
Bram Moolenaar83bab712005-08-01 21:58:57 +000010540let &cpo= s:keepcpo
10541unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000010542
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +000010544" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545" vim:ts=8 fdm=marker