blob: 42439a57d36c965c5d8c8b1046dc9eb5cb57161d [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 Moolenaar8feef4f2015-01-07 16:57:10 +01003" Date: Jan 05, 2015
4" Version: 153
Bram Moolenaarff034192013-04-24 18:51:19 +02005" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaar8d043172014-01-23 14:24:41 +01007" Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +00008" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000012" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000013" expressed or implied. By using this plugin, you agree that
14" in no event will the copyright holder be liable for any damages
15" resulting from the use of this software.
Bram Moolenaar446cb832008-06-24 21:56:24 +000016"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000017"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000018" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" (James 1:22 RSV)
20" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000021" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022if &cp || exists("g:loaded_netrw")
23 finish
24endif
Bram Moolenaar13600302014-05-22 18:26:40 +020025if v:version < 704 || !has("patch213")
26 if !exists("s:needpatch213")
27 echo "***sorry*** this version of netrw requires vim v7.4 with patch 213"
28 endif
29 let s:needpatch213= 1
30 finish
31endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010032let g:loaded_netrw = "v153"
Bram Moolenaar9964e462007-05-05 17:54:07 +000033if !exists("s:NOTE")
34 let s:NOTE = 0
35 let s:WARNING = 1
36 let s:ERROR = 2
37endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000038
Bram Moolenaar1afcace2005-11-25 19:54:28 +000039let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010040setl cpo&vim
41"let g:dechofuncname=1
Bram Moolenaar8d043172014-01-23 14:24:41 +010042"DechoRemOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000043"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw)
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000045" ======================
46" Netrw Variables: {{{1
47" ======================
48
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020050" netrw#ErrorMsg: {{{2
51" 0=note = s:NOTE
52" 1=warning = s:WARNING
53" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010054" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
55" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
56" (this function can optionally take a list of messages)
57" May 15, 2014 : max errnum currently is 98
Bram Moolenaar5b435d62012-04-05 17:33:26 +020058fun! netrw#ErrorMsg(level,msg,errnum)
59" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
60
61 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020062" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020063 return
64 endif
65
66 if a:level == 1
67 let level= "**warning** (netrw) "
68 elseif a:level == 2
69 let level= "**error** (netrw) "
70 else
71 let level= "**note** (netrw) "
72 endif
73" call Decho("level=".level)
74
75 if g:netrw_use_errorwindow
76 " (default) netrw creates a one-line window to show error/warning
77 " messages (reliably displayed)
78
79 " record current window number for NetrwRestorePosn()'s benefit
80 let s:winBeforeErr= winnr()
81" call Decho("s:winBeforeErr=".s:winBeforeErr)
82
83 " getting messages out reliably is just plain difficult!
84 " This attempt splits the current window, creating a one line window.
85 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
86" call Decho("write to NetrwMessage buffer")
87 exe bufwinnr("NetrwMessage")."wincmd w"
88" call Decho("setl ma noro")
89 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010090 if type(a:msg) == 3
91 for msg in a:msg
92 NetrwKeepj call setline(line("$")+1,level.msg)
93 endfor
94 else
95 NetrwKeepj call setline(line("$")+1,level.a:msg)
96 endif
97 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +020098 else
99" call Decho("create a NetrwMessage buffer window")
100 bo 1split
101 sil! call s:NetrwEnew()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100102 sil! NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100104 NetrwKeepj file NetrwMessage
Bram Moolenaarff034192013-04-24 18:51:19 +0200105" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100107 if type(a:msg) == 3
108 for msg in a:msg
109 NetrwKeepj call setline(line("$")+1,level.msg)
110 endfor
111 else
112 NetrwKeepj call setline(line("$"),level.a:msg)
113 endif
114 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 endif
116" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr())
117 if &fo !~ '[ta]'
118 syn clear
119 syn match netrwMesgNote "^\*\*note\*\*"
120 syn match netrwMesgWarning "^\*\*warning\*\*"
121 syn match netrwMesgError "^\*\*error\*\*"
122 hi link netrwMesgWarning WarningMsg
123 hi link netrwMesgError Error
124 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100125" call Decho("setl noma ro bh=wipe")
Bram Moolenaar13600302014-05-22 18:26:40 +0200126 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127
128 else
129 " (optional) netrw will show messages using echomsg. Even if the
130 " message doesn't appear, at least it'll be recallable via :messages
131" redraw!
132 if a:level == s:WARNING
133 echohl WarningMsg
134 elseif a:level == s:ERROR
135 echohl Error
136 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100137
138 if type(a:msg) == 3
139 for msg in a:msg
140 echomsg level.msg
141 endfor
142 else
143 echomsg level.a:msg
144 endif
145
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146" call Decho("echomsg ***netrw*** ".a:msg)
147 echohl None
148 endif
149
150" call Dret("netrw#ErrorMsg")
151endfun
152
153" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100154" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100155" Loosely, varname = value.
156fun s:NetrwInit(varname,value)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200157" call Decho("varname<".a:varname."> value=".a:value)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100158 if !exists(a:varname)
159 if type(a:value) == 0
160 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200161 elseif type(a:value) == 1 && a:value =~ '^[{[]'
162 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100163 elseif type(a:value) == 1
164 exe "let ".a:varname."="."'".a:value."'"
165 else
166 exe "let ".a:varname."=".a:value
167 endif
168 endif
169endfun
170
171" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000172" Netrw Constants: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100173call s:NetrwInit("g:netrw_dirhist_cnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000174if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100175 call s:NetrwInit("s:THINLIST",0)
176 call s:NetrwInit("s:LONGLIST",1)
177 call s:NetrwInit("s:WIDELIST",2)
178 call s:NetrwInit("s:TREELIST",3)
179 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000180endif
181
182" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000183" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200184call s:NetrwInit("g:netrw_use_errorwindow",1)
185
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000186if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100187 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000188 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 elseif executable("curl")
190 let g:netrw_dav_cmd = "curl"
191 else
192 let g:netrw_dav_cmd = ""
193 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000195if !exists("g:netrw_fetch_cmd")
196 if executable("fetch")
197 let g:netrw_fetch_cmd = "fetch -o"
198 else
199 let g:netrw_fetch_cmd = ""
200 endif
201endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100202if !exists("g:netrw_file_cmd")
203 if executable("elinks")
204 call s:NetrwInit("g:netrw_file_cmd","elinks")
205 elseif executable("links")
206 call s:NetrwInit("g:netrw_file_cmd","links")
207 endif
208endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000209if !exists("g:netrw_ftp_cmd")
210 let g:netrw_ftp_cmd = "ftp"
211endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200212let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200213if !exists("g:netrw_ftp_options")
214 let g:netrw_ftp_options= "-i -n"
215endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000216if !exists("g:netrw_http_cmd")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000217 if executable("elinks")
218 let g:netrw_http_cmd = "elinks"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100219 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000220 elseif executable("links")
221 let g:netrw_http_cmd = "links"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100222 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000223 elseif executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100224 let g:netrw_http_cmd = "curl"
225 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100227 let g:netrw_http_cmd = "wget"
228 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000229 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100230 let g:netrw_http_cmd = "fetch"
231 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000232 else
233 let g:netrw_http_cmd = ""
234 endif
235endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100236call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100237call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100238call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
239call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200240if !exists("g:netrw_scp_cmd")
241 if executable("scp")
242 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
243 elseif executable("pscp")
244 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
245 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
246 else
247 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
248 endif
249 else
250 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
251 endif
252endif
253
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
255call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000257if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000258 \ && exists("g:netrw_use_nt_rcp")
259 \ && g:netrw_use_nt_rcp
260 \ && executable( $SystemRoot .'/system32/rcp.exe')
261 let s:netrw_has_nt_rcp = 1
262 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000263else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000264 let s:netrw_has_nt_rcp = 0
265 let s:netrw_rcpmode = ''
266endif
267
268" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000269" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000270" Cygwin Detection ------- {{{3
271if !exists("g:netrw_cygwin")
272 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100273 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000274 let g:netrw_cygwin= 1
275 else
276 let g:netrw_cygwin= 0
277 endif
278 else
279 let g:netrw_cygwin= 0
280 endif
281endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000282" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100283call s:NetrwInit("g:netrw_alto" , &sb)
284call s:NetrwInit("g:netrw_altv" , &spr)
285call s:NetrwInit("g:netrw_banner" , 1)
286call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200287call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100288call s:NetrwInit("g:netrw_chgwin" , -1)
289call s:NetrwInit("g:netrw_compress" , "gzip")
290call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200291if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
292 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
293 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000294endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200295call s:NetrwInit("g:netrw_cursor" , 2)
296let s:netrw_usercul = &cursorline
297let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar8d043172014-01-23 14:24:41 +0100298call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000299" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200300call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100301call s:NetrwInit("g:netrw_dirhist_cnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200302call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100303call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200304call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100305call s:NetrwInit("g:netrw_fastbrowse" , 1)
306call 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 +0000307if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000308 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
309 let g:netrw_ftp_list_cmd = "ls -lF"
310 let g:netrw_ftp_timelist_cmd = "ls -tlF"
311 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000312 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000313 let g:netrw_ftp_list_cmd = "dir"
314 let g:netrw_ftp_timelist_cmd = "dir"
315 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000316 endif
317endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100318call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000319" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000321if !exists("g:netrw_ignorenetrc")
322 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
323 let g:netrw_ignorenetrc= 1
324 else
325 let g:netrw_ignorenetrc= 0
326 endif
327endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000329if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000330 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000331 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200332 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000333 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
334 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100335 if exists("g:netrw_list_cmd_options")
336 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
337 else
338 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
339 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000340 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200341 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100342 if exists("g:netrw_list_cmd_options")
343 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
344 else
345 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
346 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000347 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100348" call Decho(g:netrw_ssh_cmd." is not executable")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000349 let g:netrw_list_cmd= ""
350 endif
351endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100352call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000353" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200354if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200355 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200356 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
357endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100358if !exists("g:netrw_localcmdshell")
359 let g:netrw_localcmdshell= ""
360endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000361if !exists("g:netrw_localcopycmd")
362 if has("win32") || has("win95") || has("win64") || has("win16")
363 if g:netrw_cygwin
364 let g:netrw_localcopycmd= "cp"
365 else
Bram Moolenaar13600302014-05-22 18:26:40 +0200366 let g:netrw_localcopycmd= expand("$COMSPEC")." /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000367 endif
368 elseif has("unix") || has("macunix")
369 let g:netrw_localcopycmd= "cp"
370 else
371 let g:netrw_localcopycmd= ""
372 endif
373endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100374if !exists("g:netrw_localcopydircmd")
375 if has("win32") || has("win95") || has("win64") || has("win16")
376 if g:netrw_cygwin
377 let g:netrw_localcopydircmd= "cp -R"
378 else
379 let g:netrw_localcopycmd= expand("$COMSPEC")." /c xcopy /e /c /h /i /k"
380 endif
381 elseif has("unix") || has("macunix")
382 let g:netrw_localcopydircmd= "cp -R"
383 else
384 let g:netrw_localcopycmd= ""
385 endif
386endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200387if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100388 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200389 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
390endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200391if has("win32") || has("win95") || has("win64") || has("win16")
392 if g:netrw_cygwin
393 call s:NetrwInit("g:netrw_localmkdir","mkdir")
394 else
395 let g:netrw_localmkdir= expand("$COMSPEC")." /c mkdir"
396 endif
397else
398 call s:NetrwInit("g:netrw_localmkdir","mkdir")
399endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200400call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200401if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200402 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200403 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
404endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405if !exists("g:netrw_localmovecmd")
406 if has("win32") || has("win95") || has("win64") || has("win16")
407 if g:netrw_cygwin
408 let g:netrw_localmovecmd= "mv"
409 else
Bram Moolenaar13600302014-05-22 18:26:40 +0200410 let g:netrw_localmovecmd= expand("$COMSPEC")." /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000411 endif
412 elseif has("unix") || has("macunix")
413 let g:netrw_localmovecmd= "mv"
414 else
415 let g:netrw_localmovecmd= ""
416 endif
417endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200418if exists("g:netrw_local_rmdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200419 let g:netrw_localrmdir= g:netrw_local_rmdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200420 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
421endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200422if has("win32") || has("win95") || has("win64") || has("win16")
423 if g:netrw_cygwin
424 call s:NetrwInit("g:netrw_localrmdir","rmdir")
425 else
426 let g:netrw_localrmdir= expand("$COMSPEC")." /c rmdir"
427 endif
428else
429 call s:NetrwInit("g:netrw_localrmdir","rmdir")
430endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100431call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
432" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000433if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000434 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000435endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000436if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000437 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
438endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000439" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100440call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
441call s:NetrwInit("g:netrw_maxfilenamelen", 32)
442call s:NetrwInit("g:netrw_menu" , 1)
443call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200444call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~ '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100445call s:NetrwInit("g:netrw_retmap" , 0)
446if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
447 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
448elseif has("win32") || has("win95") || has("win64") || has("win16")
449 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
450else
451 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000452endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100453call s:NetrwInit("g:netrw_preview" , 0)
454call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100455call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100456call s:NetrwInit("g:netrw_sshport" , "-p")
457call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
458call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
459call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100460call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
461" Default values - q-s ---------- {{{3
462call s:NetrwInit("g:netrw_quickhelp",0)
463let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100464 \ "(create new) %:file d:directory",
465 \ "(windows split&open) o:horz v:vert p:preview",
466 \ "i:style qf:file info O:obtain r:reverse",
467 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
468 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
469 \ "(history) qb:list u:go up U:go down",
470 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100471" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
472call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100473if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
474 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
475else
476 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
477endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100478call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
479call s:NetrwInit("g:netrw_sort_options" , "")
480call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000481if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200483 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484 else
485 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000487endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_special_syntax" , 0)
489call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100490call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000491" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200493if !exists("g:netrw_xstrlen")
494 if exists("g:Align_xstrlen")
495 let g:netrw_xstrlen= g:Align_xstrlen
496 elseif exists("g:drawit_xstrlen")
497 let g:netrw_xstrlen= g:drawit_xstrlen
498 elseif &enc == "latin1" || !has("multi_byte")
499 let g:netrw_xstrlen= 0
500 else
501 let g:netrw_xstrlen= 1
502 endif
503endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100505call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200506call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200507if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000508" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000509" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200511if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200512 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200513else
Bram Moolenaarff034192013-04-24 18:51:19 +0200514 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200515endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200516call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100517call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
518call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100519if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100520 let s:treedepthstring= "│ "
521else
522 let s:treedepthstring= "| "
523endif
Bram Moolenaar8299df92004-07-10 09:47:34 +0000524
525" BufEnter event ignored by decho when following variable is true
526" Has a side effect that doau BufReadPost doesn't work, so
527" files read by network transfer aren't appropriately highlighted.
528"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529
Bram Moolenaaradc21822011-04-01 18:03:16 +0200530" ======================
531" Netrw Initialization: {{{1
532" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200533if 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 +0100534" call Decho("installed beval events")
Bram Moolenaara6878372014-03-22 21:02:50 +0100535 let &l:bexpr = "netrw#BalloonHelp()"
536 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100537 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
538 au VimEnter * let s:initbeval= &beval
539"else " Decho
540" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700") | endif
541" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval") | endif
542" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists") | endif
543" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists") | endif
544" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting") | endif
545" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists") | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200546endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200547au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200548
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100549if g:netrw_keepj =~ "keepj"
550 com! -nargs=* NetrwKeepj keepj <args>
551else
552 let g:netrw_keepj= ""
553 com! -nargs=* NetrwKeepj <args>
554endif
555
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000556" ==============================
557" Netrw Utility Functions: {{{1
558" ==============================
559
Bram Moolenaaradc21822011-04-01 18:03:16 +0200560" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100561" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100562if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
563" call Decho("loading netrw#BalloonHelp()")
Bram Moolenaara6878372014-03-22 21:02:50 +0100564 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100565 if &ft != "netrw"
566 return ""
567 endif
568 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
569 let mesg= ""
570 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
571 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
572 elseif getline(v:beval_lnum) =~ '^"\s*/'
573 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
574 elseif v:beval_text == "Sorted" || v:beval_text == "by"
575 let mesg = 's: sort by name, time, or file size r: reverse sorting order mt: mark target'
576 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
577 let mesg = "S: edit sorting sequence"
578 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
579 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
580 elseif v:beval_text == "Quick" || v:beval_text == "Help"
581 let mesg = "Help: press <F1>"
582 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
583 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
584 else
585 let mesg= ""
586 endif
587 return mesg
588 endfun
589"else " Decho
590" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -")|endif
591" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval") |endif
592" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled") |endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100593" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a") |endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100594" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists") |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200595endif
596
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200598" netrw#Explore: launch the local browser in the directory of the current file {{{2
599" indx: == -1: Nexplore
600" == -2: Pexplore
601" == +: this is overloaded:
602" * If Nexplore/Pexplore is in use, then this refers to the
603" indx'th item in the w:netrw_explore_list[] of items which
604" matched the */pattern **/pattern *//pattern **//pattern
605" * If Hexplore or Vexplore, then this will override
606" g:netrw_winsize to specify the qty of rows or columns the
607" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100608" 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 +0200609" dosplit==1: the window will be split before running the local browser
610" style == 0: Explore style == 1: Explore!
611" == 2: Hexplore style == 3: Hexplore!
612" == 4: Vexplore style == 5: Vexplore!
613" == 6: Texplore
614fun! netrw#Explore(indx,dosplit,style,...)
615" 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("%"))
616 if !exists("b:netrw_curdir")
617 let b:netrw_curdir= getcwd()
Bram Moolenaara6878372014-03-22 21:02:50 +0100618" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200619 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100620
621 " record current file for Rexplore's benefit
622 if &ft != "netrw"
623 let w:netrw_rexfile= expand("%:p")
624 endif
625
626 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200627 let curdir = simplify(b:netrw_curdir)
628 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200629 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
630 let curdir= substitute(curdir,'\','/','g')
631 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100632" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">")
633
634 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
635 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
636 " try Explore again.
637 if a:0 > 0
638" call Decho('considering retry: a:1<'.a:1.'>: '.
639 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
640 \ ((filereadable(a:1))? 'is readable' : 'is not readable').', '.
641 \ ((isdirectory(a:1))? 'is a directory' : 'is not a directory'))
642 if a:1 =~ "\\\s" && !filereadable(a:1) && !isdirectory(a:1)
643" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">")
644 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
645" call Dret("netrw#Explore : returning from retry")
646 return
647" else " Decho
648" call Decho("retry not needed")
649 endif
650 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200651
652 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100653 if has("clipboard")
654 sil! let keepregstar = @*
655 sil! let keepregplus = @+
656 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200657 sil! let keepregslash= @/
658
Bram Moolenaar8d043172014-01-23 14:24:41 +0100659 " if dosplit
660 " -or- file has been modified AND file not hidden when abandoned
661 " -or- Texplore used
662 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara6878372014-03-22 21:02:50 +0100663" 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 +0200664 call s:SaveWinVars()
665 let winsz= g:netrw_winsize
666 if a:indx > 0
667 let winsz= a:indx
668 endif
669
670 if a:style == 0 " Explore, Sexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100671" call Decho("style=0: Explore or Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200673 if winsz == 0|let winsz= ""|endif
674 exe "noswapfile ".winsz."wincmd s"
675" call Decho("exe noswapfile ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200676
677 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100678" call Decho("style=1: Explore! or Sexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200679 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200680 if winsz == 0|let winsz= ""|endif
681 exe "keepalt noswapfile ".winsz."wincmd v"
682" call Decho("exe keepalt noswapfile ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200683
684 elseif a:style == 2 " Hexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100685" call Decho("style=2: Hexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200686 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200687 if winsz == 0|let winsz= ""|endif
688 exe "keepalt noswapfile bel ".winsz."wincmd s"
689" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200690
691 elseif a:style == 3 " Hexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100692" call Decho("style=3: Hexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200693 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200694 if winsz == 0|let winsz= ""|endif
695 exe "keepalt noswapfile abo ".winsz."wincmd s"
696" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s")
Bram Moolenaarff034192013-04-24 18:51:19 +0200697
698 elseif a:style == 4 " Vexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100699" call Decho("style=4: Vexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200700 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200701 if winsz == 0|let winsz= ""|endif
702 exe "keepalt noswapfile lefta ".winsz."wincmd v"
703" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200704
705 elseif a:style == 5 " Vexplore!
Bram Moolenaara6878372014-03-22 21:02:50 +0100706" call Decho("style=5: Vexplore!")
Bram Moolenaarff034192013-04-24 18:51:19 +0200707 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200708 if winsz == 0|let winsz= ""|endif
709 exe "keepalt noswapfile rightb ".winsz."wincmd v"
710" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v")
Bram Moolenaarff034192013-04-24 18:51:19 +0200711
712 elseif a:style == 6 " Texplore
713 call s:SaveBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +0100714" call Decho("style = 6: Texplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200715 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaar13600302014-05-22 18:26:40 +0200716" call Decho("exe keepalt tabnew ".fnameescape(curdir))
Bram Moolenaarff034192013-04-24 18:51:19 +0200717 call s:RestoreBufVars()
718 endif
719 call s:RestoreWinVars()
720" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +0100721" 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 +0200722 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100723 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200724
725 if a:0 > 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100726" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara6878372014-03-22 21:02:50 +0100728" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin")
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara6878372014-03-22 21:02:50 +0100730" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200731 elseif a:1 == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +0100732" call Decho("..case a:1<".a:1.">: matches .")
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
734 if dirname !~ '/$'
735 let dirname= dirname."/"
736 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100737" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 elseif a:1 =~ '\$'
Bram Moolenaara6878372014-03-22 21:02:50 +0100739" call Decho("..case a:1<".a:1.">: matches ending $")
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let dirname= simplify(expand(a:1))
Bram Moolenaara6878372014-03-22 21:02:50 +0100741" call Decho("..using user-specified dirname<".dirname."> with $env-var")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200742 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +0100743" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let dirname= simplify(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100745" call Decho("..using user-specified dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 else
Bram Moolenaara6878372014-03-22 21:02:50 +0100747" call Decho("..case a:1: pattern or filepattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let dirname= a:1
749 endif
750 else
751 " clear explore
Bram Moolenaara6878372014-03-22 21:02:50 +0100752" call Decho("case a:0=".a:0.": clearing Explore list")
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 call s:NetrwClearExplore()
754" call Dret("netrw#Explore : cleared list")
755 return
756 endif
757
Bram Moolenaara6878372014-03-22 21:02:50 +0100758" call Decho("dirname<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200759 if dirname =~ '\.\./\=$'
760 let dirname= simplify(fnamemodify(dirname,':p:h'))
761 elseif dirname =~ '\.\.' || dirname == '.'
762 let dirname= simplify(fnamemodify(dirname,':p'))
763 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100764" call Decho("dirname<".dirname."> (after simplify)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 if dirname =~ '^\*//'
767 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100768" call Decho("case starpat=1: Explore *//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
770 let starpat= 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100771" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
773
774 elseif dirname =~ '^\*\*//'
775 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100776" call Decho("case starpat=2: Explore **//pattern")
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let pattern= substitute(dirname,'^\*\*//','','')
778 let starpat= 2
Bram Moolenaara6878372014-03-22 21:02:50 +0100779" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200780
781 elseif dirname =~ '/\*\*/'
782 " handle .../**/.../filepat
Bram Moolenaara6878372014-03-22 21:02:50 +0100783" call Decho("case starpat=4: Explore .../**/.../filepat")
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
785 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
786 let b:netrw_curdir = prefixdir
787 else
788 let b:netrw_curdir= getcwd().'/'.prefixdir
789 endif
790 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
791 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100792" call Decho("..pwd<".getcwd()."> dirname<".dirname.">")
793" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200794
795 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200796 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let starpat= 3
Bram Moolenaara6878372014-03-22 21:02:50 +0100798" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200799
800 elseif dirname=~ '^\*\*/'
801 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
802 let starpat= 4
Bram Moolenaara6878372014-03-22 21:02:50 +0100803" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200804
805 else
806 let starpat= 0
Bram Moolenaara6878372014-03-22 21:02:50 +0100807" call Decho("case starpat=0: default")
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 endif
809
810 if starpat == 0 && a:indx >= 0
811 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara6878372014-03-22 21:02:50 +0100812" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore")
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 if dirname == ""
814 let dirname= curfiledir
Bram Moolenaara6878372014-03-22 21:02:50 +0100815" call Decho("..empty dirname, using current file's directory<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200817 if dirname =~ '^scp://' || dirname =~ '^ftp://'
818 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200820 if dirname == ""
821 let dirname= getcwd()
822 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +0100823 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
824 " depending on whether backslashes have been converted to forward slashes by earlier code).
825 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200826 let dirname= b:netrw_curdir."/".dirname
827 endif
828 elseif dirname !~ '^/'
829 let dirname= b:netrw_curdir."/".dirname
830 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100831" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +0100833" call Decho("win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 endif
835 if exists("w:netrw_bannercnt")
836 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
837 " If one wants to return the same place in the netrw window, use :Rex instead.
838 exe w:netrw_bannercnt
839 endif
840
Bram Moolenaara6878372014-03-22 21:02:50 +0100841" call Decho("curdir<".curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 " ---------------------------------------------------------------------
843 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
844" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100845" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200846" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100847" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200848" endif
849 " ---------------------------------------------------------------------
850
851 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
852 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
853 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
854 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
855 elseif a:indx <= 0
856 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara6878372014-03-22 21:02:50 +0100857" 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 +0200858 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100859" call Decho("..set up <s-up> and <s-down> maps")
Bram Moolenaarff034192013-04-24 18:51:19 +0200860 let s:didstarstar= 1
861 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
862 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
863 endif
864
865 if has("path_extra")
Bram Moolenaara6878372014-03-22 21:02:50 +0100866" call Decho("..starpat=".starpat.": has +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200867 if !exists("w:netrw_explore_indx")
868 let w:netrw_explore_indx= 0
869 endif
870
871 let indx = a:indx
Bram Moolenaara6878372014-03-22 21:02:50 +0100872" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]")
Bram Moolenaarff034192013-04-24 18:51:19 +0200873
874 if indx == -1
875 " Nexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100876" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100878 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaara6878372014-03-22 21:02:50 +0100879 if has("clipboard")
880 sil! let @* = keepregstar
881 sil! let @+ = keepregstar
882 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200883 sil! let @/ = keepregslash
884" call Dret("netrw#Explore")
885 return
886 endif
887 let indx= w:netrw_explore_indx
888 if indx < 0 | let indx= 0 | endif
889 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
890 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100891" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
893 let indx= indx + 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100894" call Decho("....indx=".indx." (Nexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200895 endwhile
896 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100897" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200898
899 elseif indx == -2
900 " Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100901" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")")
Bram Moolenaarff034192013-04-24 18:51:19 +0200902 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaara6878372014-03-22 21:02:50 +0100904 if has("clipboard")
905 sil! let @* = keepregstar
906 sil! let @+ = keepregstar
907 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200908 sil! let @/ = keepregslash
909" call Dret("netrw#Explore")
910 return
911 endif
912 let indx= w:netrw_explore_indx
913 if indx < 0 | let indx= 0 | endif
914 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
915 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara6878372014-03-22 21:02:50 +0100916" call Decho("....indx=".indx." curfile<".curfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 while indx >= 0 && curfile == w:netrw_explore_list[indx]
918 let indx= indx - 1
Bram Moolenaara6878372014-03-22 21:02:50 +0100919" call Decho("....indx=".indx." (Pexplore while loop)")
Bram Moolenaarff034192013-04-24 18:51:19 +0200920 endwhile
921 if indx < 0 | let indx= 0 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100922" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx)
Bram Moolenaarff034192013-04-24 18:51:19 +0200923
924 else
925 " Explore -- initialize
926 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara6878372014-03-22 21:02:50 +0100927" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100928 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200929 let w:netrw_explore_indx= 0
930 if !exists("b:netrw_curdir")
931 let b:netrw_curdir= getcwd()
932 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100933" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200934
935 " switch on starpat to build the w:netrw_explore_list of files
936 if starpat == 1
937 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100938" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls)
939" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100941 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200942 catch /^Vim\%((\a\+)\)\=:E480/
943 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
944" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
945 return
946 endtry
947 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
948 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
949
950 elseif starpat == 2
951 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara6878372014-03-22 21:02:50 +0100952" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)")
953" call Decho("....pattern<".pattern.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100955 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 catch /^Vim\%((\a\+)\)\=:E480/
957 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
958 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100959 if has("clipboard")
960 sil! let @* = keepregstar
961 sil! let @+ = keepregstar
962 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 sil! let @/ = keepregslash
964" call Dret("netrw#Explore : no files matched pattern")
965 return
966 endtry
967 let s:netrw_curdir = b:netrw_curdir
968 let w:netrw_explore_list = getqflist()
969 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
970 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
971
972 elseif starpat == 3
973 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100974" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 let filepat= substitute(dirname,'^\*/','','')
976 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara6878372014-03-22 21:02:50 +0100977" call Decho("....b:netrw_curdir<".b:netrw_curdir.">")
978" call Decho("....filepat<".filepat.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
980 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
981
982 elseif starpat == 4
983 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara6878372014-03-22 21:02:50 +0100984" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls)
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
986 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
987 endif " switch on starpat to build w:netrw_explore_list
988
989 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara6878372014-03-22 21:02:50 +0100990" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">")
991" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +0200992
993 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100994 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +0100995 if has("clipboard")
996 sil! let @* = keepregstar
997 sil! let @+ = keepregstar
998 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 sil! let @/ = keepregslash
1000" call Dret("netrw#Explore : no files matched")
1001 return
1002 endif
1003 endif " if indx ... endif
1004
1005 " NetrwStatusLine support - for exploring support
1006 let w:netrw_explore_indx= indx
Bram Moolenaara6878372014-03-22 21:02:50 +01001007" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen)
Bram Moolenaarff034192013-04-24 18:51:19 +02001008
1009 " wrap the indx around, but issue a note
1010 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara6878372014-03-22 21:02:50 +01001011" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1013 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 endif
1016
1017 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara6878372014-03-22 21:02:50 +01001018" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01001020" call Decho("....newdir<".newdir.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001021
Bram Moolenaara6878372014-03-22 21:02:50 +01001022" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 call netrw#LocalBrowseCheck(newdir)
1024 if !exists("w:netrw_liststyle")
1025 let w:netrw_liststyle= g:netrw_liststyle
1026 endif
1027 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001028 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001029 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001030 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001031 endif
1032 let w:netrw_explore_mtchcnt = indx + 1
1033 let w:netrw_explore_bufnr = bufnr("%")
1034 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001035 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara6878372014-03-22 21:02:50 +01001036" 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 +02001037
1038 else
Bram Moolenaara6878372014-03-22 21:02:50 +01001039" call Decho("..your vim does not have +path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +02001040 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001041 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaarff034192013-04-24 18:51:19 +02001042 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001043 if has("clipboard")
1044 sil! let @* = keepregstar
1045 sil! let @+ = keepregstar
1046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001047 sil! let @/ = keepregslash
1048" call Dret("netrw#Explore : missing +path_extra")
1049 return
1050 endif
1051
1052 else
Bram Moolenaara6878372014-03-22 21:02:50 +01001053" call Decho("..default case: Explore newdir<".dirname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1055 sil! unlet w:netrw_treedict
1056 sil! unlet w:netrw_treetop
1057 endif
1058 let newdir= dirname
1059 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001060 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001061 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001062 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 endif
1064 endif
1065
1066 " visual display of **/ **// */ Exploration files
Bram Moolenaara6878372014-03-22 21:02:50 +01001067" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"))
1068" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +01001070" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001072 " only update match list when current directory isn't the same as before
Bram Moolenaara6878372014-03-22 21:02:50 +01001073" call Decho("only update match list when current directory not the same as before")
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 let s:explore_prvdir = b:netrw_curdir
1075 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001076 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 if b:netrw_curdir !~ '/$'
1078 let dirlen= dirlen + 1
1079 endif
1080 let prvfname= ""
1081 for fname in w:netrw_explore_list
Bram Moolenaara6878372014-03-22 21:02:50 +01001082" call Decho("fname<".fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 if fname =~ '^'.b:netrw_curdir
1084 if s:explore_match == ""
1085 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1086 else
1087 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1088 endif
1089 elseif fname !~ '^/' && fname != prvfname
1090 if s:explore_match == ""
1091 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1092 else
1093 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1094 endif
1095 endif
1096 let prvfname= fname
1097 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +01001098" call Decho("explore_match<".s:explore_match.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02001099 exe "2match netrwMarkFile /".s:explore_match."/"
1100 endif
1101 echo "<s-up>==Pexplore <s-down>==Nexplore"
1102 else
1103 2match none
1104 if exists("s:explore_match") | unlet s:explore_match | endif
1105 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1106 echo " "
Bram Moolenaara6878372014-03-22 21:02:50 +01001107" call Decho("cleared explore match list")
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 endif
1109
Bram Moolenaara6878372014-03-22 21:02:50 +01001110 " since Explore may be used to initialize netrw's browser,
1111 " there's no danger of a late FocusGained event on initialization.
1112 " Consequently, set s:netrw_events to 2.
1113 let s:netrw_events= 2
1114 if has("clipboard")
1115 sil! let @* = keepregstar
1116 sil! let @+ = keepregstar
1117 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 sil! let @/ = keepregslash
1119" call Dret("netrw#Explore : @/<".@/.">")
1120endfun
1121
1122" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001123" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124fun! netrw#Lexplore(count,rightside,...)
1125" call Dfunc("netrw#Lexplore(count=".a:count."rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
1126 let curwin= winnr()
1127
Bram Moolenaara6878372014-03-22 21:02:50 +01001128 if a:0 > 0 && a:1 != ""
1129 " if a netrw window is already on the left-side of the tab
1130 " and a directory has been specified, explore with that
1131 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001132 let a1 = expand(a:1)
1133" call Decho("a:1<".a:1."> curwin#".curwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001134 exe "1wincmd w"
1135 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001136" call Decho("exe Explore ".fnameescape(a:1))
1137 exe "Explore ".fnameescape(a1)
1138 exe curwin."wincmd w"
1139 if exists("t:netrw_lexposn")
1140" call Decho("forgetting t:netrw_lexposn")
1141 unlet t:netrw_lexposn
1142 endif
1143" call Dret("netrw#Lexplore")
1144 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001145 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001146 exe curwin."wincmd w"
1147 else
1148 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001149 endif
1150
Bram Moolenaar8d043172014-01-23 14:24:41 +01001151 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001152 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001153 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001154 else
1155 let lexwinnr= 0
1156 endif
1157
1158 if lexwinnr > 0
1159 " close down netrw explorer window
1160" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window")
1161 exe lexwinnr."wincmd w"
1162 let g:netrw_winsize = -winwidth(0)
1163 let t:netrw_lexposn = netrw#SavePosn()
1164" call Decho("saving t:netrw_lexposn")
1165 close
1166 if lexwinnr < curwin
1167 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001168 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001169 exe curwin."wincmd w"
Bram Moolenaar8d043172014-01-23 14:24:41 +01001170 unlet t:netrw_lexbufnr
1171
1172 else
1173 " open netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001174" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001175 exe "1wincmd w"
1176 let keep_altv = g:netrw_altv
1177 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001178 if a:count != 0
1179 let netrw_winsize = g:netrw_winsize
1180 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001181 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001182 let curfile= expand("%")
1183" call Decho("curfile<".curfile.">")
1184 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1185 if a:0 > 0 && a1 != ""
1186" call Decho("case 1: Explore ".a1)
1187 exe "Explore ".fnameescape(a1)
1188 elseif curfile =~ '^\a\+://'
1189" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''))
1190 exe "Explore ".substitute(curfile,'[^/\\]*$','','')
1191 else
1192" call Decho("case 3: Explore .")
1193 Explore .
1194 endif
1195 if a:count != 0
1196 let g:netrw_winsize = netrw_winsize
1197 endif
1198 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001199 let g:netrw_altv = keep_altv
1200 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 if exists("t:netrw_lexposn")
1202" call Decho("restoring to t:netrw_lexposn")
1203 call netrw#RestorePosn(t:netrw_lexposn)
1204 unlet t:netrw_lexposn
1205 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001206 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207
1208 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001209 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 if a:rightside
1211 let g:netrw_chgwin= 1
1212 else
1213 let g:netrw_chgwin= 2
1214 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001215 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001216
Bram Moolenaar8d043172014-01-23 14:24:41 +01001217" call Dret("netrw#Lexplore")
1218endfun
1219
1220" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001221" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001222" supports :NetrwClean -- remove netrw from first directory on runtimepath
1223" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001224fun! netrw#Clean(sys)
1225" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001226
1227 if a:sys
1228 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1229 else
1230 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1231 endif
1232" call Decho("choice=".choice)
1233 let diddel= 0
1234 let diddir= ""
1235
1236 if choice == 1
1237 for dir in split(&rtp,',')
1238 if filereadable(dir."/plugin/netrwPlugin.vim")
1239" call Decho("removing netrw-related files from ".dir)
Bram Moolenaarc236c162008-07-13 17:41:49 +00001240 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1241 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1242 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1243 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1244 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1245 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 +00001246 let diddir= dir
1247 let diddel= diddel + 1
1248 if !a:sys|break|endif
1249 endif
1250 endfor
1251 endif
1252
1253 echohl WarningMsg
1254 if diddel == 0
1255 echomsg "netrw is either not installed or not removable"
1256 elseif diddel == 1
1257 echomsg "removed one copy of netrw from <".diddir.">"
1258 else
1259 echomsg "removed ".diddel." copies of netrw"
1260 endif
1261 echohl None
1262
Bram Moolenaara6878372014-03-22 21:02:50 +01001263" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001264endfun
1265
Bram Moolenaar5c736222010-01-06 20:54:52 +01001266" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001267" netrw#MakeTgt: make a target out of the directory name provided {{{2
1268fun! netrw#MakeTgt(dname)
1269" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1270 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
1271 let svpos = netrw#SavePosn()
1272 let s:netrwmftgt_islocal= (a:dname !~ '^\a\+://')
1273" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal)
1274 if s:netrwmftgt_islocal
1275 let netrwmftgt= simplify(a:dname)
1276 else
1277 let netrwmftgt= a:dname
1278 endif
1279 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1280 " re-selected target, so just clear it
1281 unlet s:netrwmftgt s:netrwmftgt_islocal
1282 else
1283 let s:netrwmftgt= netrwmftgt
1284 endif
1285 if g:netrw_fastbrowse <= 1
1286 call s:NetrwRefresh((b:netrw_curdir !~ '\a\+://'),b:netrw_curdir)
1287 endif
1288 call netrw#RestorePosn(svpos)
1289" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001290endfun
1291
Bram Moolenaara6878372014-03-22 21:02:50 +01001292" ---------------------------------------------------------------------
1293" netrw#Obtain: {{{2
1294" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001295" islocal=0 obtain from remote source
1296" =1 obtain from local source
1297" fname : a filename or a list of filenames
1298" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001299fun! netrw#Obtain(islocal,fname,...)
1300" 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 +02001301 " NetrwStatusLine support - for obtaining support
1302
1303 if type(a:fname) == 1
1304 let fnamelist= [ a:fname ]
1305 elseif type(a:fname) == 3
1306 let fnamelist= a:fname
1307 else
1308 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 +01001309" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001310 return
1311 endif
1312" call Decho("fnamelist<".string(fnamelist).">")
1313 if a:0 > 0
1314 let tgtdir= a:1
1315 else
1316 let tgtdir= getcwd()
1317 endif
1318" call Decho("tgtdir<".tgtdir.">")
1319
1320 if exists("b:netrw_islocal") && b:netrw_islocal
1321 " obtain a file from local b:netrw_curdir to (local) tgtdir
1322" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir)
1323 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1324 let topath= s:ComposePath(tgtdir,"")
1325 if (has("win32") || has("win95") || has("win64") || has("win16"))
1326 " transfer files one at time
1327" call Decho("transfer files one at a time")
1328 for fname in fnamelist
1329" call Decho("system(".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath).")")
1330 call system(g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1331 if v:shell_error != 0
1332 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1333" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".shellescape(fname)." ".shellescape(topath))
1334 return
1335 endif
1336 endfor
1337 else
1338 " transfer files with one command
1339" call Decho("transfer files with one command")
1340 let filelist= join(map(deepcopy(fnamelist),"shellescape(v:val)"))
1341" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".shellescape(topath).")")
1342 call system(g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1343 if v:shell_error != 0
1344 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
1345" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".shellescape(topath))
1346 return
1347 endif
1348 endif
1349 elseif !exists("b:netrw_curdir")
1350 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1351 else
1352 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1353 endif
1354
1355 else
1356 " obtain files from remote b:netrw_curdir to local tgtdir
1357" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir)
1358 if type(a:fname) == 1
1359 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1360 endif
1361 call s:NetrwMethod(b:netrw_curdir)
1362
1363 if b:netrw_method == 4
1364 " obtain file using scp
1365" call Decho("obtain via scp (method#4)")
1366 if exists("g:netrw_port") && g:netrw_port != ""
1367 let useport= " ".g:netrw_scpport." ".g:netrw_port
1368 else
1369 let useport= ""
1370 endif
1371 if b:netrw_fname =~ '/'
1372 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1373 else
1374 let path= ""
1375 endif
1376 let filelist= join(map(deepcopy(fnamelist),'shellescape(g:netrw_machine.":".path.v:val,1)'))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001377 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".filelist." ".shellescape(tgtdir,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001378
1379 elseif b:netrw_method == 2
1380 " obtain file using ftp + .netrc
1381" call Decho("obtain via ftp+.netrc (method #2)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001382 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001383 let tmpbufnr= bufnr("%")
1384 setl ff=unix
1385 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001386 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaarff034192013-04-24 18:51:19 +02001387" call Decho("filter input: ".getline('$'))
1388 endif
1389
1390 if exists("b:netrw_fname") && b:netrw_fname != ""
1391 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
1392" call Decho("filter input: ".getline('$'))
1393 endif
1394
1395 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001396 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaarff034192013-04-24 18:51:19 +02001397" call Decho("filter input: ".getline('$'))
1398 endif
1399 for fname in fnamelist
1400 call setline(line("$")+1,'get "'.fname.'"')
1401" call Decho("filter input: ".getline('$'))
1402 endfor
1403 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001404 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001406 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 endif
1408 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1409 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1410 let debugkeep= &debug
1411 setl debug=msg
1412 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1413 let &debug= debugkeep
1414 endif
1415
1416 elseif b:netrw_method == 3
1417 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
1418" call Decho("obtain via ftp+mipf (method #3)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001419 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 let tmpbufnr= bufnr("%")
1421 setl ff=unix
1422
1423 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001424 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarff034192013-04-24 18:51:19 +02001425" call Decho("filter input: ".getline('$'))
1426 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001427 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarff034192013-04-24 18:51:19 +02001428" call Decho("filter input: ".getline('$'))
1429 endif
1430
1431 if exists("g:netrw_uid") && g:netrw_uid != ""
1432 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001433 NetrwKeepj put =g:netrw_uid
Bram Moolenaarff034192013-04-24 18:51:19 +02001434" call Decho("filter input: ".getline('$'))
1435 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001436 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 endif
1438" call Decho("filter input: ".getline('$'))
1439 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001440 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001441" call Decho("filter input: ".getline('$'))
1442 endif
1443 endif
1444
1445 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001446 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaarff034192013-04-24 18:51:19 +02001447" call Decho("filter input: ".getline('$'))
1448 endif
1449
1450 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001452" call Decho("filter input: ".getline('$'))
1453 endif
1454
1455 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001456 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaarff034192013-04-24 18:51:19 +02001457" call Decho("filter input: ".getline('$'))
1458 endif
1459
1460 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001461 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaarff034192013-04-24 18:51:19 +02001462" call Decho("filter input: ".getline('$'))
1463 endif
1464 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001465 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001466 endfor
1467" call Decho("filter input: ".getline('$'))
1468
1469 " perform ftp:
1470 " -i : turns off interactive prompting from ftp
1471 " -n unix : DON'T use <.netrc>, even though it exists
1472 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 NetrwKeepj norm! 1Gdd
1474 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1476 if getline(1) !~ "^$"
1477" call Decho("error<".getline(1).">")
1478 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001482
1483 elseif b:netrw_method == 9
1484 " obtain file using sftp
1485" call Decho("obtain via sftp (method #9)")
1486 if a:fname =~ '/'
1487 let localfile= substitute(a:fname,'^.*/','','')
1488 else
1489 let localfile= a:fname
1490 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001491 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1).shellescape(localfile)." ".shellescape(tgtdir))
Bram Moolenaar13600302014-05-22 18:26:40 +02001492
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001494 " probably a badly formed url; protocol not recognized
1495" call Dret("netrw#Obtain : unsupported method")
1496 return
1497
1498 else
1499 " protocol recognized but not supported for Obtain (yet?)
1500 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001501 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001502 endif
1503" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 return
1505 endif
1506
1507 " restore status line
1508 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001510 endif
1511
1512 endif
1513
1514 " cleanup
1515 if exists("tmpbufnr")
1516 if bufnr("%") != tmpbufnr
1517 exe tmpbufnr."bw!"
1518 else
1519 q!
1520 endif
1521 endif
1522
Bram Moolenaara6878372014-03-22 21:02:50 +01001523" call Dret("netrw#Obtain")
1524endfun
1525
1526" ---------------------------------------------------------------------
1527" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1528fun! netrw#Nread(mode,fname)
1529" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
1530 call netrw#SavePosn()
1531 call netrw#NetRead(a:mode,a:fname)
1532 call netrw#RestorePosn()
1533
1534 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1535 if exists("w:netrw_bannercnt")
1536 " start with cursor just after the banner
1537 exe w:netrw_bannercnt
1538 endif
1539 endif
1540" call Dret("netrw#Nread")
1541endfun
1542
1543" ------------------------------------------------------------------------
1544" s:NetrwOptionRestore: restore options (based on prior s:NetrwOptionSave) {{{2
1545fun! s:NetrwOptionRestore(vt)
1546" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1547" 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)
1548 if !exists("{a:vt}netrw_optionsave")
1549 if exists("s:nbcd_curpos_{bufnr('%')}")
1550" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001551 NetrwKeepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
Bram Moolenaara6878372014-03-22 21:02:50 +01001552" call Decho("win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
1553" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1554 unlet s:nbcd_curpos_{bufnr('%')}
1555 else
1556" call Decho("no previous position")
1557 endif
1558" 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)
1559" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1560" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
1561 return
1562 endif
1563 unlet {a:vt}netrw_optionsave
1564
1565 if exists("+acd")
1566 if exists("{a:vt}netrw_acdkeep")
1567" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1568 let curdir = getcwd()
1569 let &l:acd = {a:vt}netrw_acdkeep
1570 unlet {a:vt}netrw_acdkeep
1571 if &l:acd
1572 call s:NetrwLcd(curdir)
1573 endif
1574 endif
1575 endif
1576 if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif
1577 if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif
1578 if g:netrw_liststyle != s:TREELIST
1579 if exists("{a:vt}netrw_bhkeep") |let &l:bh = {a:vt}netrw_bhkeep |unlet {a:vt}netrw_bhkeep |endif
1580 endif
1581 if exists("{a:vt}netrw_blkeep") |let &l:bl = {a:vt}netrw_blkeep |unlet {a:vt}netrw_blkeep |endif
1582 if exists("{a:vt}netrw_btkeep") |let &l:bt = {a:vt}netrw_btkeep |unlet {a:vt}netrw_btkeep |endif
1583 if exists("{a:vt}netrw_bombkeep") |let &l:bomb = {a:vt}netrw_bombkeep |unlet {a:vt}netrw_bombkeep |endif
1584 if exists("{a:vt}netrw_cedit") |let &cedit = {a:vt}netrw_cedit |unlet {a:vt}netrw_cedit |endif
1585 if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif
1586 if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif
1587 if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif
1588 if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif
1589 if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif
1590 if exists("{a:vt}netrw_diffkeep") |let &l:diff = {a:vt}netrw_diffkeep |unlet {a:vt}netrw_diffkeep |endif
1591 if exists("{a:vt}netrw_fenkeep") |let &l:fen = {a:vt}netrw_fenkeep |unlet {a:vt}netrw_fenkeep |endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001592 if exists("g:netrw_ffkep") && g:netrw_ffkeep
1593 if exists("{a:vt}netrw_ffkeep") |let &l:ff = {a:vt}netrw_ffkeep |unlet {a:vt}netrw_ffkeep |endif
1594 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001595 if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif
1596 if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif
1597 if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif
1598 if exists("{a:vt}netrw_imkeep") |let &l:im = {a:vt}netrw_imkeep |unlet {a:vt}netrw_imkeep |endif
1599 if exists("{a:vt}netrw_iskkeep") |let &l:isk = {a:vt}netrw_iskkeep |unlet {a:vt}netrw_iskkeep |endif
1600 if exists("{a:vt}netrw_lskeep") |let &l:ls = {a:vt}netrw_lskeep |unlet {a:vt}netrw_lskeep |endif
1601 if exists("{a:vt}netrw_makeep") |let &l:ma = {a:vt}netrw_makeep |unlet {a:vt}netrw_makeep |endif
1602 if exists("{a:vt}netrw_magickeep")|let &l:magic = {a:vt}netrw_magickeep |unlet {a:vt}netrw_magickeep|endif
1603 if exists("{a:vt}netrw_modkeep") |let &l:mod = {a:vt}netrw_modkeep |unlet {a:vt}netrw_modkeep |endif
1604 if exists("{a:vt}netrw_nukeep") |let &l:nu = {a:vt}netrw_nukeep |unlet {a:vt}netrw_nukeep |endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001605 if exists("{a:vt}netrw_rnukeep") |let &l:rnu = {a:vt}netrw_rnukeep |unlet {a:vt}netrw_rnukeep |endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001606 if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif
1607 if exists("{a:vt}netrw_rokeep") |let &l:ro = {a:vt}netrw_rokeep |unlet {a:vt}netrw_rokeep |endif
1608 if exists("{a:vt}netrw_selkeep") |let &l:sel = {a:vt}netrw_selkeep |unlet {a:vt}netrw_selkeep |endif
1609 if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif
1610 if has("clipboard")
1611 if exists("{a:vt}netrw_starkeep") |let @* = {a:vt}netrw_starkeep |unlet {a:vt}netrw_starkeep |endif
1612 endif
1613 " Problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1614" if exists("{a:vt}netrw_tskeep") |let &l:ts = {a:vt}netrw_tskeep |unlet {a:vt}netrw_tskeep |endif
1615 if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif
1616 if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif
1617 if exists("{a:vt}netrw_wrapkeep") |let &l:wrap = {a:vt}netrw_wrapkeep |unlet {a:vt}netrw_wrapkeep |endif
1618 if exists("{a:vt}netrw_writekeep")|let &l:write = {a:vt}netrw_writekeep |unlet {a:vt}netrw_writekeep|endif
1619 if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif
1620 if exists("{a:vt}netrw_swfkeep")
1621 if &directory == ""
1622 " user hasn't specified a swapfile directory;
1623 " netrw will temporarily set the swapfile directory
1624 " to the current directory as returned by getcwd().
1625 let &l:directory= getcwd()
1626 sil! let &l:swf = {a:vt}netrw_swfkeep
1627 setl directory=
1628 unlet {a:vt}netrw_swfkeep
1629 elseif &l:swf != {a:vt}netrw_swfkeep
1630 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1631 sil! let &l:swf= {a:vt}netrw_swfkeep
1632 unlet {a:vt}netrw_swfkeep
1633 endif
1634 endif
1635 if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
1636 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1637 if exists("{a:vt}netrw_dirkeep")
1638 call s:NetrwLcd(dirkeep)
1639 unlet {a:vt}netrw_dirkeep
1640 endif
1641 endif
1642 if has("clipboard")
1643 if exists("{a:vt}netrw_regstar") |sil! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif
1644 endif
1645 if exists("{a:vt}netrw_regslash")|sil! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif
1646 if exists("s:nbcd_curpos_{bufnr('%')}")
1647" call Decho("restoring previous position (s:nbcd_curpos_".bufnr('%')." exists)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001648 NetrwKeepj call netrw#RestorePosn(s:nbcd_curpos_{bufnr('%')})
Bram Moolenaara6878372014-03-22 21:02:50 +01001649" call Decho("unlet s:nbcd_curpos_".bufnr('%'))
1650 if exists("s:nbcd_curpos_".bufnr('%'))
1651 unlet s:nbcd_curpos_{bufnr('%')}
1652 endif
1653 else
1654" call Decho("no previous position")
1655 endif
1656
1657" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
1658" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"))
1659" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
1660" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"))
1661" call Decho("ts=".&l:ts)
1662 " Moved the filetype detect here from NetrwGetFile() because remote files
1663 " were having their filetype detect-generated settings overwritten by
1664 " NetrwOptionRestore.
1665 if &ft != "netrw"
1666" call Decho("filetype detect (ft=".&ft.")")
1667 filetype detect
1668 endif
1669" 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)
1670" call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
1671endfun
1672
1673" ---------------------------------------------------------------------
1674" s:NetrwOptionSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1675" Options get restored by s:NetrwOptionRestore()
1676" 06/08/07 : removed call to NetrwSafeOptions(), either placed
1677" immediately after NetrwOptionSave() calls in NetRead
1678" and NetWrite, or after the s:NetrwEnew() call in
1679" NetrwBrowse.
1680" vt: normally its "w:" or "s:" (a variable type)
1681fun! s:NetrwOptionSave(vt)
1682" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1683" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"))
1684" 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)
1685
1686 if !exists("{a:vt}netrw_optionsave")
1687 let {a:vt}netrw_optionsave= 1
1688 else
1689" call Dret("s:NetrwOptionSave : options already saved")
1690 return
1691 endif
1692" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
1693
1694 " Save current settings and current directory
1695" call Decho("saving current settings and current directory")
1696 let s:yykeep = @@
1697 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1698 let {a:vt}netrw_aikeep = &l:ai
1699 let {a:vt}netrw_awkeep = &l:aw
1700 let {a:vt}netrw_bhkeep = &l:bh
1701 let {a:vt}netrw_blkeep = &l:bl
Bram Moolenaar13600302014-05-22 18:26:40 +02001702 let {a:vt}netrw_btkeep = &l:bt
Bram Moolenaara6878372014-03-22 21:02:50 +01001703 let {a:vt}netrw_bombkeep = &l:bomb
1704 let {a:vt}netrw_cedit = &cedit
1705 let {a:vt}netrw_cikeep = &l:ci
1706 let {a:vt}netrw_cinkeep = &l:cin
1707 let {a:vt}netrw_cinokeep = &l:cino
1708 let {a:vt}netrw_comkeep = &l:com
1709 let {a:vt}netrw_cpokeep = &l:cpo
1710 let {a:vt}netrw_diffkeep = &l:diff
1711 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001712 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
Bram Moolenaar13600302014-05-22 18:26:40 +02001713 let {a:vt}netrw_ffkeep = &l:ff
1714 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001715 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1716 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1717 let {a:vt}netrw_hidkeep = &l:hidden
1718 let {a:vt}netrw_imkeep = &l:im
1719 let {a:vt}netrw_iskkeep = &l:isk
1720 let {a:vt}netrw_lskeep = &l:ls
1721 let {a:vt}netrw_makeep = &l:ma
1722 let {a:vt}netrw_magickeep = &l:magic
1723 let {a:vt}netrw_modkeep = &l:mod
1724 let {a:vt}netrw_nukeep = &l:nu
Bram Moolenaar13600302014-05-22 18:26:40 +02001725 let {a:vt}netrw_rnukeep = &l:rnu
Bram Moolenaara6878372014-03-22 21:02:50 +01001726 let {a:vt}netrw_repkeep = &l:report
1727 let {a:vt}netrw_rokeep = &l:ro
1728 let {a:vt}netrw_selkeep = &l:sel
1729 let {a:vt}netrw_spellkeep = &l:spell
1730 if g:netrw_use_noswf
1731 let {a:vt}netrw_swfkeep = &l:swf
1732 endif
1733 if has("clipboard")
1734 let {a:vt}netrw_starkeep = @*
1735 endif
1736 let {a:vt}netrw_tskeep = &l:ts
1737 let {a:vt}netrw_twkeep = &l:tw " textwidth
1738 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1739 let {a:vt}netrw_wrapkeep = &l:wrap
1740 let {a:vt}netrw_writekeep = &l:write
1741
1742 " save a few selected netrw-related variables
1743" call Decho("saving a few selected netrw-related variables")
1744 if g:netrw_keepdir
1745 let {a:vt}netrw_dirkeep = getcwd()
1746 endif
1747 if has("clipboard")
1748 if &go =~# 'a' | sil! let {a:vt}netrw_regstar = @* | endif
1749 endif
1750 sil! let {a:vt}netrw_regslash= @/
1751
1752" 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)
1753" call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr())
1754endfun
1755
1756" ------------------------------------------------------------------------
1757" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
1758" Use s:NetrwSaveOptions() to save user settings
1759" Use s:NetrwOptionRestore() to restore user settings
1760fun! s:NetrwSafeOptions()
1761" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1762" call Decho("win#".winnr()."'s ft=".&ft)
1763" 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)
1764 if exists("+acd") | setl noacd | endif
1765 setl noai
1766 setl noaw
1767 setl nobl
1768 setl nobomb
1769 setl bt=nofile
1770 setl noci
1771 setl nocin
1772 if g:netrw_liststyle == s:TREELIST
1773 setl bh=hide
1774 endif
1775 setl cino=
1776 setl com=
1777 setl cpo-=a
1778 setl cpo-=A
1779 setl fo=nroql2
1780 setl nohid
1781 setl noim
1782 setl isk+=@ isk+=* isk+=/
1783 setl magic
1784 if g:netrw_use_noswf
1785 setl noswf
1786 endif
1787 setl report=10000
1788 setl sel=inclusive
1789 setl nospell
1790 setl tw=0
1791 setl wig=
1792 setl cedit&
1793 call s:NetrwCursor()
1794
1795 " allow the user to override safe options
1796" call Decho("ft<".&ft."> ei=".&ei)
1797 if &ft == "netrw"
1798" call Decho("do any netrw FileType autocmds (doau FileType netrw)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001799 sil! keepalt NetrwKeepj doau FileType netrw
Bram Moolenaara6878372014-03-22 21:02:50 +01001800 endif
1801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001802" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001803" 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)
1804" call Dret("s:NetrwSafeOptions")
Bram Moolenaarff034192013-04-24 18:51:19 +02001805endfun
1806
1807" ---------------------------------------------------------------------
1808" NetrwStatusLine: {{{2
1809fun! NetrwStatusLine()
1810
1811" vvv NetrwStatusLine() debugging vvv
1812" let g:stlmsg=""
1813" if !exists("w:netrw_explore_bufnr")
1814" let g:stlmsg="!X<explore_bufnr>"
1815" elseif w:netrw_explore_bufnr != bufnr("%")
1816" let g:stlmsg="explore_bufnr!=".bufnr("%")
1817" endif
1818" if !exists("w:netrw_explore_line")
1819" let g:stlmsg=" !X<explore_line>"
1820" elseif w:netrw_explore_line != line(".")
1821" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1822" endif
1823" if !exists("w:netrw_explore_list")
1824" let g:stlmsg=" !X<explore_list>"
1825" endif
1826" ^^^ NetrwStatusLine() debugging ^^^
1827
1828 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")
1829 " restore user's status line
1830 let &stl = s:netrw_users_stl
1831 let &laststatus = s:netrw_users_ls
1832 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1833 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1834 return ""
1835 else
1836 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1837 endif
1838endfun
1839
1840" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001841" Netrw Transfer Functions: {{{1
1842" ===============================
1843
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001845" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001846" mode: =0 read remote file and insert before current line
1847" =1 read remote file and insert after current line
1848" =2 replace with remote file
1849" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001850fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001851" 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 +00001852
Bram Moolenaar5c736222010-01-06 20:54:52 +01001853 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001854 call s:NetrwOptionSave("w:")
1855 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001856 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001857 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1858 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1859 setl bl
1860" call Decho("(netrw#NetRead) buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001861
Bram Moolenaar5c736222010-01-06 20:54:52 +01001862 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001863 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001864 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001865 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001866 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001867 elseif a:mode == 2 " replace with remote file
1868 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001869 elseif a:mode == 3 " skip read of file (leave as temporary)
1870 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001871 else
1872 exe a:mode
1873 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001874 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001875 let ichoice = (a:0 == 0)? 0 : 1
1876" call Decho("readcmd<".readcmd."> ichoice=".ichoice)
1877
Bram Moolenaar5c736222010-01-06 20:54:52 +01001878 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001879 let tmpfile= s:GetTempfile("")
1880 if tmpfile == ""
1881" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001882 return
1883 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001884
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001885 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001886
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001887 " attempt to repeat with previous host-file-etc
1888 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001889" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001890 let choice = b:netrw_lastfile
1891 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001892
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001893 else
1894 exe "let choice= a:" . ichoice
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001895" call Decho("no lastfile: choice<" . choice . ">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001896
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001897 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001898 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001899 echomsg 'NetRead Usage:'
1900 echomsg ':Nread machine:path uses rcp'
1901 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1902 echomsg ':Nread "machine id password path" uses ftp'
1903 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1904 echomsg ':Nread fetch://machine/path uses fetch'
1905 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1906 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001907 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001908 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001909 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1910 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1911 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1912 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001913 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001914 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001915
Bram Moolenaar9964e462007-05-05 17:54:07 +00001916 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001917 " Reconstruct Choice if choice starts with '"'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001918" call Decho("reconstructing choice")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001919 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001920 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001921 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001922 else
1923 " case "... ... ..."
1924 let choice = strpart(choice,1,strlen(choice)-1)
1925 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001926
Bram Moolenaar9964e462007-05-05 17:54:07 +00001927 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001928 let wholechoice = wholechoice . " " . choice
1929 let ichoice = ichoice + 1
1930 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001931 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00001932 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001933 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001934" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001935 return
1936 endif
1937 let choice= a:{ichoice}
1938 endwhile
1939 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1940 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 endif
1942 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001944" call Decho("choice<" . choice . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001945 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001946
Bram Moolenaar5c736222010-01-06 20:54:52 +01001947 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001948 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001949 if !exists("b:netrw_method") || b:netrw_method < 0
1950" call Dfunc("netrw#NetRead : unsupported method")
1951 return
1952 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001953 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001954
Bram Moolenaar8d043172014-01-23 14:24:41 +01001955 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaar446cb832008-06-24 21:56:24 +00001956" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
Bram Moolenaar15146672011-10-20 22:22:38 +02001957 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaar910f66f2006-04-05 20:41:53 +00001958" call Decho("yes, choice matches '^.*[\/]$'")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001959 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00001960" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001961 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001963
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001964 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01001965 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001966 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00001967 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
1968 echo "(netrw) Processing your read request..."
1969 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001970
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001971 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001972 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001973 if b:netrw_method == 1 " read with rcp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001974" call Decho("read via rcp (method #1)")
Bram Moolenaard68071d2006-05-02 22:08:30 +00001975 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001976 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01001977 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001978 " ER: the tmpfile is full path: rcp sees C:\... as host C
1979 if s:netrw_has_nt_rcp == 1
1980 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1981 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
1982 else
1983 " Any way needed it machine contains a '.'
1984 let uid_machine = g:netrw_machine .'.'. $USERNAME
1985 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001987 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
1988 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
1989 else
1990 let uid_machine = g:netrw_machine
1991 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001993 call s:NetrwExe(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 +00001994 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001995 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001996
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001997 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01001998 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001999 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002000" call Decho("read via ftp+.netrc (method #2)")
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002001 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002002 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002003 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002004 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002005 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002006" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002007 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002008 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002009" call Decho("filter input: ".getline(line("$")))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002010 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002011 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
2012" call Decho("filter input: ".getline(line("$")))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002013 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002014 call s:NetrwExe(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 +00002015 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002016 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002017 endif
2018 " 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 +00002019 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002020 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002021 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002022 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002023 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002024 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002025 call s:SaveBufVars()
2026 bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002027 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2028 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002029 q!
2030 endif
2031 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002032 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002033 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002034
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002035 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002036 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2038 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002039" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002040 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002041 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002042 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002043 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002045 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00002046" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002048 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00002049" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaar97d62492012-11-15 21:28:22 +01002052 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002053 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002054 NetrwKeepj put =g:netrw_uid
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002055" call Decho("filter input: ".getline('.'))
2056 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002057 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002058 endif
2059" call Decho("filter input: ".getline('.'))
2060 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002061 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002062" call Decho("filter input: ".getline('.'))
2063 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002067 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00002068" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002070 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002071 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002072" call Decho("filter input: ".getline('.'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002073 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002074 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +00002075" call Decho("filter input: ".getline('.'))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 " perform ftp:
2078 " -i : turns off interactive prompting from ftp
2079 " -n unix : DON'T use <.netrc>, even though it exists
2080 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002081 NetrwKeepj norm! 1Gdd
2082 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2084 if getline(1) !~ "^$"
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002085" call Decho("error<".getline(1).">")
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002086 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002087 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002088 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002090 call s:SaveBufVars()|bd!|call s:RestoreBufVars()
2091 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002093
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002095 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 elseif b:netrw_method == 4 " read with scp
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002097" call Decho("read via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002099 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 else
2101 let useport= ""
2102 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002103 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2104 " This is workaround to avoid mis-handle windows local-path:
2105 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2106 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2107 else
2108 let tmpfile_get = tmpfile
2109 endif
2110 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002111 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002115 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002116 elseif b:netrw_method == 5
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002117" call Decho("read via http (method #5)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002119 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002121 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002123 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002125
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002126 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2127 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002128" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002129 if exists("g:netrw_http_xcmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002130 call s:NetrwExe(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 +00002131 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002132 call s:NetrwExe(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 +00002133 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002134 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002135
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002137 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002138" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002139 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2140 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002141" call Decho("netrw_html<".netrw_html.">")
2142" call Decho("netrw_tag <".netrw_tag.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 call s:NetrwExe(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 +00002144 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002145" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 endif
2148 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01002149" call Decho("setl ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02002150 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002151
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002154 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002155" call Decho("read via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002156
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 if !executable(g:netrw_dav_cmd)
2158 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2159" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2160 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002162 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002163 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 else
2165 " Construct execution string (four lines) which will be passed through filter
2166 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2167 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002168 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002169 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002170 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002171 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002172 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002173 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002174 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002175 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002177 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2178 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002179
Bram Moolenaar5c736222010-01-06 20:54:52 +01002180 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 NetrwKeepj norm! 1Gdd
2182 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002183 bd!
2184 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002185 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002187
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002189 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002190 elseif b:netrw_method == 7
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002191" call Decho("read via rsync (method #7)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 call s:NetrwExe(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 +00002193 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002195
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002197 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002198 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002199 elseif b:netrw_method == 8
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200" call Decho("read via fetch (method #8)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002202 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002203 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002204 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002205" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002206 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002208 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 let netrw_option= "http"
2210 else
2211 let netrw_option= "ftp"
2212 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002213" call Decho("read via fetch for ".netrw_option)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002214
Bram Moolenaar446cb832008-06-24 21:56:24 +00002215 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002216 call s:NetrwExe(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 +00002217 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002218 call s:NetrwExe(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 +00002219 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002220
Bram Moolenaar446cb832008-06-24 21:56:24 +00002221 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 let b:netrw_lastfile = choice
Bram Moolenaara6878372014-03-22 21:02:50 +01002223" call Decho("setl ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02002224 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002225
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002227 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002228 elseif b:netrw_method == 9
Bram Moolenaar9964e462007-05-05 17:54:07 +00002229" call Decho("read via sftp (method #9)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002230 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002231 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002235 " NetRead: (file) NetRead Method #10 {{{3
2236 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
2237" " call Decho("read via ".b:netrw_file_cmd." (method #10)")
2238 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".shellescape(b:netrw_fname,1)." ".tmpfile)
2239 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2240 let b:netrw_lastfile = choice
2241
2242 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002243 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002244 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002245 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002246 endif
2247 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002248
Bram Moolenaar5c736222010-01-06 20:54:52 +01002249 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 if exists("b:netrw_method")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002251" call Decho("cleanup b:netrw_method and b:netrw_fname")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 unlet b:netrw_fname
2254 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002255 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 +00002256" call Decho("cleanup by deleting tmpfile<".tmpfile.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002260
Bram Moolenaar9964e462007-05-05 17:54:07 +00002261" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262endfun
2263
2264" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002265" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002266fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002267" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002268
Bram Moolenaar5c736222010-01-06 20:54:52 +01002269 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002271 call s:NetrwOptionSave("w:")
2272 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002275 let tmpfile= s:GetTempfile("")
2276 if tmpfile == ""
2277" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002278 return
2279 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002280
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 if a:0 == 0
2282 let ichoice = 0
2283 else
2284 let ichoice = 1
2285 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002286
Bram Moolenaar9964e462007-05-05 17:54:07 +00002287 let curbufname= expand("%")
2288" call Decho("curbufname<".curbufname.">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002289 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002290 " For binary writes, always write entire file.
2291 " (line numbers don't really make sense for that).
2292 " Also supports the writing of tar and zip files.
Bram Moolenaaradc21822011-04-01 18:03:16 +02002293" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002295 elseif g:netrw_cygwin
2296 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002297 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaaradc21822011-04-01 18:03:16 +02002298" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002299 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002300 else
2301 " write (selected portion of) file to temporary
Bram Moolenaaradc21822011-04-01 18:03:16 +02002302" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002303 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002304 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002305
Bram Moolenaar9964e462007-05-05 17:54:07 +00002306 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002307 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002308 " on the temporary file's name. Deletion of the temporary file during
2309 " cleanup then causes an error message.
2310 0file!
2311 endif
2312
Bram Moolenaar5c736222010-01-06 20:54:52 +01002313 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002314 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaar9964e462007-05-05 17:54:07 +00002316 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 " attempt to repeat with previous host-file-etc
2318 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002319" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 let choice = b:netrw_lastfile
2321 let ichoice= ichoice + 1
2322 else
2323 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002324
Bram Moolenaar8d043172014-01-23 14:24:41 +01002325 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002327 echomsg 'NetWrite Usage:"'
2328 echomsg ':Nwrite machine:path uses rcp'
2329 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2330 echomsg ':Nwrite "machine id password path" uses ftp'
2331 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2332 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2333 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2334 echomsg ':Nwrite rcp://machine/path uses rcp'
2335 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2336 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2337 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002338 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002340
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002341 elseif match(choice,"^\"") != -1
2342 if match(choice,"\"$") != -1
2343 " case "..."
2344 let choice=strpart(choice,1,strlen(choice)-2)
2345 else
2346 " case "... ... ..."
2347 let choice = strpart(choice,1,strlen(choice)-1)
2348 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002349
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002350 while match(choice,"\"$") == -1
2351 let wholechoice= wholechoice . " " . choice
2352 let ichoice = ichoice + 1
2353 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002354 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002355 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002356 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002357" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002358 return
2359 endif
2360 let choice= a:{ichoice}
2361 endwhile
2362 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2363 endif
2364 endif
2365 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002366 let ichoice= ichoice + 1
Bram Moolenaar9964e462007-05-05 17:54:07 +00002367" call Decho("choice<" . choice . "> ichoice=".ichoice)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002368
Bram Moolenaar9964e462007-05-05 17:54:07 +00002369 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 if !exists("b:netrw_method") || b:netrw_method < 0
2372" call Dfunc("netrw#NetWrite : unsupported method")
2373 return
2374 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002375
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002378 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002379 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2380 echo "(netrw) Processing your write request..."
Bram Moolenaar446cb832008-06-24 21:56:24 +00002381" call Decho("(netrw) Processing your write request...")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002382 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002383
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002386 if b:netrw_method == 1
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002387" call Decho("write via rcp (method #1)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 if s:netrw_has_nt_rcp == 1
2389 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2390 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2391 else
2392 let uid_machine = g:netrw_machine .'.'. $USERNAME
2393 endif
2394 else
2395 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2396 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2397 else
2398 let uid_machine = g:netrw_machine
2399 endif
2400 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002401 call s:NetrwExe(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 +00002402 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002405 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002406 elseif b:netrw_method == 2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002407" call Decho("write via ftp+.netrc (method #2)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002408 let netrw_fname = b:netrw_fname
2409
2410 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2411 let bhkeep = &l:bh
2412 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002413 setl bh=hide
2414 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002415
Bram Moolenaar446cb832008-06-24 21:56:24 +00002416" call Decho("filter input window#".winnr())
Bram Moolenaarff034192013-04-24 18:51:19 +02002417 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002418 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002419" call Decho("filter input: ".getline('$'))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002420 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002421 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002422" call Decho("filter input: ".getline("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002423 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002424 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002425" call Decho("filter input: ".getline("$"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 call s:NetrwExe(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 +00002428 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00002429" call Decho("filter input window#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 endif
2432 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2433 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002434 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002435 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002436 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002439
2440 " remove enew buffer (quietly)
2441 let filtbuf= bufnr("%")
2442 exe curbuf."b!"
2443 let &l:bh = bhkeep
2444 exe filtbuf."bw!"
2445
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002447
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002450 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002451 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452" call Decho("read via ftp+mipf (method #3)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 let netrw_fname = b:netrw_fname
2454 let bhkeep = &l:bh
2455
2456 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2457 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002458 setl bh=hide
2459 keepalt enew
2460 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002463 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00002464" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002466 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00002467" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002468 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002469 if exists("g:netrw_uid") && g:netrw_uid != ""
2470 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002471 NetrwKeepj put =g:netrw_uid
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002472" call Decho("filter input: ".getline('.'))
2473 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002474 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002475 endif
2476" call Decho("filter input: ".getline('.'))
2477 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002478 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002479" call Decho("filter input: ".getline('.'))
2480 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002481 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002482 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaar5c736222010-01-06 20:54:52 +01002483" call Decho("filter input: ".getline('$'))
2484 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002485 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002486" call Decho("filter input: ".getline("$"))
2487 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002488 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002489" call Decho("filter input: ".getline('.'))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002490 " save choice/id/password for future use
2491 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002492
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002493 " perform ftp:
2494 " -i : turns off interactive prompting from ftp
2495 " -n unix : DON'T use <.netrc>, even though it exists
2496 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002497 NetrwKeepj norm! 1Gdd
2498 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2500 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002501 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002502 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002503 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 let mod=1
2505 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002506
2507 " remove enew buffer (quietly)
2508 let filtbuf= bufnr("%")
2509 exe curbuf."b!"
2510 let &l:bh= bhkeep
2511 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002512
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002514 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002515 elseif b:netrw_method == 4
Bram Moolenaar9964e462007-05-05 17:54:07 +00002516" call Decho("write via scp (method #4)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002517 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002518 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002519 else
2520 let useport= ""
2521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002522 call s:NetrwExe(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 +00002523 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002524
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002526 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002527 elseif b:netrw_method == 5
Bram Moolenaar9964e462007-05-05 17:54:07 +00002528" call Decho("write via http (method #5)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002529 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2530 if executable(curl)
2531 let url= g:netrw_choice
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002532 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".shellescape(tmpfile,1)." ".shellescape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002533 elseif !exists("g:netrw_quiet")
2534 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd".">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002535 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002538 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002539 elseif b:netrw_method == 6
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002540" call Decho("write via cadaver (method #6)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002541
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002543 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2544 let bhkeep = &l:bh
2545
2546 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2547 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002548 setl bh=hide
2549 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002550
Bram Moolenaarff034192013-04-24 18:51:19 +02002551 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002552 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002553 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002555 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002556 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002557 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002559 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002562 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002563 NetrwKeepj norm! 1Gdd
2564 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565
2566 " remove enew buffer (quietly)
2567 let filtbuf= bufnr("%")
2568 exe curbuf."b!"
2569 let &l:bh = bhkeep
2570 exe filtbuf."bw!"
2571
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002573
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002575 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002576 elseif b:netrw_method == 7
Bram Moolenaar9964e462007-05-05 17:54:07 +00002577" call Decho("write via rsync (method #7)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002578 call s:NetrwExe(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 +00002579 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002580
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002581 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002582 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002583 elseif b:netrw_method == 9
Bram Moolenaar97d62492012-11-15 21:28:22 +01002584" call Decho("write via sftp (method #9)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002585 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2587 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2588 else
2589 let uid_machine = g:netrw_machine
2590 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591
2592 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2593 let bhkeep = &l:bh
2594 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002595 setl bh=hide
2596 keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597
Bram Moolenaarff034192013-04-24 18:51:19 +02002598 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002600" call Decho("filter input: ".getline('.'))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002601 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 let filtbuf= bufnr("%")
2604 exe curbuf."b!"
2605 let &l:bh = bhkeep
2606 exe filtbuf."bw!"
2607 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002608
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002609 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002611 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002612 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002613 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002616
Bram Moolenaar5c736222010-01-06 20:54:52 +01002617 " NetWrite: Cleanup: {{{3
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002618" call Decho("cleanup")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002619 if s:FileReadable(tmpfile)
2620" call Decho("tmpfile<".tmpfile."> readable, will now delete it")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002621 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002622 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002623 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002624
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002625 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002626 " restore modifiability; usually equivalent to set nomod
2627 let &mod= mod
Bram Moolenaara6878372014-03-22 21:02:50 +01002628" 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 +02002629 elseif !exists("leavemod")
2630 " indicate that the buffer has not been modified since last written
Bram Moolenaara6878372014-03-22 21:02:50 +01002631" call Decho("set nomod")
2632 setl nomod
2633" 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 +00002634 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002635
Bram Moolenaar9964e462007-05-05 17:54:07 +00002636" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002637endfun
2638
2639" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002640" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002641" uses NetRead to get a copy of the file into a temporarily file,
2642" then sources that file,
2643" then removes that file.
2644fun! netrw#NetSource(...)
2645" call Dfunc("netrw#NetSource() a:0=".a:0)
2646 if a:0 > 0 && a:1 == '?'
2647 " give help
2648 echomsg 'NetSource Usage:'
2649 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2650 echomsg ':Nsource fetch://machine/path uses fetch'
2651 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002652 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002653 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2654 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2655 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2656 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2657 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002659 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002660 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002661 call netrw#NetRead(3,a:{i})
Bram Moolenaara6878372014-03-22 21:02:50 +01002662" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002663 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002664" call Decho("exe so ".fnameescape(s:netrw_tmpfile))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002665 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara6878372014-03-22 21:02:50 +01002666" call Decho("delete(".s:netrw_tmpfile.")")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002667 call delete(s:netrw_tmpfile)
2668 unlet s:netrw_tmpfile
2669 else
2670 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2671 endif
2672 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002673 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002674 endif
2675" call Dret("netrw#NetSource")
2676endfun
2677
Bram Moolenaar8d043172014-01-23 14:24:41 +01002678" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002679" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2680" (implements the :Ntree command)
2681fun! netrw#SetTreetop(...)
2682" call Dfunc("netrw#SetTreetop(".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2683
Bram Moolenaar8d043172014-01-23 14:24:41 +01002684 " clear out the current tree
2685 if exists("w:netrw_treetop")
Bram Moolenaara6878372014-03-22 21:02:50 +01002686" call Decho("clearing out current tree")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002687 let inittreetop= w:netrw_treetop
2688 unlet w:netrw_treetop
2689 endif
2690 if exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01002691" call Decho("freeing w:netrw_treedict")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002692 unlet w:netrw_treedict
2693 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002694
2695 if a:1 == "" && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002696 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01002697" call Decho("treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002698 else
2699 if isdirectory(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01002700" call Decho("a:1<".a:1."> is a directory")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002701 let treedir= a:1
2702 elseif exists("b:netrw_curdir") && isdirectory(b:netrw_curdir."/".a:1)
2703 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01002704" call Decho("a:1<".a:1."> is NOT a directory, trying treedir<".treedir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002705 else
2706 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara6878372014-03-22 21:02:50 +01002707 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002708 endif
2709 endif
2710" call Decho("treedir<".treedir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002711 let islocal= expand("%") !~ '^\a\+://'
2712" call Decho("islocal=".islocal)
2713 if islocal
2714 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2715 else
2716 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2717 endif
2718" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002719endfun
2720
Bram Moolenaar9964e462007-05-05 17:54:07 +00002721" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002722" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002723" readcmd == %r : replace buffer with newly read file
2724" == 0r : read file at top of buffer
2725" == r : read file after current line
2726" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002727fun! s:NetrwGetFile(readcmd, tfile, method)
2728" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002729
2730 " readcmd=='t': simply do nothing
2731 if a:readcmd == 't'
Bram Moolenaara6878372014-03-22 21:02:50 +01002732" 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 +00002733" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002734 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002735 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002736
Bram Moolenaar9964e462007-05-05 17:54:07 +00002737 " get name of remote filename (ie. url and all)
2738 let rfile= bufname("%")
2739" call Decho("rfile<".rfile.">")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002740
Bram Moolenaar9964e462007-05-05 17:54:07 +00002741 if exists("*NetReadFixup")
2742 " for the use of NetReadFixup (not otherwise used internally)
2743 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002744 endif
2745
Bram Moolenaar9964e462007-05-05 17:54:07 +00002746 if a:readcmd[0] == '%'
2747 " get file into buffer
2748" call Decho("get file into buffer")
2749
2750 " rename the current buffer to the temp file (ie. tfile)
2751 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002752 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002753 else
2754 let tfile= a:tfile
2755 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002756" call Decho("exe sil! keepalt file ".fnameescape(tfile))
2757 exe "sil! keepalt file ".fnameescape(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002758
2759 " edit temporary file (ie. read the temporary file in)
2760 if rfile =~ '\.zip$'
2761" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
2762 call zip#Browse(tfile)
2763 elseif rfile =~ '\.tar$'
2764" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
2765 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002766 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002767" call Decho("handling remote gzip-compressed tar file")
2768 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002769 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002770" call Decho("handling remote bz2-compressed tar file")
2771 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002772 elseif rfile =~ '\.tar\.xz$'
2773" call Decho("handling remote xz-compressed tar file")
2774 call tar#Browse(tfile)
2775 elseif rfile =~ '\.txz$'
2776" call Decho("handling remote xz-compressed tar file (.txz)")
2777 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778 else
2779" call Decho("edit temporary file")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002780 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002781 endif
2782
2783 " rename buffer back to remote filename
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002784" call Decho("exe sil! keepalt file ".fnameescape(rfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002785 exe "sil! NetrwKeepj keepalt file ".fnameescape(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002786
Bram Moolenaar97d62492012-11-15 21:28:22 +01002787 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002788 " Note that isk must not include a "/" for scripts.vim
2789 " to process this detection correctly.
2790" call Decho("detect filetype of local version of remote file")
Bram Moolenaar97d62492012-11-15 21:28:22 +01002791 let iskkeep= &l:isk
2792 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002793 let &l:isk= iskkeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00002794" call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
2795 let line1 = 1
2796 let line2 = line("$")
2797
Bram Moolenaar8d043172014-01-23 14:24:41 +01002798 elseif !&ma
2799 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002800 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002801" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
2802 return
2803
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 elseif s:FileReadable(a:tfile)
2805 " read file after current line
2806" call Decho("read file<".a:tfile."> after current line")
2807 let curline = line(".")
2808 let lastline= line("$")
Bram Moolenaarc236c162008-07-13 17:41:49 +00002809" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002810 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 let line1= curline + 1
2812 let line2= line("$") - lastline + 1
2813
2814 else
2815 " not readable
Bram Moolenaara6878372014-03-22 21:02:50 +01002816" 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 +00002817" call Decho("tfile<".a:tfile."> not readable")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002818 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002819" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820 return
2821 endif
2822
2823 " User-provided (ie. optional) fix-it-up command
2824 if exists("*NetReadFixup")
2825" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002826 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827" else " Decho
2828" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")")
2829 endif
2830
Bram Moolenaaradc21822011-04-01 18:03:16 +02002831 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002832 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002833 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002834 endif
2835
2836" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
2837
2838 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002839" redraw!
2840
Bram Moolenaara6878372014-03-22 21:02:50 +01002841" 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 +00002842" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002843endfun
2844
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002846" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002847" Input:
2848" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2849" Output:
2850" b:netrw_method= 1: rcp
2851" 2: ftp + <.netrc>
2852" 3: ftp + machine, id, password, and [path]filename
2853" 4: scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002854" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002855" 6: dav
2856" 7: rsync
2857" 8: fetch
2858" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002859" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002860" g:netrw_machine= hostname
2861" b:netrw_fname = filename
2862" g:netrw_port = optional port number (for ftp)
2863" g:netrw_choice = copy of input url (choice)
2864fun! s:NetrwMethod(choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002865" call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002866
Bram Moolenaar251e1912011-06-19 05:09:16 +02002867 " sanity check: choice should have at least three slashes in it
2868 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2869 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2870 let b:netrw_method = -1
2871" call Dret("NetrwMethod : incorrect url format<".a:choice.">")
2872 return
2873 endif
2874
Bram Moolenaar5c736222010-01-06 20:54:52 +01002875 " record current g:netrw_machine, if any
2876 " curmachine used if protocol == ftp and no .netrc
2877 if exists("g:netrw_machine")
2878 let curmachine= g:netrw_machine
2879" call Decho("curmachine<".curmachine.">")
2880 else
2881 let curmachine= "N O T A HOST"
2882 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002883 if exists("g:netrw_port")
2884 let netrw_port= g:netrw_port
2885 endif
2886
2887 " insure that netrw_ftp_cmd starts off every method determination
2888 " with the current g:netrw_ftp_cmd
2889 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002890
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002891 " initialization
2892 let b:netrw_method = 0
2893 let g:netrw_machine = ""
2894 let b:netrw_fname = ""
2895 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002896 let g:netrw_choice = a:choice
2897
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002898 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002899 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002900 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2901 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002902 " rcpurm : rcp://[user@]host/filename Use rcp
2903 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002904 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002905 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002906 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002907 " rsyncurm : rsync://host[:port]/path Use rsync
2908 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2909 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002910 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002911 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2912 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002913 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2914 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002915 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002916 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002917 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002918 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002919 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002920 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002921 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002922 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002923
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002924" call Decho("determine method:")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002925 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002926 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002927 if match(a:choice,rcpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002928" call Decho("rcp://...")
Bram Moolenaar83bab712005-08-01 21:58:57 +00002929 let b:netrw_method = 1
2930 let userid = substitute(a:choice,rcpurm,'\1',"")
2931 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2932 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002933 if userid != ""
2934 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002936
Bram Moolenaaradc21822011-04-01 18:03:16 +02002937 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002938 elseif match(a:choice,scpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002939" call Decho("scp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002940 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002941 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2942 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2943 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002944
Bram Moolenaar15146672011-10-20 22:22:38 +02002945 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002946 elseif match(a:choice,httpurm) == 0
Bram Moolenaara6878372014-03-22 21:02:50 +01002947" call Decho("http[s]://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002948 let b:netrw_method = 5
2949 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
2950 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01002951 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002952
Bram Moolenaaradc21822011-04-01 18:03:16 +02002953 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002954 elseif match(a:choice,davurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002955" call Decho("dav://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002956 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02002957 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002958 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
2959 else
2960 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
2961 endif
2962 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002963
Bram Moolenaaradc21822011-04-01 18:03:16 +02002964 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002965 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002966" call Decho("rsync://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002967 let b:netrw_method = 7
2968 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
2969 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002970
Bram Moolenaaradc21822011-04-01 18:03:16 +02002971 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002972 elseif match(a:choice,ftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002973" call Decho("ftp://...")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002974 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002975 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
2976 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
2977 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002978" call Decho("g:netrw_machine<".g:netrw_machine.">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002979 if userid != ""
2980 let g:netrw_uid= userid
2981 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002982
Bram Moolenaaradc21822011-04-01 18:03:16 +02002983 if curmachine != g:netrw_machine
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002984 if exists("s:netwr_hup[".g:netrw_machine."]")
2985 call NetUserPass("ftp:".g:netrw_machine)
2986 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02002987 " if there's a change in hostname, require password re-entry
2988 unlet s:netrw_passwd
2989 endif
2990 if exists("netrw_port")
2991 unlet netrw_port
2992 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002993 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002994
Bram Moolenaar446cb832008-06-24 21:56:24 +00002995 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002996 let b:netrw_method = 3
2997 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998 let host= substitute(g:netrw_machine,'\..*$','','')
2999 if exists("s:netrw_hup[host]")
3000 call NetUserPass("ftp:".host)
3001
3002 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
Bram Moolenaaradc21822011-04-01 18:03:16 +02003003" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
3004" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
3005 if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003006 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaaradc21822011-04-01 18:03:16 +02003007" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
3008 endif
3009 let b:netrw_method= 2
3010 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
3011" call Decho("using <".expand("$HOME/.netrc")."> (readable)")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003012 let b:netrw_method= 2
3013 else
3014 if !exists("g:netrw_uid") || g:netrw_uid == ""
3015 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003016 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003017 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003018 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003019 endif
3020 let b:netrw_method= 3
3021 endif
3022 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003023
Bram Moolenaaradc21822011-04-01 18:03:16 +02003024 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003025 elseif match(a:choice,fetchurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003026" call Decho("fetch://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003027 let b:netrw_method = 8
3028 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3029 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3030 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3031 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003032
Bram Moolenaaradc21822011-04-01 18:03:16 +02003033 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003034 elseif match(a:choice,mipf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003035" call Decho("(ftp) host id pass file")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003037 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3038 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003039 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003040 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003041 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003042
Bram Moolenaaradc21822011-04-01 18:03:16 +02003043 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003044 elseif match(a:choice,mf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003045" call Decho("(ftp) host file")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003046 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003047 let b:netrw_method = 3
3048 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3049 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003050
Bram Moolenaar9964e462007-05-05 17:54:07 +00003051 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003052 let b:netrw_method = 2
3053 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3054 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3055 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003056
Bram Moolenaaradc21822011-04-01 18:03:16 +02003057 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003058 elseif match(a:choice,sftpurm) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003059" call Decho("sftp://...")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003060 let b:netrw_method = 9
3061 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3062 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003063
Bram Moolenaaradc21822011-04-01 18:03:16 +02003064 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 elseif match(a:choice,rcphf) == 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003066" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003067 let b:netrw_method = 1
3068 let userid = substitute(a:choice,rcphf,'\2',"")
3069 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3070 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003071" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
3072" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
3073" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
3074" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003075 if userid != ""
3076 let g:netrw_uid= userid
3077 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003078
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003079 " Method#10: file://user@hostname/...path-to-file {{{3
3080 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
3081" call Decho("http[s]://...")
3082 let b:netrw_method = 10
3083 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
3084" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">")
3085
Bram Moolenaaradc21822011-04-01 18:03:16 +02003086 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003088 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003090 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003091 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003093 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003094
Bram Moolenaar81695252004-12-29 20:58:21 +00003095 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 " remove any leading [:#] from port number
3097 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3098 elseif exists("netrw_port")
3099 " retain port number as implicit for subsequent ftp operations
3100 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003101 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003102
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003103" call Decho("a:choice <".a:choice.">")
3104" call Decho("b:netrw_method <".b:netrw_method.">")
3105" call Decho("g:netrw_machine<".g:netrw_machine.">")
3106" call Decho("g:netrw_port <".g:netrw_port.">")
3107" if exists("g:netrw_uid") "Decho
3108" call Decho("g:netrw_uid <".g:netrw_uid.">")
3109" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003110" if exists("s:netrw_passwd") "Decho
3111" call Decho("s:netrw_passwd <".s:netrw_passwd.">")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003112" endif "Decho
3113" call Decho("b:netrw_fname <".b:netrw_fname.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003114" call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116
3117" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003118" NetReadFixup: this sort of function is typically written by the user {{{2
3119" to handle extra junk that their system's ftp dumps
3120" into the transfer. This function is provided as an
3121" example and as a fix for a Windows 95 problem: in my
3122" experience, win95's ftp always dumped four blank lines
3123" at the end of the transfer.
3124if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3125 fun! NetReadFixup(method, line1, line2)
3126" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003127
3128 " sanity checks -- attempt to convert inputs to integers
3129 let method = a:method + 0
3130 let line1 = a:line1 + 0
3131 let line2 = a:line2 + 0
3132 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3133" call Dret("NetReadFixup")
3134 return
3135 endif
3136
Bram Moolenaar9964e462007-05-05 17:54:07 +00003137 if method == 3 " ftp (no <.netrc>)
3138 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003139 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003140 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003141 call histdel("/",-1)
3142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003143 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003144
Bram Moolenaar9964e462007-05-05 17:54:07 +00003145" call Dret("NetReadFixup")
3146 endfun
3147endif
3148
3149" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003150" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003151" Usage: :call NetUserPass() -- will prompt for userid and password
3152" :call NetUserPass("uid") -- will prompt for password
3153" :call NetUserPass("uid","password") -- sets global userid and password
3154" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3155" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156fun! NetUserPass(...)
3157
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003158" call Dfunc("NetUserPass() a:0=".a:0)
3159
3160 if !exists('s:netrw_hup')
3161 let s:netrw_hup= {}
3162 endif
3163
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003165 " case: no input arguments
3166
3167 " change host and username if not previously entered; get new password
3168 if !exists("g:netrw_machine")
3169 let g:netrw_machine= input('Enter hostname: ')
3170 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003172 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 let g:netrw_uid= input('Enter username: ')
3174 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003175 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003176 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003177
3178 " set up hup database
3179 let host = substitute(g:netrw_machine,'\..*$','','')
3180 if !exists('s:netrw_hup[host]')
3181 let s:netrw_hup[host]= {}
3182 endif
3183 let s:netrw_hup[host].uid = g:netrw_uid
3184 let s:netrw_hup[host].passwd = s:netrw_passwd
3185
3186 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003187 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003188
3189 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003190 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003191 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara6878372014-03-22 21:02:50 +01003192" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003193 let host = substitute(a:1,'^ftp:','','')
3194 let host = substitute(host,'\..*','','')
3195 if exists("s:netrw_hup[host]")
3196 let g:netrw_uid = s:netrw_hup[host].uid
3197 let s:netrw_passwd = s:netrw_hup[host].passwd
3198" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3199" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
3200 else
3201 let g:netrw_uid = input("Enter UserId: ")
3202 let s:netrw_passwd = inputsecret("Enter Password: ")
3203 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003204
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003205 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003206 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara6878372014-03-22 21:02:50 +01003207" 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 +02003208 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003209 if g:netrw_machine =~ '[0-9.]\+'
3210 let host= g:netrw_machine
3211 else
3212 let host= substitute(g:netrw_machine,'\..*$','','')
3213 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003214 else
3215 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003217 let g:netrw_uid = a:1
3218" call Decho("set g:netrw_uid= <".g:netrw_uid.">")
3219 if exists("g:netrw_passwd")
3220 " ask for password if one not previously entered
3221 let s:netrw_passwd= g:netrw_passwd
3222 else
3223 let s:netrw_passwd = inputsecret("Enter Password: ")
3224 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003225 endif
3226
3227" call Decho("host<".host.">")
3228 if exists("host")
3229 if !exists('s:netrw_hup[host]')
3230 let s:netrw_hup[host]= {}
3231 endif
3232 let s:netrw_hup[host].uid = g:netrw_uid
3233 let s:netrw_hup[host].passwd = s:netrw_passwd
3234 endif
3235
3236 elseif a:0 == 2
3237 let g:netrw_uid = a:1
3238 let s:netrw_passwd = a:2
3239
3240 elseif a:0 == 3
3241 " enter hostname, user-id, and password into the hup dictionary
3242 let host = substitute(a:1,'^\a\+:','','')
3243 let host = substitute(host,'\..*$','','')
3244 if !exists('s:netrw_hup[host]')
3245 let s:netrw_hup[host]= {}
3246 endif
3247 let s:netrw_hup[host].uid = a:2
3248 let s:netrw_hup[host].passwd = a:3
3249 let g:netrw_uid = s:netrw_hup[host].uid
3250 let s:netrw_passwd = s:netrw_hup[host].passwd
3251" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">")
3252" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003254
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003255" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257
Bram Moolenaar9964e462007-05-05 17:54:07 +00003258" ===========================================
3259" Shared Browsing Support: {{{1
3260" ===========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003262" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003263" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3264fun! s:ExplorePatHls(pattern)
3265" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3266 let repat= substitute(a:pattern,'^**/\{1,2}','','')
3267" call Decho("repat<".repat.">")
3268 let repat= escape(repat,'][.\')
3269" call Decho("repat<".repat.">")
3270 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3271" call Dret("s:ExplorePatHls repat<".repat.">")
3272 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003273endfun
3274
3275" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003276" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003277" 0: (user: <mb>) bookmark current directory
3278" 1: (user: <gb>) change to the bookmarked directory
3279" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003280" 3: (browsing) records current directory history
3281" 4: (user: <u>) go up (previous) directory, using history
3282" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003283" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003284fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003285" 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 +02003286 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3287" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3288 return
3289 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003290
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003291 let ykeep = @@
3292 let curbufnr = bufnr("%")
3293
Bram Moolenaar9964e462007-05-05 17:54:07 +00003294 if a:chg == 0
3295 " bookmark the current directory
3296" call Decho("(user: <b>) bookmark the current directory")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 if exists("s:netrwmarkfilelist_{curbufnr}")
3298 call s:NetrwBookmark(0)
3299 echo "bookmarked marked files"
3300 else
3301 call s:MakeBookmark(a:curdir)
3302 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003303 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003304
3305 elseif a:chg == 1
3306 " change to the bookmarked directory
Bram Moolenaarff034192013-04-24 18:51:19 +02003307" call Decho("(user: <".v:count."gb>) change to the bookmarked directory")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003308 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaarff034192013-04-24 18:51:19 +02003309" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003310 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003311 else
3312 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3313 endif
3314
3315 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003316" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003317 let didwork= 0
3318 " list user's bookmarks
3319" call Decho("(user: <q>) list user's bookmarks")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003320 if exists("g:netrw_bookmarklist")
3321" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
3322 let cnt= 1
3323 for bmd in g:netrw_bookmarklist
3324" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
Bram Moolenaarff034192013-04-24 18:51:19 +02003325 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003326 let didwork = 1
3327 let cnt = cnt + 1
3328 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003329 endif
3330
3331 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003332 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003333 let first = 1
3334 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003335 if g:netrw_dirhistmax > 0
3336 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaar5c736222010-01-06 20:54:52 +01003337" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
Bram Moolenaaradc21822011-04-01 18:03:16 +02003338 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003339" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt})
Bram Moolenaarff034192013-04-24 18:51:19 +02003340 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003341 let didwork= 1
3342 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003343 let histcnt = histcnt + 1
3344 let first = 0
3345 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003346 if cnt < 0
3347 let cnt= cnt + g:netrw_dirhistmax
3348 endif
3349 endwhile
3350 else
3351 let g:netrw_dirhist_cnt= 0
3352 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003353 if didwork
3354 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3355 endif
3356
3357 elseif a:chg == 3
3358 " saves most recently visited directories (when they differ)
3359" call Decho("(browsing) record curdir history")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003360 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 +02003361 if g:netrw_dirhistmax > 0
3362 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3363 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
3364 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003365" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003366 endif
3367
3368 elseif a:chg == 4
3369 " u: change to the previous directory stored on the history list
3370" call Decho("(user: <u>) chg to prev dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003371 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003372 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003373 if g:netrw_dirhist_cnt < 0
3374 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3375 endif
3376 else
3377 let g:netrw_dirhist_cnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003378 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003379 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
3380" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003381 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003382 setl ma noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003383" call Decho("setl ma noro")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003384 sil! NetrwKeepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003385 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01003386" call Decho("setl nomod")
3387" 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 +00003388 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003389" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003390 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003391 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003392 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003393 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003394 else
3395 let g:netrw_dirhist_cnt= 0
3396 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003397 echo "Sorry, no predecessor directory exists yet"
3398 endif
3399
3400 elseif a:chg == 5
3401 " U: change to the subsequent directory stored on the history list
3402" call Decho("(user: <U>) chg to next dir from history")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003403 if g:netrw_dirhistmax > 0
3404 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3405 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003406" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003407 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara6878372014-03-22 21:02:50 +01003408" call Decho("setl ma noro")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003410 sil! NetrwKeepj %d
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411" call Decho("removed all lines from buffer (%d)")
Bram Moolenaara6878372014-03-22 21:02:50 +01003412" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003413 setl nomod
3414" 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 +02003415 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003416" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003417 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003418 else
3419 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
3420 if g:netrw_dirhist_cnt < 0
3421 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3422 endif
3423 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003424 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003425 else
3426 let g:netrw_dirhist_cnt= 0
3427 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003428 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003429
3430 elseif a:chg == 6
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003431 if exists("s:netrwmarkfilelist_{curbufnr}")
3432 call s:NetrwBookmark(1)
3433 echo "removed marked files from bookmarks"
3434 else
3435 " delete the v:count'th bookmark
3436" call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
3437 call s:MergeBookmarks()
Bram Moolenaarff034192013-04-24 18:51:19 +02003438" call Decho("remove g:netrw_bookmarklist[".(v:count-1)."]")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003439 NetrwKeepj call remove(g:netrw_bookmarklist,v:count-1)
3440 echo "removed current directory from bookmarks"
3441 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003442" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003444 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003445 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003446 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003447" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003448endfun
3449
3450" ---------------------------------------------------------------------
3451" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003452" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453" Sister function: s:NetrwBookHistSave()
3454fun! s:NetrwBookHistRead()
3455" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003456 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3457" " call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
3458 return
3459 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003460 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003461 if !exists("s:netrw_initbookhist")
3462 let home = s:NetrwHome()
3463 let savefile= home."/.netrwbook"
3464 if filereadable(savefile)
3465" call Decho("sourcing .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003467 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003468 if g:netrw_dirhistmax > 0
3469 let savefile= home."/.netrwhist"
3470 if filereadable(savefile)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003471" call Decho("sourcing .netrwhist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003472 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003473 endif
3474 let s:netrw_initbookhist= 1
3475 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003476 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003477 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003478 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003479" call Dret("s:NetrwBookHistRead")
3480endfun
3481
3482" ---------------------------------------------------------------------
3483" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
3484" Sister function: s:NetrwBookHistRead()
3485" I used to do this via viminfo but that appears to
3486" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003487" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3488" will be saved.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489fun! s:NetrwBookHistSave()
3490" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003491 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003492" call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
3493 return
3494 endif
3495
Bram Moolenaar5c736222010-01-06 20:54:52 +01003496 let savefile= s:NetrwHome()."/.netrwhist"
3497 1split
3498 call s:NetrwEnew()
Bram Moolenaarff034192013-04-24 18:51:19 +02003499 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3500 setl nocin noai noci magic nospell nohid wig= noaw
3501 setl ma noro write
3502 if exists("+acd") | setl noacd | endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003503 sil! NetrwKeepj keepalt %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504
3505 " save .netrwhist -- no attempt to merge
Bram Moolenaarff034192013-04-24 18:51:19 +02003506 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003507 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
3508 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
3509 let lastline = line("$")
3510 let cnt = 1
3511 while cnt <= g:netrw_dirhist_cnt
3512 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3513 let cnt= cnt + 1
3514 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003515 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003516
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003517 sil NetrwKeepj %d
Bram Moolenaar5c736222010-01-06 20:54:52 +01003518 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
3519 " merge and write .netrwbook
3520 let savefile= s:NetrwHome()."/.netrwbook"
3521
3522 if filereadable(savefile)
3523 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003524 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003525 for bdm in booklist
3526 if index(g:netrw_bookmarklist,bdm) == -1
3527 call add(g:netrw_bookmarklist,bdm)
3528 endif
3529 endfor
3530 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003531 endif
3532
3533 " construct and save .netrwbook
3534 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003535 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003536 endif
3537 let bgone= bufnr("%")
3538 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003539 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540
3541" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003542endfun
3543
3544" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003545" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3546" list of the contents of a local or remote directory. It is assumed that the
3547" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3548" with the requested remote hostname first.
3549fun! s:NetrwBrowse(islocal,dirname)
3550 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003551" 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 +01003552" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003553" call Dredir("ls!")
Bram Moolenaara6878372014-03-22 21:02:50 +01003554
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003555 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3556 " This is useful when one edits a local file, then :e ., then :Rex
3557 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3558 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003559 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003560
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003561 " s:NetrwBrowse : initialize history {{{3
3562 if !exists("s:netrw_initbookhist")
3563 NetrwKeepj call s:NetrwBookHistRead()
3564 endif
3565
3566 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003567 if a:dirname !~ '^\a\+://'
3568 let dirname= simplify(a:dirname)
3569 else
3570 let dirname= a:dirname
3571 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003572
3573 if exists("s:netrw_skipbrowse")
3574 unlet s:netrw_skipbrowse
Bram Moolenaara6878372014-03-22 21:02:50 +01003575" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">")
3576" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003577 return
3578 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003579
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003580 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003581 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003582 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003583" call Dret("s:NetrwBrowse : missing shellescape()")
3584 return
3585 endif
3586 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003587 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003588" call Dret("s:NetrwBrowse : missing fnameescape()")
3589 return
3590 endif
3591
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003592 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003593 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003594
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003595 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003596 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01003597" call Decho("clearing marked files")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003598 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3599 endif
3600
3601 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003602 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003603" call Decho("handle w:netrw_acdkeep:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003604" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01003605 call s:NetrwLcd(dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003606 call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01003607" call Decho("getcwd<".getcwd().">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003608
Bram Moolenaar5c736222010-01-06 20:54:52 +01003609 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003610 " s:NetrwBrowse : remote regular file handler {{{3
3611" call Decho("handle remote regular file: dirname<".dirname.">")
3612 if bufname(dirname) != ""
3613" call Decho("edit buf#".bufname(dirname)." in win#".winnr())
3614 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003615 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003616 " attempt transfer of remote regular file
3617" call Decho("attempt transfer as regular file<".dirname.">")
3618
3619 " remove any filetype indicator from end of dirname, except for the
3620 " "this is a directory" indicator (/).
3621 " There shouldn't be one of those here, anyway.
3622 let path= substitute(dirname,'[*=@|]\r\=$','','e')
3623" call Decho("new path<".path.">")
3624 call s:RemotePathAnalysis(dirname)
3625
3626 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3627 call s:NetrwEnew(dirname)
3628 call s:NetrwSafeOptions()
3629 setl ma noro
3630" call Decho("setl ma noro")
3631 let b:netrw_curdir = dirname
3632 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
3633" call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
3634 exe "sil! NetrwKeepj keepalt file ".fnameescape(url)
3635 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3636 sil call netrw#NetRead(2,url)
3637 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
3638" call Decho("url<".url.">")
3639" call Decho("s:path<".s:path.">")
3640" call Decho("s:fname<".s:fname.">")
3641 if s:path =~ '.bz2'
3642 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3643 elseif s:path =~ '.gz'
3644 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3645 elseif s:path =~ '.gz'
3646 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3647 else
3648 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3649 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003650 endif
3651
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003652 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003653 call s:SetBufWinVars()
3654 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003655" call Decho("setl ma nomod")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003656 setl ma nomod noro
Bram Moolenaara6878372014-03-22 21:02:50 +01003657" 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 +00003658
Bram Moolenaar446cb832008-06-24 21:56:24 +00003659" call Dret("s:NetrwBrowse : file<".s:fname.">")
3660 return
3661 endif
3662
Bram Moolenaaradc21822011-04-01 18:03:16 +02003663 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003664 call s:UseBufWinVars()
3665
3666 " set up some variables {{{3
3667 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003669 let s:last_sort_by = g:netrw_sort_by
3670
3671 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003672 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003673
Bram Moolenaar97d62492012-11-15 21:28:22 +01003674 " get/set-up buffer {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003675" call Decho("saving position across a buffer refresh")
3676 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
3678 " maintain markfile highlighting
3679 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaara6878372014-03-22 21:02:50 +01003680" call Decho("bufnr(%)=".bufnr('%'))
3681" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003682 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3683 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003684" call Decho("2match none")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 2match none
3686 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003687 if reusing && line("$") > 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003688 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003689" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003690 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003691" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01003692" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003693 return
3694 endif
3695
3696 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003697" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003698 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003699 if b:netrw_curdir =~ '[/\\]$'
3700 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3701 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003702 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3703 let b:netrw_curdir= b:netrw_curdir."/"
3704 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003705 if b:netrw_curdir == ''
3706 if has("amiga")
3707 " On the Amiga, the empty string connotes the current directory
3708 let b:netrw_curdir= getcwd()
3709 else
3710 " under unix, when the root directory is encountered, the result
3711 " from the preceding substitute is an empty string.
3712 let b:netrw_curdir= '/'
3713 endif
3714 endif
3715 if !a:islocal && b:netrw_curdir !~ '/$'
3716 let b:netrw_curdir= b:netrw_curdir.'/'
3717 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003718" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003719
3720 " ------------
3721 " (local only) {{{3
3722 " ------------
3723 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01003724" call Decho("local only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003725
3726 " Set up ShellCmdPost handling. Append current buffer to browselist
3727 call s:LocalFastBrowser()
3728
3729 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3730 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003731" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
3732" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003733 if !exists("&l:acd") || !&l:acd
Bram Moolenaara6878372014-03-22 21:02:50 +01003734 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003735 endif
3736 endif
3737
3738 " --------------------------------
3739 " remote handling: {{{3
3740 " --------------------------------
3741 else
Bram Moolenaara6878372014-03-22 21:02:50 +01003742" call Decho("remote only:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003743
Bram Moolenaar97d62492012-11-15 21:28:22 +01003744 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003745" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 if dirname =~ "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747 let dirname= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01003748" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003749 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3750 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3751 if dirname !~ '/$'
3752 let dirname= dirname.'/'
3753 endif
3754 let b:netrw_curdir = dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003755" call Decho("(liststyle is TREELIST) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003756 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara6878372014-03-22 21:02:50 +01003758" call Decho("(normal) dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003759 endif
3760
3761 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3762 if dirname !~ dirpat
3763 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003764 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003765 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003766 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01003767" call Decho("setl noma nomod nowrap")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003768 setl noma nomod nowrap
Bram Moolenaara6878372014-03-22 21:02:50 +01003769" 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 +00003770" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3771 return
3772 endif
3773 let b:netrw_curdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003774" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775 endif " (additional remote handling)
3776
3777 " -----------------------
3778 " Directory Listing: {{{3
3779 " -----------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003780 NetrwKeepj call s:NetrwMaps(a:islocal)
3781 NetrwKeepj call s:NetrwCommands(a:islocal)
3782 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02003783 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003784 let &l:bexpr= "netrw#BalloonHelp()"
3785" call Decho("set up balloon help: l:bexpr=".&l:bexpr)
3786 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003787 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003788 call s:NetrwOptionRestore("w:")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003789
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003790 " restore position and jumplist entry
3791 if !reusing
3792" call Decho("restoring position across buffer refresh")
3793 call netrw#RestorePosn(svpos)
3794 endif
3795
Bram Moolenaara6878372014-03-22 21:02:50 +01003796 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003797 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
Bram Moolenaara6878372014-03-22 21:02:50 +01003798 " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003799
Bram Moolenaara6878372014-03-22 21:02:50 +01003800" 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 +02003801" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003802 return
3803endfun
3804
3805" ---------------------------------------------------------------------
3806" s:NetrwFileInfo: supports qf (query for file information) {{{2
3807fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003808" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003809 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810 if a:islocal
3811 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003812
3813 if getline(".") == "../"
3814 echo system("/bin/ls -lsad ".shellescape(".."))
3815" call Decho("#1: echo system(/bin/ls -lsad ".shellescape(..).")")
3816
Bram Moolenaara6878372014-03-22 21:02:50 +01003817 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaar8d043172014-01-23 14:24:41 +01003818 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir))
3819" call Decho("#2: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir).")")
3820
3821 elseif exists("b:netrw_curdir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 if b:netrw_curdir =~ '/$'
3823 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003824" call Decho("#3: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname).")")
3825
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826 else
3827 echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003828" call Decho("#4: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003829 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003830
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831 else
3832" call Decho('using ls '.a:fname." using cwd<".getcwd().">")
3833 echo system("/bin/ls -lsad ".shellescape(a:fname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003834" call Decho("#5: echo system(/bin/ls -lsad ".shellescape(a:fname).")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835 endif
3836 else
3837 " use vim functions to return information about file below cursor
3838" call Decho("using vim functions to query for file info")
3839 if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
3840 let fname= substitute(a:fname,".$","","")
3841 else
3842 let fname= a:fname
3843 endif
3844 let t = getftime(fname)
3845 let sz = getfsize(fname)
3846 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname))
Bram Moolenaara6878372014-03-22 21:02:50 +01003847" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848 endif
3849 else
3850 echo "sorry, \"qf\" not supported yet for remote files"
3851 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003852 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853" call Dret("s:NetrwFileInfo")
3854endfun
3855
3856" ---------------------------------------------------------------------
3857" s:NetrwGetBuffer: {{{2
3858" returns 0=cleared buffer
3859" 1=re-used buffer
3860fun! s:NetrwGetBuffer(islocal,dirname)
3861" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara6878372014-03-22 21:02:50 +01003862" 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 +00003863 let dirname= a:dirname
3864
3865 " re-use buffer if possible {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003866" call Decho("--re-use a buffer if possible--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003867 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3868 " find NetrwTreeList buffer if there is one
Bram Moolenaara6878372014-03-22 21:02:50 +01003869" call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870 if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01003871" call Decho(" re-using w:netrw_treebufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003872 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003873 setl ei=all
Bram Moolenaar13600302014-05-22 18:26:40 +02003874 exe "sil! noswapfile keepalt b ".w:netrw_treebufnr
Bram Moolenaar446cb832008-06-24 21:56:24 +00003875 let &ei= eikeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01003876 setl ma
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 sil! NetrwKeepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01003878" 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 +02003879" call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
3880 return 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00003881 endif
3882 let bufnum= -1
Bram Moolenaara6878372014-03-22 21:02:50 +01003883" call Decho(" liststyle=TREE but w:netrw_treebufnr doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003884
3885 else
3886 " find buffer number of buffer named precisely the same as dirname {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003887" call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003888" call Dredir("(NetrwGetBuffer) ls!","ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889
3890 " get dirname and associated buffer number
3891 let bufnum = bufnr(escape(dirname,'\'))
Bram Moolenaara6878372014-03-22 21:02:50 +01003892" call Decho(" find buffer<".dirname.">'s number ")
3893" call Decho(" bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894
3895 if bufnum < 0 && dirname !~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003896 " try appending a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003897" call Decho(" try appending a trailing / to dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003898 let bufnum= bufnr(escape(dirname.'/','\'))
3899 if bufnum > 0
3900 let dirname= dirname.'/'
3901 endif
3902 endif
3903
3904 if bufnum < 0 && dirname =~ '/$'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003905 " try removing a trailing /
Bram Moolenaara6878372014-03-22 21:02:50 +01003906" call Decho(" try removing a trailing / from dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907 let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
3908 if bufnum > 0
3909 let dirname= substitute(dirname,'/$','','')
3910 endif
3911 endif
3912
Bram Moolenaara6878372014-03-22 21:02:50 +01003913" call Decho(" findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003914 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches)
3915 if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
3916 " handle approximate matches
Bram Moolenaara6878372014-03-22 21:02:50 +01003917" call Decho(" handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003918 let ibuf = 1
3919 let buflast = bufnr("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01003920" call Decho(" findbuf2: buflast=bufnr($)=".buflast)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 while ibuf <= buflast
3922 let bname= substitute(bufname(ibuf),'\\','/','g')
Bram Moolenaarc236c162008-07-13 17:41:49 +00003923 let bname= substitute(bname,'.\zs/$','','')
Bram Moolenaara6878372014-03-22 21:02:50 +01003924" call Decho(" findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003925 if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
3926 " bname is not empty
3927 " dirname ends with bname,
3928 " dirname doesn't start with /, so its not a absolute path
Bram Moolenaara6878372014-03-22 21:02:50 +01003929" call Decho(" findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003930 break
3931 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003932 if bname =~ '^'.dirname.'/\=$'
3933 " bname begins with dirname
3934" call Decho(' findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003935 break
3936 endif
3937 if dirname =~ '^'.bname.'/$'
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003938" call Decho(' findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
3939 break
3940 endif
3941 if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
3942" call Decho(' findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
Bram Moolenaar5c736222010-01-06 20:54:52 +01003943 break
3944 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 let ibuf= ibuf + 1
3946 endwhile
3947 if ibuf > buflast
3948 let bufnum= -1
3949 else
3950 let bufnum= ibuf
3951 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003952" call Decho(" findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 endif
3954 endif
3955
3956 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01003957" call Decho(" get enew buffer and name it OR re-use buffer")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003958 sil! NetrwKeepj keepalt mark '
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 if bufnum < 0 || !bufexists(bufnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003960" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961 call s:NetrwEnew(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003962" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963 " name the buffer
3964 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3965 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +01003966" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003967 if !exists("s:netrw_treelistnum")
3968 let s:netrw_treelistnum= 1
3969 else
3970 let s:netrw_treelistnum= s:netrw_treelistnum + 1
3971 endif
3972 let w:netrw_treebufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01003973" call Decho(" exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003974 exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
Bram Moolenaara6878372014-03-22 21:02:50 +01003975 setl bt=nofile noswf
Bram Moolenaaradc21822011-04-01 18:03:16 +02003976 nnoremap <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
3977 nnoremap <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
3978 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[')<cr>
3979 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01003980" call Decho(" tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003982" let v:errmsg = "" " Decho
3983 let escdirname = fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003984" call Decho(" errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003985" call Decho(' exe sil! keepalt file '.escdirname)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003986" let v:errmsg= "" " Decho
3987 exe 'sil! keepalt file '.escdirname
Bram Moolenaara6878372014-03-22 21:02:50 +01003988" call Decho(" errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003990" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003991
3992 else " Re-use the buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01003993" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01003995 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00003996 if getline(2) =~ '^" Netrw Directory Listing'
Bram Moolenaara6878372014-03-22 21:02:50 +01003997" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
Bram Moolenaar13600302014-05-22 18:26:40 +02003998 exe "sil! noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00003999 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004000" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
Bram Moolenaar13600302014-05-22 18:26:40 +02004001 exe "sil! noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 endif
4003 if bufname("%") == '.'
Bram Moolenaara6878372014-03-22 21:02:50 +01004004" call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004005 exe "sil! keepalt file ".fnameescape(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 endif
4007 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004008
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009 if line("$") <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004010 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01004011" 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 +01004012" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4013 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004014
Bram Moolenaar97d62492012-11-15 21:28:22 +01004015 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004016" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer")
4017 NetrwKeepj call s:NetrwListSettings(a:islocal)
4018 sil NetrwKeepj %d
Bram Moolenaara6878372014-03-22 21:02:50 +01004019" 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 +01004020" 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 +00004021 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004022
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01004024" call Decho("--re-use tree listing--")
4025" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004026 sil NetrwKeepj %d
4027 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01004028" 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 +01004029" 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 +00004030 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004031
Bram Moolenaar446cb832008-06-24 21:56:24 +00004032 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004033" 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 +01004034" call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004035 return 1
4036 endif
4037 endif
4038
4039 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4040 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4041 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4042 " med 1 D H
4043 " fast 2 H H
Bram Moolenaara6878372014-03-22 21:02:50 +01004044" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004045 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004046 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01004047" call Decho("exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004048 exe "sil! NetrwKeepj keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004049
4050 " delete all lines from buffer {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01004051" call Decho("--delete all lines from buffer--")
4052" call Decho(" clear buffer<".expand("%")."> with :%d")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004053 sil! keepalt NetrwKeepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004054
Bram Moolenaara6878372014-03-22 21:02:50 +01004055" 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 +01004056" call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004057 return 0
4058endfun
4059
4060" ---------------------------------------------------------------------
4061" s:NetrwGetcwd: get the current directory. {{{2
4062" Change backslashes to forward slashes, if any.
4063" If doesc is true, escape certain troublesome characters
4064fun! s:NetrwGetcwd(doesc)
4065" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4066 let curdir= substitute(getcwd(),'\\','/','ge')
4067 if curdir !~ '[\/]$'
4068 let curdir= curdir.'/'
4069 endif
4070 if a:doesc
4071 let curdir= fnameescape(curdir)
4072 endif
4073" call Dret("NetrwGetcwd <".curdir.">")
4074 return curdir
4075endfun
4076
4077" ---------------------------------------------------------------------
4078" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4079fun! s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004080" call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 call s:UseBufWinVars()
4082
4083 " insure that w:netrw_liststyle is set up
4084 if !exists("w:netrw_liststyle")
4085 if exists("g:netrw_liststyle")
4086 let w:netrw_liststyle= g:netrw_liststyle
4087 else
4088 let w:netrw_liststyle= s:THINLIST
4089 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004090" "call Decho("w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004091 endif
4092
4093 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4094 " Active Banner support
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004095" "call Decho("active banner handling")
4096 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004097 let dirname= "./"
4098 let curline= getline('.')
4099
4100 if curline =~ '"\s*Sorted by\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004101 NetrwKeepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004102 let s:netrw_skipbrowse= 1
4103 echo 'Pressing "s" also works'
4104
4105 elseif curline =~ '"\s*Sort sequence:'
4106 let s:netrw_skipbrowse= 1
4107 echo 'Press "S" to edit sorting sequence'
4108
4109 elseif curline =~ '"\s*Quick Help:'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004110 NetrwKeepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004112
4113 elseif curline =~ '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004114 NetrwKeepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004115 let s:netrw_skipbrowse= 1
4116 echo 'Pressing "a" also works'
4117
4118 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004119 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004120 endif
4121
4122 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004123" "call Decho("thin column handling")
4124 NetrwKeepj norm! 0
4125 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004126
4127 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004128" "call Decho("long column handling")
4129 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004130 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4131
4132 elseif w:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004133" "call Decho("treelist handling")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004134 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004135 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004136
4137 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004138" "call Decho("obtain word from wide listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139 let dirname= getline('.')
4140
4141 if !exists("b:netrw_cpf")
4142 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004143 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004144 call histdel("/",-1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004145" "call Decho("computed cpf=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004146 endif
4147
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004148" "call Decho("buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004150" "call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt)
4151" "call Decho("1: dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004153 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 else
4155 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004156 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 endif
4158 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004159 let eofname= filestart + b:netrw_cpf + 1
4160 if eofname <= col("$")
4161 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004162 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004163 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004164 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004165 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 let dirname = @a
4167 let @a = rega
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004168" "call Decho("2: dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004169 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004170" "call Decho("3: dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 endif
4172
4173 " symlinks are indicated by a trailing "@". Remove it before further processing.
4174 let dirname= substitute(dirname,"@$","","")
4175
4176 " executables are indicated by a trailing "*". Remove it before further processing.
4177 let dirname= substitute(dirname,"\*$","","")
4178
4179" call Dret("s:NetrwGetWord <".dirname.">")
4180 return dirname
4181endfun
4182
4183" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004184" s:NetrwListSettings: make standard settings for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004185fun! s:NetrwListSettings(islocal)
4186" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01004187" 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 +00004188 let fname= bufname("%")
Bram Moolenaar13600302014-05-22 18:26:40 +02004189" " call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro nornu")
4190 setl bt=nofile nobl ma nonu nowrap noro nornu
Bram Moolenaarff034192013-04-24 18:51:19 +02004191" call Decho("(NetrwListSettings) exe sil! keepalt file ".fnameescape(fname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004192 exe "sil! keepalt file ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004193 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004194 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004196" call Dredir("ls!")
Bram Moolenaarff034192013-04-24 18:51:19 +02004197" call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004198 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004199 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004200 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004201 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004202 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004203 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004205" 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 +00004206" call Dret("s:NetrwListSettings")
4207endfun
4208
4209" ---------------------------------------------------------------------
4210" s:NetrwListStyle: {{{2
4211" islocal=0: remote browsing
4212" =1: local browsing
4213fun! s:NetrwListStyle(islocal)
4214" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004215
Bram Moolenaar97d62492012-11-15 21:28:22 +01004216 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004217 let fname = s:NetrwGetWord()
4218 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004219 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
4221" call Decho("fname<".fname.">")
4222" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
4223" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
4224
4225 if w:netrw_liststyle == s:THINLIST
4226 " use one column listing
4227" call Decho("use one column list")
4228 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4229
4230 elseif w:netrw_liststyle == s:LONGLIST
4231 " use long list
4232" call Decho("use long list")
4233 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4234
4235 elseif w:netrw_liststyle == s:WIDELIST
4236 " give wide list
4237" call Decho("use wide list")
4238 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4239
4240 elseif w:netrw_liststyle == s:TREELIST
4241" call Decho("use tree list")
4242 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4243
4244 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004245 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004246 let g:netrw_liststyle = s:THINLIST
4247 let w:netrw_liststyle = g:netrw_liststyle
4248 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4249 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004250 setl ma noro
4251" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252
4253 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
4254" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004255 sil! NetrwKeepj %d
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004256 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara6878372014-03-22 21:02:50 +01004257" call Decho("setl nomod")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004258 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004259" 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 +00004260
4261 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004262" call Decho("refresh the listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004263 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4264 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265
Bram Moolenaar13600302014-05-22 18:26:40 +02004266 " restore position; keep cursor on the filename
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004267 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004268 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004269
4270" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4271endfun
4272
4273" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004274" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4275fun! s:NetrwBannerCtrl(islocal)
4276" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4277
Bram Moolenaar97d62492012-11-15 21:28:22 +01004278 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004279 " toggle the banner (enable/suppress)
4280 let g:netrw_banner= !g:netrw_banner
4281
4282 " refresh the listing
Bram Moolenaara6878372014-03-22 21:02:50 +01004283 let svpos= netrw#SavePosn()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004284 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4285
4286 " keep cursor on the filename
4287 let fname= s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004288 sil NetrwKeepj $
Bram Moolenaar5c736222010-01-06 20:54:52 +01004289 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4290" call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
4291 if result <= 0 && exists("w:netrw_bannercnt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004292 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01004293 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004294 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004295" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4296endfun
4297
4298" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004299" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4300"
4301" No bang: enters files/directories into Netrw's bookmark system
4302" No argument and in netrw buffer:
4303" if there are marked files: bookmark marked files
4304" otherwise : bookmark file/directory under cursor
4305" No argument and not in netrw buffer: bookmarks current open file
4306" Has arguments: globs them individually and bookmarks them
4307"
4308" With bang: deletes files/directories from Netrw's bookmark system
4309fun! s:NetrwBookmark(del,...)
4310" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4311 if a:0 == 0
4312 if &ft == "netrw"
4313 let curbufnr = bufnr("%")
4314
4315 if exists("s:netrwmarkfilelist_{curbufnr}")
4316 " for every filename in the marked list
4317" call Decho("bookmark every filename in marked list")
4318 let svpos = netrw#SavePosn()
4319 let islocal= expand("%") !~ '^\a\+://'
4320 for fname in s:netrwmarkfilelist_{curbufnr}
4321 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4322 endfor
4323 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4324 call s:NetrwUnmarkList(curbufnr,curdir)
4325 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
4326 NetrwKeepj call netrw#RestorePosn(svpos)
4327 else
4328 let fname= s:NetrwGetWord()
4329 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4330 endif
4331
4332 else
4333 " bookmark currently open file
4334" call Decho("bookmark currently open file")
4335 let fname= expand("%")
4336 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4337 endif
4338
4339 else
4340 " bookmark specified files
4341 " attempts to infer if working remote or local
4342 " by deciding if the current file begins with an url
4343 " Globbing cannot be done remotely.
4344 let islocal= expand("%") !~ '^\a\+://'
4345" call Decho("bookmark specified file".((a:0>1)? "s" : ""))
4346 let i = 1
4347 while i <= a:0
4348 if islocal
4349 let mbfiles= glob(a:{i},0,1)
4350 else
4351 let mbfiles= [a:{i}]
4352 endif
4353" call Decho("mbfiles".string(mbfiles))
4354 for mbfile in mbfiles
4355" call Decho("mbfile<".mbfile.">")
4356 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4357 endfor
4358 let i= i + 1
4359 endwhile
4360 endif
4361
4362 " update the menu
4363 call s:NetrwBookmarkMenu()
4364
4365" call Dret("s:NetrwBookmark")
4366endfun
4367
4368" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4370" .2.[cnt] for bookmarks, and
4371" .3.[cnt] for history
4372" (see s:NetrwMenu())
4373fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004374 if !exists("s:netrw_menucnt")
4375 return
4376 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004377" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378
4379 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004380 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004381 if exists("g:NetrwTopLvlMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004382" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004383 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4384 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004385 endif
4386 if !exists("s:netrw_initbookhist")
4387 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004388 endif
4389
4390 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004391 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004392 let cnt= 1
4393 for bmd in g:netrw_bookmarklist
Bram Moolenaar8d043172014-01-23 14:24:41 +01004394" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd)
4395 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004396
4397 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004398 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004399
4400 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004401 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 +01004402 let cnt= cnt + 1
4403 endfor
4404
4405 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004406
4407 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004408 if g:netrw_dirhistmax > 0
4409 let cnt = g:netrw_dirhist_cnt
4410 let first = 1
4411 let histcnt = 0
4412 while ( first || cnt != g:netrw_dirhist_cnt )
4413 let histcnt = histcnt + 1
4414 let priority = g:netrw_dirhist_cnt + histcnt
4415 if exists("g:netrw_dirhist_{cnt}")
4416 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
4417" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir)
4418 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4419 endif
4420 let first = 0
4421 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4422 if cnt < 0
4423 let cnt= cnt + g:netrw_dirhistmax
4424 endif
4425 endwhile
4426 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004427
Bram Moolenaar9964e462007-05-05 17:54:07 +00004428 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004430endfun
4431
4432" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004433" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4434" directory and a new directory name. Also, if the
4435" "new directory name" is actually a file,
4436" NetrwBrowseChgDir() edits the file.
4437fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4438" 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 +01004439" call Decho("win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +00004440
Bram Moolenaar97d62492012-11-15 21:28:22 +01004441 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 if !exists("b:netrw_curdir")
4443 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4444 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004445 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01004446" call Decho("b:netrw_curdir doesn't exist!")
4447" call Decho("getcwd<".getcwd().">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004448" call Dredir("ls!")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004450 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004451 endif
4452
Bram Moolenaar97d62492012-11-15 21:28:22 +01004453 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01004454" call Decho("saving options")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004455 NetrwKeepj call s:NetrwOptionSave("s:")
4456 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01004457 let nbcd_curpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
Bram Moolenaara6878372014-03-22 21:02:50 +01004459" call Decho("setting s:nbcd_curpos_".bufnr('%')." to SavePosn")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004460 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004461 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004462 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004463 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004464 endif
4465 let newdir = a:newdir
4466 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004467 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004468" call Decho("dirname<".dirname.">")
4469
4470 " ignore <cr>s when done in the banner
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471" call Decho('ignore <cr>s when done in banner (g:netrw_banner='.g:netrw_banner.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01004472 if g:netrw_banner
4473" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"))
4474 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
4475 if getline(".") =~ 'Quick Help'
4476" 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.">)")
4477 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
4478" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar13600302014-05-22 18:26:40 +02004479 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004481 setl noma nomod nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 NetrwKeepj call netrw#RestorePosn(nbcd_curpos)
4483 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004484" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
4485 endif
4486 endif
4487" else " Decho
4488" call Decho("(s:NetrwBrowseChgdir) g:netrw_banner=".g:netrw_banner." (no banner)")
4489 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004490
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 " set up o/s-dependent directory recognition pattern
Bram Moolenaara6878372014-03-22 21:02:50 +01004492" call Decho("set up o/s-dependent directory recognition pattern")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 if has("amiga")
4494 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004495 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 let dirpat= '[\/]$'
4497 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004498" call Decho("dirname<".dirname."> dirpat<".dirpat.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499
4500 if dirname !~ dirpat
4501 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004502 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004503 let dirname= dirname.'/'
Bram Moolenaara6878372014-03-22 21:02:50 +01004504" call Decho("adjusting dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506" call Decho("newdir<".newdir."> !~ dirpat<".dirpat.">? ".((newdir !~ dirpat)? "yes" : "no"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004508 if newdir !~ dirpat && !(a:islocal && isdirectory(newdir))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004509 " ------------------------------
4510 " NetrwBrowseChgDir: edit a file {{{3
4511 " ------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004512" call Decho('edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004513
Bram Moolenaar97d62492012-11-15 21:28:22 +01004514 " save position for benefit of Rexplore
Bram Moolenaara6878372014-03-22 21:02:50 +01004515 let s:rexposn_{bufnr("%")}= netrw#SavePosn()
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004516
Bram Moolenaara6878372014-03-22 21:02:50 +01004517" call Decho("edit-a-file: setting s:rexposn_".bufnr("%")." to SavePosn")
4518" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
4519" 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.">")
4520
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara6878372014-03-22 21:02:50 +01004522" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">")
4523" call Decho("edit-a-file: newdir<".newdir.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004524 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525 if dirname =~ '/$'
4526 let dirname= dirname.newdir
4527 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004528 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004530" call Decho("edit-a-file: dirname<".dirname.">")
4531" call Decho("edit-a-file: tree listing")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 elseif newdir =~ '^\(/\|\a:\)'
4533 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004534 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004536 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004537" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004538 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004539 if a:0 < 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004540" call Decho("edit-a-file: set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004541 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004543" call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr())
4544 if type(g:netrw_browse_split) == 3
4545 " open file in server
4546 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
4547" call Decho("edit-a-file: open file in server")
4548 call s:NetrwServerEdit(a:islocal,dirname)
4549" call Dret("s:NetrwBrowseChgDir")
4550 return
4551 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004552 " horizontally splitting the window first
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004553" call Decho("edit-a-file: horizontally splitting window prior to edit")
Bram Moolenaarff034192013-04-24 18:51:19 +02004554 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004555 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004556 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004557 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004559 " vertically splitting the window first
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004560" call Decho("edit-a-file: vertically splitting window prior to edit")
Bram Moolenaarff034192013-04-24 18:51:19 +02004561 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004562 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004563 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004564 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004566 " open file in new tab
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004567" call Decho("edit-a-file: opening new tab prior to edit")
Bram Moolenaarff034192013-04-24 18:51:19 +02004568 keepalt tabnew
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004570 " act like "P" (ie. open previous window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004571" call Decho("edit-a-file: use previous window for edit")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004573 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004575 return
4576 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004577 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 " handling a file, didn't split, so remove menu
Bram Moolenaara6878372014-03-22 21:02:50 +01004579" call Decho("edit-a-file: handling a file+didn't split, so remove menu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 call s:NetrwMenu(0)
4581 " optional change to window
4582 if g:netrw_chgwin >= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004583" call Decho("edit-a-file: changing window to #".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02004584 if winnr("$")+1 == g:netrw_chgwin
4585 " if g:netrw_chgwin is set to one more than the last window, then
4586 " vertically split the last window to make that window available.
4587 let curwin= winnr()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004588 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".winnr("$")
Bram Moolenaar13600302014-05-22 18:26:40 +02004589 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004590 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004591 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004592 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004593 endif
4594 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004595 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004596
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 " the point where netrw actually edits the (local) file
4598 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004599 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600 if a:islocal
Bram Moolenaara6878372014-03-22 21:02:50 +01004601" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004602 " some like c-^ to return to the last edited file
4603 " others like c-^ to return to the netrw buffer
4604 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004605 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004606 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004607 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004608 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004609" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004610 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004611 if &hidden || &bufhidden == "hide"
4612 " file came from vim's hidden storage. Don't "restore" options with it.
4613 let dorestore= 0
4614 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004615 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004616" call Decho("edit-a-file: remote file: NetrwBrowse will edit it")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004617 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004619
4620 " handle g:Netrw_funcref -- call external-to-netrw functions
4621 " This code will handle g:Netrw_funcref as an individual function reference
4622 " or as a list of function references. It will ignore anything that's not
4623 " a function reference. See :help Funcref for information about function references.
4624 if exists("g:Netrw_funcref")
Bram Moolenaara6878372014-03-22 21:02:50 +01004625" call Decho("edit-a-file: handle optional Funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004626 if type(g:Netrw_funcref) == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01004627" call Decho("edit-a-file: handling a g:Netrw_funcref")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004628 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004629 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01004630" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004631 for Fncref in g:Netrw_funcref
4632 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004633 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004634 endif
4635 endfor
4636 endif
4637 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004638 endif
4639
4640 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004641 " ----------------------------------------------------
4642 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4643 " ----------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004644" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004645 let dirname = newdir
4646 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
4647 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004648
4649 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004650 " ---------------------------------------------
4651 " NetrwBrowseChgDir: refresh the directory list {{{3
4652 " ---------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004653" call Decho('refresh-dirlist: case "refresh directory listing": newdir == "./"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004654 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004655
4656 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004657 " --------------------------------------
4658 " NetrwBrowseChgDir: go up one directory {{{3
4659 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004660" call Decho('go-up: case "go up one directory": newdir == "../"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004661
4662 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4663 " force a refresh
Bram Moolenaara6878372014-03-22 21:02:50 +01004664" call Decho("go-up: clear buffer<".expand("%")."> with :%d")
4665" call Decho("go-up: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004666 setl noro ma
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004667 NetrwKeepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004668 endif
4669
4670 if has("amiga")
4671 " amiga
Bram Moolenaara6878372014-03-22 21:02:50 +01004672" call Decho('go-up: case "go up one directory": newdir == "../" and amiga')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004673 if a:islocal
4674 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4675 let dirname= substitute(dirname,'/$','','')
4676 else
4677 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4678 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004679" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004680
Bram Moolenaar8d043172014-01-23 14:24:41 +01004681 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4682 " windows
4683 if a:islocal
4684 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4685 if dirname == ""
4686 let dirname= '/'
4687 endif
4688 else
4689 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4690 endif
4691 if dirname =~ '^\a:$'
4692 let dirname= dirname.'/'
4693 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004694" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004695
Bram Moolenaar446cb832008-06-24 21:56:24 +00004696 else
4697 " unix or cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +01004698" call Decho('go-up: case "go up one directory": newdir == "../" and unix or cygwin')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004699 if a:islocal
4700 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4701 if dirname == ""
4702 let dirname= '/'
4703 endif
4704 else
4705 let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
4706 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004707" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004708 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004709 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004710
4711 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004712 " --------------------------------------
4713 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4714 " --------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004715" call Decho('tree-list: case liststyle is TREELIST and w:netrw_treedict exists')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004716 " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh)
Bram Moolenaara6878372014-03-22 21:02:50 +01004717" call Decho("tree-list: setl noro ma")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004718 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004719 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004720" call Decho("tree-list: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 NetrwKeepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00004722 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004724 let s:treecurpos = nbcd_curpos
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 let haskey = 0
Bram Moolenaara6878372014-03-22 21:02:50 +01004726" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004727
4728 " search treedict for tree dir as-is
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004729" call Decho("search treedict for tree dir as-is")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004731" call Decho('tree-list: ....searched for treedir<'.treedir.'> : found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004732 let haskey= 1
4733 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004734" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004735 endif
4736
4737 " search treedict for treedir with a / appended
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004738" call Decho("search treedict for treedir with a / appended")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004739 if !haskey && treedir !~ '/$'
4740 if has_key(w:netrw_treedict,treedir."/")
4741 let treedir= treedir."/"
Bram Moolenaara6878372014-03-22 21:02:50 +01004742" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004743 let haskey = 1
4744 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004745" call Decho('tree-list: ....searched for treedir<'.treedir.'/> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004746 endif
4747 endif
4748
4749 " search treedict for treedir with any trailing / elided
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004750" call Decho("search treedict for treedir with any trailing / elided")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004751 if !haskey && treedir =~ '/$'
4752 let treedir= substitute(treedir,'/$','','')
4753 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004754" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004755 let haskey = 1
4756 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004757" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004758 endif
4759 endif
4760
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004761" call Decho("haskey=".haskey)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004762 if haskey
4763 " close tree listing for selected subdirectory
Bram Moolenaara6878372014-03-22 21:02:50 +01004764" call Decho("tree-list: closing selected subdirectory<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004765 call remove(w:netrw_treedict,treedir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004766" call Decho("tree-list: removed entry<".treedir."> from treedict")
4767" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004768 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004769 else
4770 " go down one directory
4771 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara6878372014-03-22 21:02:50 +01004772" call Decho("tree-list: go down one dir: treedir<".treedir.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004773" call Decho("tree-list: ... : dirname<".dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004775 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
4776" call Decho("setting s:treeforceredraw to true")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004777 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004778
4779 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004780 " ----------------------------------------
4781 " NetrwBrowseChgDir: Go down one directory {{{3
4782 " ----------------------------------------
4783 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01004784" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004785 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004786 endif
4787
Bram Moolenaar97d62492012-11-15 21:28:22 +01004788 " --------------------------------------
4789 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4790 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004791 if dorestore
4792 " dorestore is zero'd when a local file was hidden or bufhidden;
4793 " in such a case, we want to keep whatever settings it may have.
4794" call Decho("doing option restore (dorestore=".dorestore.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004795 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004796" else " Decho
4797" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod)
4798 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004799 if dolockout && dorestore
Bram Moolenaara6878372014-03-22 21:02:50 +01004800" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004801 if filewritable(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01004802" call Decho("restore: doing modification lockout settings: ma nomod noro")
4803" call Decho("restore: setl ma nomod noro")
Bram Moolenaar13600302014-05-22 18:26:40 +02004804 setl ma noro nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004805" 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 +02004806 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004807" call Decho("restore: doing modification lockout settings: ma nomod ro")
4808" call Decho("restore: setl ma nomod noro")
Bram Moolenaar13600302014-05-22 18:26:40 +02004809 setl ma ro nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01004810" 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 +02004811 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004812 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004814
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
4816 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817endfun
4818
4819" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004820" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4821" for thin, long, and wide: cursor placed just after banner
4822" for tree, keeps cursor on current filename
4823fun! s:NetrwBrowseUpDir(islocal)
4824" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004825 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4826 " this test needed because occasionally this function seems to be incorrectly called
4827 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
4828 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
4829 " directories.
4830" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
4831 return
4832 endif
4833
Bram Moolenaara6878372014-03-22 21:02:50 +01004834 norm! 0
4835 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004836" call Decho("case: treestyle")
Bram Moolenaara6878372014-03-22 21:02:50 +01004837 let curline= getline(".")
4838 let swwline= winline() - 1
4839 if exists("w:netrw_treetop")
4840 let b:netrw_curdir= w:netrw_treetop
4841 endif
4842 if a:islocal
4843 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4844 else
4845 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4846 endif
4847 if !search('\c^'.s:treedepthstring.curline,'cw')
4848 if !search('\c^'.curline,'cw')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004849 sil! NetrwKeepj 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004850 endif
4851 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004852 exe "sil! NetrwKeepj norm! z\<cr>"
Bram Moolenaara6878372014-03-22 21:02:50 +01004853 while winline() < swwline
4854 let curwinline= winline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004855 exe "sil! NetrwKeepj norm! \<c-y>"
Bram Moolenaara6878372014-03-22 21:02:50 +01004856 if curwinline == winline()
4857 break
4858 endif
4859 endwhile
4860 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004861" call Decho("case: not treestyle")
Bram Moolenaara6878372014-03-22 21:02:50 +01004862 if a:islocal
4863 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
4864 else
4865 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
4866 endif
4867 if exists("w:netrw_bannercnt")
4868" call Decho("moving to line#".w:netrw_bannercnt)
4869 exe w:netrw_bannercnt
4870 else
4871 1
4872 endif
4873 endif
4874" call Dret("s:NetrwBrowseUpDir")
4875endfun
4876
4877" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004878" netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01004879" given filename; typically this means given their extension.
4880" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004881fun! netrw#BrowseX(fname,remote)
4882" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.")")
4883
4884 " if its really just a directory, then do a "gf" instead
4885 if a:fname =~ '/$'
4886 norm! gf
4887" call Dret("netrw#BrowseX : did gf instead")
4888 endif
4889
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890
Bram Moolenaar97d62492012-11-15 21:28:22 +01004891 let ykeep = @@
Bram Moolenaara6878372014-03-22 21:02:50 +01004892 let screenposn = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +01004893
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004894 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
4895 let awkeep = &aw
4896 set noaw
4897
Bram Moolenaar5c736222010-01-06 20:54:52 +01004898 " special core dump handler
4899 if a:fname =~ '/core\(\.\d\+\)\=$'
4900 if exists("g:Netrw_corehandler")
4901 if type(g:Netrw_corehandler) == 2
4902 " g:Netrw_corehandler is a function reference (see :help Funcref)
4903" call Decho("g:Netrw_corehandler is a funcref")
4904 call g:Netrw_corehandler(a:fname)
Bram Moolenaarff034192013-04-24 18:51:19 +02004905 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01004906 " g:Netrw_corehandler is a List of function references (see :help Funcref)
4907" call Decho("g:Netrw_corehandler is a List")
4908 for Fncref in g:Netrw_corehandler
4909 if type(FncRef) == 2
4910 call FncRef(a:fname)
4911 endif
4912 endfor
4913 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004914 call netrw#RestorePosn(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004915 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004916 let &aw= awkeep
4917" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004918 return
4919 endif
4920 endif
4921
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 " set up the filename
4923 " (lower case the extension, make a local copy of a remote file)
4924 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
4925 if has("win32") || has("win95") || has("win64") || has("win16")
4926 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00004927 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928" call Decho("exten<".exten.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929
Bram Moolenaar446cb832008-06-24 21:56:24 +00004930 if a:remote == 1
4931 " create a local copy
Bram Moolenaara6878372014-03-22 21:02:50 +01004932" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">")
Bram Moolenaarff034192013-04-24 18:51:19 +02004933 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01004934 call netrw#NetRead(3,a:fname)
4935 " attempt to rename tempfile
4936 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01004937 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938" call Decho("basename<".basename.">")
4939" call Decho("newname <".newname.">")
4940 if rename(s:netrw_tmpfile,newname) == 0
4941 " renaming succeeded
4942 let fname= newname
4943 else
4944 " renaming failed
4945 let fname= s:netrw_tmpfile
4946 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00004947 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004948" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00004949 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004950 " special ~ handler for local
4951 if fname =~ '^\~' && expand("$HOME") != ""
4952" call Decho('invoking special ~ handler')
4953 let fname= substitute(fname,'^\~',expand("$HOME"),'')
4954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004956" call Decho("fname<".fname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten))
4958
4959 " set up redirection
4960 if &srr =~ "%s"
4961 if (has("win32") || has("win95") || has("win64") || has("win16"))
4962 let redir= substitute(&srr,"%s","nul","")
4963 else
4964 let redir= substitute(&srr,"%s","/dev/null","")
4965 endif
4966 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
4967 let redir= &srr . "nul"
4968 else
4969 let redir= &srr . "/dev/null"
4970 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004971" call Decho("set up redirection: redir{".redir."} srr{".&srr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972
4973 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004974" call Decho("extract any viewing options")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004975 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5c736222010-01-06 20:54:52 +01004976" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004977 if g:netrw_browsex_viewer =~ '\s'
4978 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
4979 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
4980 let oviewer = ''
4981 let cnt = 1
4982 while !executable(viewer) && viewer != oviewer
4983 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
4984 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
4985 let cnt = cnt + 1
4986 let oviewer = viewer
4987" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">")
4988 endwhile
4989 else
4990 let viewer = g:netrw_browsex_viewer
4991 let viewopt = ""
4992 endif
4993" call Decho("viewer<".viewer."> viewopt<".viewopt.">")
4994 endif
4995
4996 " execute the file handler
Bram Moolenaar97d62492012-11-15 21:28:22 +01004997" call Decho("execute the file handler (if any)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
4999" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
5000 let ret= netrwFileHandlers#Invoke(exten,fname)
5001
5002 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
5003" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005004 call s:NetrwExe("sil !".viewer." ".viewopt.shellescape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 let ret= v:shell_error
5006
5007 elseif has("win32") || has("win64")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005008" call Decho("windows")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005009 if executable("start")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005010 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005011 elseif executable("rundll32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005012 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.shellescape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005013 else
5014 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005016 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
5017 let ret= v:shell_error
5018
Bram Moolenaar97d62492012-11-15 21:28:22 +01005019 elseif has("win32unix")
5020 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
5021" call Decho("cygwin: winfname<".shellescape(winfname,1).">")
5022 if executable("start")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005023 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005024 elseif executable("rundll32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005025 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.shellescape(winfname,1))
5026 elseif executable("cygstart")
5027 call s:NetrwExe('sil !cygstart '.shellescape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005028 else
5029 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5030 endif
5031 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
5032 let ret= v:shell_error
5033
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005034 elseif has("unix") && executable("xdg-open") && !s:CheckIfKde()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005035" call Decho("unix and xdg-open")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005036 call s:NetrwExe("sil !xdg-open ".shellescape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005037 let ret= v:shell_error
5038
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005039 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005040" call Decho("unix and kfmclient")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005041 call s:NetrwExe("sil !kfmclient exec ".shellescape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042 let ret= v:shell_error
5043
5044 elseif has("macunix") && executable("open")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005045" call Decho("macunix and open")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005046 call s:NetrwExe("sil !open ".shellescape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047 let ret= v:shell_error
5048
5049 else
5050 " netrwFileHandlers#Invoke() always returns 0
5051 let ret= netrwFileHandlers#Invoke(exten,fname)
5052 endif
5053
5054 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5055 if ret
5056 let ret= netrwFileHandlers#Invoke(exten,fname)
5057 endif
5058
Bram Moolenaarc236c162008-07-13 17:41:49 +00005059 " restoring redraw! after external file handlers
5060 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061
5062 " cleanup: remove temporary file,
5063 " delete current buffer if success with handler,
5064 " return to prior buffer (directory listing)
5065 " Feb 12, 2008: had to de-activiate removal of
5066 " temporary file because it wasn't getting seen.
5067" if a:remote == 1 && fname != a:fname
Bram Moolenaar97d62492012-11-15 21:28:22 +01005068"" call Decho("deleting temporary file<".fname.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +00005069" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070" endif
5071
5072 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005073 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005074 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005075 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005077 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005078" redraw!
5079 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005080 call netrw#RestorePosn(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005081 let @@ = ykeep
5082 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005083
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005084" call Dret("netrw#BrowseX")
5085endfun
5086
5087" ---------------------------------------------------------------------
5088" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5089fun! netrw#BrowseXVis()
5090" call Dfunc("netrw#BrowseXVis()")
5091 let atkeep = @@
5092 norm! gvy
5093" call Decho("@@<".@@.">")
5094 call netrw#BrowseX(@@,netrw#CheckIfRemote())
5095 let @@ = atkeep
5096" call Dret("netrw#BrowseXVis")
5097endfun
5098
5099" ---------------------------------------------------------------------
5100" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
5101fun! netrw#CheckIfRemote()
5102" call Dfunc("netrw#CheckIfRemote()")
5103 if expand("%") =~ '^\a\+://'
5104" call Dret("netrw#CheckIfRemote 1")
5105 return 1
5106 else
5107" call Dret("netrw#CheckIfRemote 0")
5108 return 0
5109 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005110endfun
5111
5112" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005113" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5114fun! s:NetrwChgPerm(islocal,curdir)
5115" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005116 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005117 call inputsave()
5118 let newperm= input("Enter new permission: ")
5119 call inputrestore()
5120 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',shellescape(expand("<cfile>")),'')
5121 let chgperm= substitute(chgperm,'\<PERM\>',shellescape(newperm),'')
5122" call Decho("chgperm<".chgperm.">")
5123 call system(chgperm)
5124 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005125 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005126 endif
5127 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005128 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005129 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005130 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005131" call Dret("s:NetrwChgPerm")
5132endfun
5133
5134" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005135" s:CheckIfKde: checks if kdeinit is running {{{2
5136" Returns 0: kdeinit not running
5137" 1: kdeinit is running
5138fun! s:CheckIfKde()
5139" call Dfunc("s:CheckIfKde()")
5140 " seems kde systems often have gnome-open due to dependencies, even though
5141 " gnome-open's subsidiary display tools are largely absent. Kde systems
5142 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5143 if !exists("s:haskdeinit")
5144 if has("unix") && executable("ps") && !has("win32unix")
5145 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
5146 if v:shell_error
5147 let s:haskdeinit = 0
5148 endif
5149 else
5150 let s:haskdeinit= 0
5151 endif
5152" call Decho("setting s:haskdeinit=".s:haskdeinit)
5153 endif
5154
5155" call Dret("s:CheckIfKde ".s:haskdeinit)
5156 return s:haskdeinit
5157endfun
5158
5159" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005160" s:NetrwClearExplore: clear explore variables (if any) {{{2
5161fun! s:NetrwClearExplore()
5162" call Dfunc("s:NetrwClearExplore()")
5163 2match none
5164 if exists("s:explore_match") |unlet s:explore_match |endif
5165 if exists("s:explore_indx") |unlet s:explore_indx |endif
5166 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5167 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5168 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5169 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5170 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5171 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5172 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5173" redraw!
5174 echo " "
5175 echo " "
5176" call Dret("s:NetrwClearExplore")
5177endfun
5178
5179" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005180" s:NetrwExploreListUniq: {{{2
5181fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005182" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005183
5184 " this assumes that the list is already sorted
5185 let newexplist= []
5186 for member in a:explist
5187 if !exists("uniqmember") || member != uniqmember
5188 let uniqmember = member
5189 let newexplist = newexplist + [ member ]
5190 endif
5191 endfor
5192
Bram Moolenaar15146672011-10-20 22:22:38 +02005193" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005194 return newexplist
5195endfun
5196
5197" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005198" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5199fun! s:NetrwForceChgDir(islocal,newdir)
5200" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005201 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005202 if a:newdir !~ '/$'
5203 " ok, looks like force is needed to get directory-style treatment
5204 if a:newdir =~ '@$'
5205 let newdir= substitute(a:newdir,'@$','/','')
5206 elseif a:newdir =~ '[*=|\\]$'
5207 let newdir= substitute(a:newdir,'.$','/','')
5208 else
5209 let newdir= a:newdir.'/'
5210 endif
5211" call Decho("adjusting newdir<".newdir."> due to gd")
5212 else
5213 " should already be getting treatment as a directory
5214 let newdir= a:newdir
5215 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005216 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005217 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005218 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005219" call Dret("s:NetrwForceChgDir")
5220endfun
5221
5222" ---------------------------------------------------------------------
5223" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5224fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005225" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005226 if a:newfile =~ '[/@*=|\\]$'
5227 let newfile= substitute(a:newfile,'.$','','')
5228 else
5229 let newfile= a:newfile
5230 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005231 if a:islocal
5232 call s:NetrwBrowseChgDir(a:islocal,newfile)
5233 else
5234 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5235 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005236" call Dret("s:NetrwForceFile")
5237endfun
5238
5239" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005240" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5241" and switches the hiding mode. The actual hiding is done by
5242" s:NetrwListHide().
5243" g:netrw_hide= 0: show all
5244" 1: show not-hidden files
5245" 2: show hidden files only
5246fun! s:NetrwHide(islocal)
5247" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005248 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01005249 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005250
5251 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara6878372014-03-22 21:02:50 +01005252" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005253" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">")
5254
5255 " hide the files in the markfile list
5256 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02005257" 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 +00005258 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5259 " remove fname from hiding list
5260 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5261 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5262 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
5263" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">")
5264 else
5265 " append fname to hiding list
5266 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5267 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5268 else
5269 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5270 endif
5271" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">")
5272 endif
5273 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005274 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005275 let g:netrw_hide= 1
5276
5277 else
5278
5279 " switch between show-all/show-not-hidden/show-hidden
5280 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005281 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005282 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005283 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005284 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005285" call Dret("NetrwHide")
5286 return
5287 endif
5288 endif
5289
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005290 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5291 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005292 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005293" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005294endfun
5295
5296" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005297" s:NetrwHidden: invoked by "gh" {{{2
5298fun! s:NetrwHidden(islocal)
5299" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005300 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005301 " save current position
Bram Moolenaara6878372014-03-22 21:02:50 +01005302 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005303
5304 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
5305 " remove pattern from hiding list
5306 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005307 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005308 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5309 else
5310 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5311 endif
5312
5313 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005314 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5315 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005316 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005317" call Dret("s:NetrwHidden")
5318endfun
5319
5320" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005321" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5322fun! s:NetrwHome()
5323 if exists("g:netrw_home")
5324 let home= g:netrw_home
5325 else
5326 " go to vim plugin home
5327 for home in split(&rtp,',') + ['']
5328 if isdirectory(home) && filewritable(home) | break | endif
5329 let basehome= substitute(home,'[/\\]\.vim$','','')
5330 if isdirectory(basehome) && filewritable(basehome)
5331 let home= basehome."/.vim"
5332 break
5333 endif
5334 endfor
5335 if home == ""
5336 " just pick the first directory
5337 let home= substitute(&rtp,',.*$','','')
5338 endif
5339 if (has("win32") || has("win95") || has("win64") || has("win16"))
5340 let home= substitute(home,'/','\\','g')
5341 endif
5342 endif
5343 " insure that the home directory exists
Bram Moolenaarff034192013-04-24 18:51:19 +02005344 if g:netrw_dirhistmax > 0 && !isdirectory(home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 if exists("g:netrw_mkdir")
5346 call system(g:netrw_mkdir." ".shellescape(home))
5347 else
5348 call mkdir(home)
5349 endif
5350 endif
5351 let g:netrw_home= home
5352 return home
5353endfun
5354
5355" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5357fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005358 if exists("s:netrwdrag")
5359 return
5360 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005361" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005362
Bram Moolenaar97d62492012-11-15 21:28:22 +01005363 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005364 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005365 while getchar(0) != 0
5366 "clear the input stream
5367 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005368 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005369 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005370 let mouse_lnum = v:mouse_lnum
5371 let wlastline = line('w$')
5372 let lastline = line('$')
5373" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr())
5374" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0))
5375 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5376 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005377 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005378" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5379 return
5380 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005381 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005382 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005383 " without this test when its disabled.
5384 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
5385" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"))
5386 if v:mouse_col > virtcol('.')
5387 let @@= ykeep
5388" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5389 return
5390 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005391
Bram Moolenaar446cb832008-06-24 21:56:24 +00005392 if a:islocal
5393 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005394 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005395 endif
5396 else
5397 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005398 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399 endif
5400 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005401 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402" call Dret("s:NetrwLeftmouse")
5403endfun
5404
5405" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005406" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5407" a:islocal=0 : <c-r> not used, remote
5408" a:islocal=1 : <c-r> no used, local
5409" a:islocal=2 : <c-r> used, remote
5410" a:islocal=3 : <c-r> used, local
5411fun! s:NetrwServerEdit(islocal,fname)
5412" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5413 let islocal = a:islocal%2 " =0: remote =1: local
5414 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5415
5416 if (islocal && isdirectory(a:fname)) || (!islocal && a:fname =~ '/$')
5417 " handle directories in the local window -- not in the remote vim server
5418 " user must have closed the NETRWSERVER window. Treat as a normal editing from netrw.
5419 let g:netrw_browse_split= 0
5420 if exists("s:netrw_browse_split_".winnr())
5421 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5422 unlet s:netrw_browse_split_{winnr()}
5423 endif
5424 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5425" call Dret("s:NetrwServerEdit")
5426 return
5427 endif
5428
5429 if has("clientserver") && executable("gvim")
5430" call Decho("has clientserver and gvim")
5431
5432 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
5433" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split))
5434 let srvrname = g:netrw_browse_split[0]
5435 let tabnum = g:netrw_browse_split[1]
5436 let winnum = g:netrw_browse_split[2]
5437
5438 if serverlist() !~ '\<'.srvrname.'\>'
5439" call Decho("server not available; ctrlr=".ctrlr)
5440
5441 if !ctrlr
5442 " user must have closed the server window and the user did not use <c-r>, but
5443 " used something like <cr>.
5444" call Decho("user must have closed server AND did not use ctrl-r")
5445 if exists("g:netrw_browse_split")
5446 unlet g:netrw_browse_split
5447 endif
5448 let g:netrw_browse_split= 0
5449 if exists("s:netrw_browse_split_".winnr())
5450 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5451 endif
5452 call s:NetrwBrowseChgDir(islocal,a:fname)
5453" call Dret("s:NetrwServerEdit")
5454 return
5455
5456 elseif has("win32") && executable("start")
5457 " start up remote netrw server under windows
5458" call Decho("starting up gvim server<".srvrname."> for windows")
5459 call system("start gvim --servername ".srvrname)
5460
5461 else
5462 " start up remote netrw server under linux
5463" call Decho("starting up gvim server<".srvrname.">")
5464 call system("gvim --servername ".srvrname)
5465 endif
5466 endif
5467
5468" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">")
5469 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5470 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
5471 call remote_send(srvrname,":e ".fnameescape(a:fname)."\<cr>")
5472
5473 else
5474
5475 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5476
5477 if !ctrlr
5478" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used")
5479 if exists("g:netrw_browse_split")
5480 unlet g:netrw_browse_split
5481 endif
5482 let g:netrw_browse_split= 0
5483 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5484" call Dret("s:NetrwServerEdit")
5485 return
5486
5487 else
5488" call Decho("server<".g:netrw_servername."> not available but ctrl-r used")
5489 if has("win32") && executable("start")
5490 " start up remote netrw server under windows
5491" call Decho("starting up gvim server<".g:netrw_servername."> for windows")
5492 call system("start gvim --servername ".g:netrw_servername)
5493 else
5494 " start up remote netrw server under linux
5495" call Decho("starting up gvim server<".g:netrw_servername.">")
5496 call system("gvim --servername ".g:netrw_servername)
5497 endif
5498 endif
5499 endif
5500
5501 while 1
5502 try
5503" call Decho("remote-send: e ".a:fname)
5504 call remote_send(g:netrw_servername,":e ".fnameescape(a:fname)."\<cr>")
5505 break
5506 catch /^Vim\%((\a\+)\)\=:E241/
5507 sleep 200m
5508 endtry
5509 endwhile
5510
5511 if exists("g:netrw_browse_split")
5512 if type(g:netrw_browse_split) != 3
5513 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5514 endif
5515 unlet g:netrw_browse_split
5516 endif
5517 let g:netrw_browse_split= [g:netrw_servername,1,1]
5518 endif
5519
5520 else
5521 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5522 endif
5523
5524" call Dret("s:NetrwServerEdit")
5525endfun
5526
5527" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005528" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5529fun! s:NetrwSLeftmouse(islocal)
5530" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
5531
5532 let s:ngw= s:NetrwGetWord()
5533 call s:NetrwMarkFile(a:islocal,s:ngw)
5534
5535" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005536endfun
5537
5538" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005539" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5540" Used to mark multiple files.
5541fun! s:NetrwSLeftdrag(islocal)
5542" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5543 if !exists("s:netrwdrag")
5544 let s:netrwdrag = winnr()
5545 if a:islocal
5546 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005547 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005548 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005549 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005550 endif
5551 let ngw = s:NetrwGetWord()
5552 if !exists("s:ngw") || s:ngw != ngw
5553 call s:NetrwMarkFile(a:islocal,ngw)
5554 endif
5555 let s:ngw= ngw
5556" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5557endfun
5558
5559" ---------------------------------------------------------------------
5560" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5561fun! s:NetrwSLeftrelease(islocal)
5562" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5563 if exists("s:netrwdrag")
5564 nunmap <s-leftrelease>
5565 let ngw = s:NetrwGetWord()
5566 if !exists("s:ngw") || s:ngw != ngw
5567 call s:NetrwMarkFile(a:islocal,ngw)
5568 endif
5569 if exists("s:ngw")
5570 unlet s:ngw
5571 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005572 unlet s:netrwdrag
5573 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005574" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005575endfun
5576
5577" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005578" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
5579" separated patterns given in g:netrw_list_hide
5580fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005581" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005582 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005583
5584 " find a character not in the "hide" string to use as a separator for :g and :v commands
5585 " How-it-works: take the hiding command, convert it into a range. Duplicate
5586 " characters don't matter. Remove all such characters from the '/~...90'
5587 " string. Use the first character left as a separator character.
5588 let listhide= g:netrw_list_hide
5589 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
5590" call Decho("sep=".sep)
5591
5592 while listhide != ""
5593 if listhide =~ ','
5594 let hide = substitute(listhide,',.*$','','e')
5595 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5596 else
5597 let hide = listhide
5598 let listhide = ""
5599 endif
5600
5601 " Prune the list by hiding any files which match
5602 if g:netrw_hide == 1
5603" call Decho("hiding<".hide."> listhide<".listhide.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005604 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005605 elseif g:netrw_hide == 2
5606" call Decho("showing<".hide."> listhide<".listhide.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005607 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005608 endif
5609 endwhile
5610 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005611 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
5612 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005613 endif
5614
Bram Moolenaaradc21822011-04-01 18:03:16 +02005615 " remove any blank lines that have somehow remained.
5616 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005617 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005618
Bram Moolenaar97d62492012-11-15 21:28:22 +01005619 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005620" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005621endfun
5622
5623" ---------------------------------------------------------------------
5624" NetrwHideEdit: allows user to edit the file/directory hiding list
5625fun! s:NetrwHideEdit(islocal)
5626" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5627
Bram Moolenaar97d62492012-11-15 21:28:22 +01005628 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005629 " save current cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005630 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005631
5632 " get new hiding list from user
5633 call inputsave()
5634 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5635 call inputrestore()
5636 let g:netrw_list_hide= newhide
5637" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">")
5638
5639 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005640 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005641
5642 " restore cursor position
Bram Moolenaara6878372014-03-22 21:02:50 +01005643 call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005644 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005645
5646" call Dret("NetrwHideEdit")
5647endfun
5648
5649" ---------------------------------------------------------------------
5650" NetSortSequence: allows user to edit the sorting sequence
5651fun! s:NetSortSequence(islocal)
5652" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
5653
Bram Moolenaar97d62492012-11-15 21:28:22 +01005654 let ykeep= @@
Bram Moolenaara6878372014-03-22 21:02:50 +01005655 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005656 call inputsave()
5657 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
5658 call inputrestore()
5659
5660 " refresh the listing
5661 let g:netrw_sort_sequence= newsortseq
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005662 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
5663 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005664 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005665
5666" call Dret("NetSortSequence")
5667endfun
5668
5669" ---------------------------------------------------------------------
5670" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005671" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005672fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01005673" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005674
Bram Moolenaar97d62492012-11-15 21:28:22 +01005675 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005676 " get name of new directory from user. A bare <CR> will skip.
5677 " if its currently a directory, also request will be skipped, but with
5678 " a message.
5679 call inputsave()
5680 let newdirname= input("Please give directory name: ")
5681 call inputrestore()
5682" call Decho("newdirname<".newdirname.">")
5683
5684 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005685 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005686" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005687 return
5688 endif
5689
5690 if a:usrhost == ""
5691" call Decho("local mkdir")
5692
5693 " Local mkdir:
5694 " sanity checks
5695 let fullnewdir= b:netrw_curdir.'/'.newdirname
5696" call Decho("fullnewdir<".fullnewdir.">")
5697 if isdirectory(fullnewdir)
5698 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005699 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005700 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005701 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005702" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005703 return
5704 endif
5705 if s:FileReadable(fullnewdir)
5706 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005707 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005708 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005709 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005710" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005711 return
5712 endif
5713
5714 " requested new local directory is neither a pre-existing file or
5715 " directory, so make it!
5716 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005717 if has("unix")
5718 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5719 else
5720 call mkdir(fullnewdir,"p")
5721 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005722 else
5723 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaara6878372014-03-22 21:02:50 +01005724 call s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005725" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005726 call s:NetrwExe("sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005727 if v:shell_error != 0
5728 let @@= ykeep
5729 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 +01005730" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.shellescape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005731 return
5732 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005733 if !g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01005734" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir)
5735 call s:NetrwLcd(netrw_origdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005736 endif
5737 endif
5738
5739 if v:shell_error == 0
5740 " refresh listing
5741" call Decho("refresh listing")
Bram Moolenaara6878372014-03-22 21:02:50 +01005742 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005743 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01005744 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005745 elseif !exists("g:netrw_quiet")
5746 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5747 endif
5748" redraw!
5749
5750 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005751 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005752" call Decho("remote mkdir")
5753 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5754 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005755 call s:NetrwExe("sil! !".mkdircmd." ".shellescape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005756 if v:shell_error == 0
5757 " refresh listing
Bram Moolenaara6878372014-03-22 21:02:50 +01005758 let svpos= netrw#SavePosn()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005759 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
5760 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005761 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005762 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005763 endif
5764" redraw!
5765
5766 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005767 " Remote mkdir: using ftp+.netrc
5768 let svpos= netrw#SavePosn()
5769" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5770 if exists("b:netrw_fname")
5771" call Decho("b:netrw_fname<".b:netrw_fname.">")
5772 let remotepath= b:netrw_fname
5773 else
5774 let remotepath= ""
5775 endif
5776 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005777 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
5778 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01005779
Bram Moolenaar446cb832008-06-24 21:56:24 +00005780 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005781 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
5782 let svpos= netrw#SavePosn()
5783" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
5784 if exists("b:netrw_fname")
5785" call Decho("b:netrw_fname<".b:netrw_fname.">")
5786 let remotepath= b:netrw_fname
5787 else
5788 let remotepath= ""
5789 endif
5790 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005791 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
5792 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005793 endif
5794
Bram Moolenaar97d62492012-11-15 21:28:22 +01005795 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005796" call Dret("s:NetrwMakeDir")
5797endfun
5798
5799" ---------------------------------------------------------------------
5800" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
5801fun! s:TreeSqueezeDir(islocal)
5802" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
5803 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5804 " its a tree-listing style
5805 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5806 let iline = line(".") - 1
5807 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
5808" call Decho("curdepth=".curdepth)
5809" call Decho("stopline#".stopline)
5810" call Decho("starting with line#".line(".").": ".getline('.'))
5811 while iline > stopline
5812 " find a line that has less depth
5813 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
5814" call Decho("considering line#".line(".").": ".getline('.'))
5815 if depth < curdepth
5816 break
5817 endif
5818 norm! k
5819 endwhile
5820" call Decho("squeezing at line#".line(".").": ".getline('.'))
5821 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
5822 endif
5823" call Dret("s:TreeSqueezeDir")
5824endfun
5825
5826" ---------------------------------------------------------------------
5827" s:NetrwMaps: {{{2
5828fun! s:NetrwMaps(islocal)
5829" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
5830
5831 if g:netrw_mousemaps && g:netrw_retmap
5832" call Decho("set up Rexplore 2-leftmouse")
5833 if !hasmapto("<Plug>NetrwReturn")
5834 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
5835" call Decho("making map for 2-leftmouse")
5836 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
5837 elseif maparg("<c-leftmouse>","n") == ""
5838" call Decho("making map for c-leftmouse")
5839 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
5840 endif
5841 endif
5842 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
5843" call Decho("made <Plug>NetrwReturn map")
5844 endif
5845
5846 if a:islocal
5847" call Decho("make local maps")
5848 " local normal-mode maps
5849 nnoremap <buffer> <silent> a :call <SID>NetrwHide(1)<cr>
5850 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(1)<cr>
5851 nnoremap <buffer> <silent> c :call <SID>NetrwLcd(b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005852 nnoremap <buffer> <silent> C :<c-u>call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005853 nnoremap <buffer> <silent> <cr> :call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5854 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005855 nnoremap <buffer> <silent> <c-r> :call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005856 nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>
5857 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(1)<cr>
5858 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5859 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
5860 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
5861 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(1)<cr>
5862 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5863 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
5864 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(1)<cr>
5865 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5866 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5867 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5868 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5869 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5870 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5871 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
5872 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5873 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5874 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5875 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5876 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5877 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5878 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5879 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5880 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 nnoremap <buffer> <silent> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5882 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
5883 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005884 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5885 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(1)<cr>
5886 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(3)<cr>
5887 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5888 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(1)<cr>
5889 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5890 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5891 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5892 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>
5893 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(1)<cr>
5894 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(1)<cr>
5895 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(4)<cr>
5896 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5897 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5898 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5899 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5900 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 nnoremap <buffer> <silent> x :call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005902 nnoremap <buffer> <silent> X :call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
5903 " local insert-mode maps
5904 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(1)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005905 inoremap <buffer> <silent> c <c-o>:exe "NetrwKeepj lcd ".fnameescape(b:netrw_curdir)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005906 inoremap <buffer> <silent> c <c-o>:call <SID>NetrwLcd(b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02005907 inoremap <buffer> <silent> C <c-o>:call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005908 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(1)<cr>
5909 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(1)<cr>
5910 inoremap <buffer> <silent> <cr> <c-o>:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
5911 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(1)<cr>
5912 inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>
5913 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
5914 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(1)<cr>
5915 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
5916 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
5917 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(1)<cr>
5918 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
5919 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
5920 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
5921 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
5922 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
5923 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5924 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
5925 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
5926 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(1)<cr>
5927 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
5928 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
5929 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(1)<cr>
5930 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(1)<cr>
5931 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
5932 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(1)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005933 inoremap <buffer> <silent> mv <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
5934 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
5935 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005936 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
5937 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(1)<cr>
5938 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(3)<cr>
5939 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
5940 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5941 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
5942 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
5943 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
5944 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>
5945 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(1)<cr>
5946 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(1)<cr>
5947 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(4)<cr>
5948 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
5949 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
5950 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
5951 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
5952 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(5)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005953 inoremap <buffer> <silent> x <c-o>:call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01005954 if !hasmapto('<Plug>NetrwHideEdit')
5955 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5956 imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
5957 endif
5958 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
5959 if !hasmapto('<Plug>NetrwRefresh')
5960 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5961 imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
5962 endif
5963 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
5964 if s:didstarstar || !mapcheck("<s-down>","n")
5965 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
5966 inoremap <buffer> <silent> <s-down> :Nexplore<cr>
5967 endif
5968 if s:didstarstar || !mapcheck("<s-up>","n")
5969 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
5970 inoremap <buffer> <silent> <s-up> :Pexplore<cr>
5971 endif
5972 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
5973 if g:netrw_mousemaps == 1
5974 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
5975 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
5976 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
5977 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
5978 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
5979 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
5980 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
5981 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
5982 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
5983 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
5984 imap <buffer> <leftmouse> <Plug>ILeftmouse
5985 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(1)<cr>
5986 imap <buffer> <middlemouse> <Plug>IMiddlemouse
5987 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(1)<cr>
5988 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
5989 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
5990 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5991 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5992 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5993 endif
5994 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5995 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5996 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
5997 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("")<cr>'
5998 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
5999 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6000 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6001 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6002 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6003 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6004 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("")<cr>'
6005 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6006
6007 else " remote
6008" call Decho("make remote maps")
6009 call s:RemotePathAnalysis(b:netrw_curdir)
6010 " remote normal-mode maps
6011 nnoremap <buffer> <silent> <cr> :call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6012 nnoremap <buffer> <silent> <s-cr> :call <SID>TreeSqueezeDir(0)<cr>
6013 nnoremap <buffer> <silent> <c-l> :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006014 nnoremap <buffer> <silent> <c-r> :call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006015 nnoremap <buffer> <silent> - :call <SID>NetrwBrowseUpDir(0)<cr>
6016 nnoremap <buffer> <silent> a :call <SID>NetrwHide(0)<cr>
6017 nnoremap <buffer> <silent> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6018 nnoremap <buffer> <silent> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6019 nnoremap <buffer> <silent> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6020 nnoremap <buffer> <silent> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6021 nnoremap <buffer> <silent> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6022 nnoremap <buffer> <silent> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6023 nnoremap <buffer> <silent> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6024 nnoremap <buffer> <silent> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6025 nnoremap <buffer> <silent> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6026 nnoremap <buffer> <silent> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6027 nnoremap <buffer> <silent> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6028 nnoremap <buffer> <silent> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
6029 nnoremap <buffer> <silent> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
6030 nnoremap <buffer> <silent> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
6031 nnoremap <buffer> <silent> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006032 nnoremap <buffer> <silent> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6033 nnoremap <buffer> <silent> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6034 nnoremap <buffer> <silent> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006035 nnoremap <buffer> <silent> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
6036 nnoremap <buffer> <silent> gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6037 nnoremap <buffer> <silent> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6038 nnoremap <buffer> <silent> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6039 nnoremap <buffer> <silent> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6040 nnoremap <buffer> <silent> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02006041 nnoremap <buffer> <silent> C :<c-u>call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006042 nnoremap <buffer> <silent> i :call <SID>NetrwListStyle(0)<cr>
6043 nnoremap <buffer> <silent> I :call <SID>NetrwBannerCtrl(1)<cr>
6044 nnoremap <buffer> <silent> o :call <SID>NetrwSplit(0)<cr>
6045 nnoremap <buffer> <silent> O :call <SID>NetrwObtain(0)<cr>
6046 nnoremap <buffer> <silent> p :call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6047 nnoremap <buffer> <silent> P :call <SID>NetrwPrevWinOpen(0)<cr>
6048 nnoremap <buffer> <silent> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6049 nnoremap <buffer> <silent> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6050 nnoremap <buffer> <silent> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6051 nnoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
6052 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>
6053 nnoremap <buffer> <silent> s :call <SID>NetrwSortStyle(0)<cr>
6054 nnoremap <buffer> <silent> S :call <SID>NetSortSequence(0)<cr>
6055 nnoremap <buffer> <silent> t :call <SID>NetrwSplit(1)<cr>
6056 nnoremap <buffer> <silent> Tb :<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
6057 nnoremap <buffer> <silent> Th :<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
6058 nnoremap <buffer> <silent> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6059 nnoremap <buffer> <silent> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6060 nnoremap <buffer> <silent> v :call <SID>NetrwSplit(2)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061 nnoremap <buffer> <silent> x :call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006062 nnoremap <buffer> <silent> % :call <SID>NetrwOpenFile(0)<cr>
6063 " remote insert-mode maps
6064 inoremap <buffer> <silent> <cr> <c-o>:call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6065 inoremap <buffer> <silent> <c-l> <c-o>:call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6066 inoremap <buffer> <silent> <s-cr> <c-o>:call <SID>TreeSqueezeDir(0)<cr>
6067 inoremap <buffer> <silent> - <c-o>:call <SID>NetrwBrowseUpDir(0)<cr>
6068 inoremap <buffer> <silent> a <c-o>:call <SID>NetrwHide(0)<cr>
6069 inoremap <buffer> <silent> mb <c-o>:<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6070 inoremap <buffer> <silent> mc <c-o>:<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6071 inoremap <buffer> <silent> md <c-o>:<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6072 inoremap <buffer> <silent> me <c-o>:<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6073 inoremap <buffer> <silent> mf <c-o>:<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6074 inoremap <buffer> <silent> mg <c-o>:<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6075 inoremap <buffer> <silent> mh <c-o>:<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6076 inoremap <buffer> <silent> mm <c-o>:<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6077 inoremap <buffer> <silent> mp <c-o>:<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6078 inoremap <buffer> <silent> mr <c-o>:<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6079 inoremap <buffer> <silent> ms <c-o>:<c-u>call <SID>NetrwMarkFileSource(0)<cr>
6080 inoremap <buffer> <silent> mt <c-o>:<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
6081 inoremap <buffer> <silent> mT <c-o>:<c-u>call <SID>NetrwMarkFileTag(0)<cr>
6082 inoremap <buffer> <silent> mu <c-o>:<c-u>call <SID>NetrwUnMarkFile(0)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083 nnoremap <buffer> <silent> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6084 inoremap <buffer> <silent> mx <c-o>:<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6085 inoremap <buffer> <silent> mX <c-o>:<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6086 inoremap <buffer> <silent> mv <c-o>:<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006087 inoremap <buffer> <silent> mz <c-o>:<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
6088 inoremap <buffer> <silent> gb <c-o>:<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6089 inoremap <buffer> <silent> gh <c-o>:<c-u>call <SID>NetrwHidden(0)<cr>
6090 inoremap <buffer> <silent> gp <c-o>:<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
Bram Moolenaar13600302014-05-22 18:26:40 +02006091 inoremap <buffer> <silent> C <c-o>:call <SID>NetrwSetChgwin()<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006092 inoremap <buffer> <silent> i <c-o>:call <SID>NetrwListStyle(0)<cr>
6093 inoremap <buffer> <silent> I <c-o>:call <SID>NetrwBannerCtrl(1)<cr>
6094 inoremap <buffer> <silent> o <c-o>:call <SID>NetrwSplit(0)<cr>
6095 inoremap <buffer> <silent> O <c-o>:call <SID>NetrwObtain(0)<cr>
6096 inoremap <buffer> <silent> p <c-o>:call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6097 inoremap <buffer> <silent> P <c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
6098 inoremap <buffer> <silent> qb <c-o>:<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6099 inoremap <buffer> <silent> mB <c-o>:<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6100 inoremap <buffer> <silent> qf <c-o>:<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6101 inoremap <buffer> <silent> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
6102 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>
6103 inoremap <buffer> <silent> s <c-o>:call <SID>NetrwSortStyle(0)<cr>
6104 inoremap <buffer> <silent> S <c-o>:call <SID>NetSortSequence(0)<cr>
6105 inoremap <buffer> <silent> t <c-o>:call <SID>NetrwSplit(1)<cr>
6106 inoremap <buffer> <silent> Tb <c-o>:<c-u>call <SID>NetrwSetTgt('b',v:count1)<cr>
6107 inoremap <buffer> <silent> Th <c-o>:<c-u>call <SID>NetrwSetTgt('h',v:count)<cr>
6108 inoremap <buffer> <silent> u <c-o>:<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6109 inoremap <buffer> <silent> U <c-o>:<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6110 inoremap <buffer> <silent> v <c-o>:call <SID>NetrwSplit(2)<cr>
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006111 inoremap <buffer> <silent> x <c-o>:call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006112 inoremap <buffer> <silent> % <c-o>:call <SID>NetrwOpenFile(0)<cr>
6113 if !hasmapto('<Plug>NetrwHideEdit')
6114 nmap <buffer> <c-h> <Plug>NetrwHideEdit
6115 imap <buffer> <c-h> <Plug>NetrwHideEdit
6116 endif
6117 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6118 if !hasmapto('<Plug>NetrwRefresh')
6119 nmap <buffer> <c-l> <Plug>NetrwRefresh
6120 imap <buffer> <c-l> <Plug>NetrwRefresh
6121 endif
6122
6123 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006125
6126 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6127 if g:netrw_mousemaps == 1
6128 nmap <leftmouse> <Plug>NetrwLeftmouse
6129 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6130 nmap <buffer> <leftdrag> <Plug>NetrwLeftdrag
6131 nno <buffer> <silent> <Plug>NetrwLeftdrag :call <SID>NetrwLeftdrag(0)<cr>
6132 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6133 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6134 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6135 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6136 nmap <middlemouse> <Plug>NetrwMiddlemouse
6137 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6138 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6139 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6140 imap <buffer> <leftmouse> <Plug>ILeftmouse
6141 ino <buffer> <silent> <Plug>ILeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwLeftmouse(0)<cr>
6142 imap <buffer> <middlemouse> <Plug>IMiddlemouse
6143 ino <buffer> <silent> <Plug>IMiddlemouse <c-o><leftmouse><c-o>:call <SID>NetrwPrevWinOpen(0)<cr>
6144 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
6145 ino <buffer> <silent> <Plug>ISLeftmouse <c-o><leftmouse><c-o>:call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6146 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6147 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6148 exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6149 endif
6150 exe 'nnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6151 exe 'nnoremap <buffer> <silent> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6152 exe 'nnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6153 exe 'nnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6154 exe 'vnoremap <buffer> <silent> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6155 exe 'vnoremap <buffer> <silent> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6156 exe 'vnoremap <buffer> <silent> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6157 exe 'inoremap <buffer> <silent> <del> <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6158 exe 'inoremap <buffer> <silent> d <c-o>:call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6159 exe 'inoremap <buffer> <silent> D <c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6160 exe 'inoremap <buffer> <silent> R <c-o>:call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6161 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6162 inoremap <buffer> <F1> <c-o>:he netrw-quickhelp<cr>
6163 endif
6164
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006165 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01006166
6167" call Dret("s:NetrwMaps")
6168endfun
6169
6170" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006171" s:NetrwCommands: sets up commands {{{2
6172" If -buffer, the command is only available from within netrw buffers
6173" Otherwise, the command is available from any window, so long as netrw
6174" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006175fun! s:NetrwCommands(islocal)
6176" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6177
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006178 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6179 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006180 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
6181 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006182 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006183 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006184 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006185 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006186 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
6187 " the following two commands are intended to be used for testing only, so I'm not advertising them in the manual
6188 com! -buffer -nargs=0 CRL call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
6189 com! -buffer -nargs=0 CRR call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))
Bram Moolenaara6878372014-03-22 21:02:50 +01006190
6191" call Dret("s:NetrwCommands")
6192endfun
6193
6194" ---------------------------------------------------------------------
6195" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6196" glob()ing only works with local files
6197fun! s:NetrwMarkFiles(islocal,...)
6198" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
6199 let i = 1
6200 while i <= a:0
6201 if a:islocal
6202 let mffiles= glob(a:{i},0,1)
6203 else
6204 let mffiles= [a:{i}]
6205 endif
6206" call Decho("mffiles".string(mffiles))
6207 for mffile in mffiles
6208" call Decho("mffile<".mffile.">")
6209 call s:NetrwMarkFile(a:islocal,mffile)
6210 endfor
6211 let i= i + 1
6212 endwhile
6213" call Dret("s:NetrwMarkFiles")
6214endfun
6215
6216" ---------------------------------------------------------------------
6217" s:NetrwMarkTarget: {{{2
6218fun! s:NetrwMarkTarget(...)
6219" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6220 if a:0 == 0 || (a:0 == 1 && a:1 == "")
6221 let tgt= b:netrw_curdir
6222 else
6223 let tgt= a:1
6224 endif
6225" call Decho("tgt<".tgt.">")
6226 let s:netrwmftgt = tgt
6227 let s:netrwmftgt_islocal = tgt !~ '^\a\+://'
6228 let curislocal = b:netrw_curdir !~ '^\a\+://'
6229 let svpos = netrw#SavePosn()
6230 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
6231 call netrw#RestorePosn(svpos)
6232" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233endfun
6234
6235" ---------------------------------------------------------------------
6236" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6237" mark and unmark files. If a markfile list exists,
6238" then the rename and delete functions will use it instead
6239" of whatever may happen to be under the cursor at that
6240" moment. When the mouse and gui are available,
6241" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006242"
6243" Creates two lists
6244" s:netrwmarkfilelist -- holds complete paths to all marked files
6245" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6246"
6247" Creates a marked file match string
6248" s:netrwmarfilemtch_# -- used with 2match to display marked files
6249"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006250" Creates a buffer version of islocal
6251" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252fun! s:NetrwMarkFile(islocal,fname)
6253" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaarff034192013-04-24 18:51:19 +02006254
6255 " sanity check
6256 if empty(a:fname)
6257" call Dret("s:NetrwMarkFile : emtpy fname")
6258 return
6259 endif
6260
Bram Moolenaar97d62492012-11-15 21:28:22 +01006261 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006262 let curbufnr= bufnr("%")
6263 let curdir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006264 if a:fname =~ '^\a'
6265 let leader= '\<'
6266 else
6267 let leader= ''
6268 endif
6269 if a:fname =~ '\a$'
6270 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6271 else
6272 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6273 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006274
Bram Moolenaar446cb832008-06-24 21:56:24 +00006275 if exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006276 " markfile list pre-exists
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277" call Decho("starting s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
6278" call Decho("starting s:netrwmarkfilemtch_{curbufnr}<".s:netrwmarkfilemtch_{curbufnr}.">")
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006279 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280
6281 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006282 " append filename to buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
6284 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006285 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286
6287 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006288 " remove filename from buffer's markfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
6290 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6291 if s:netrwmarkfilelist_{curbufnr} == []
6292 " local markfilelist is empty; remove it entirely
Bram Moolenaar5c736222010-01-06 20:54:52 +01006293" call Decho("markfile list now empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294 call s:NetrwUnmarkList(curbufnr,curdir)
6295 else
6296 " rebuild match list to display markings correctly
6297" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr)
6298 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006299 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 for fname in s:netrwmarkfilelist_{curbufnr}
6301 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006302 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006304 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 endif
6306 let first= 0
6307 endfor
Bram Moolenaar15146672011-10-20 22:22:38 +02006308" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 endif
6310 endif
6311
6312 else
6313 " initialize new markfilelist
6314
6315" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr)
6316 let s:netrwmarkfilelist_{curbufnr}= []
6317 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
6318" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">")
6319
6320 " build initial markfile matching pattern
6321 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006322 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006323 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006324 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325 endif
6326" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">")
6327 endif
6328
6329 " handle global markfilelist
6330 if exists("s:netrwmarkfilelist")
6331 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6332 if index(s:netrwmarkfilelist,dname) == -1
6333 " append new filename to global markfilelist
6334 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
6335" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">")
6336 else
6337 " remove new filename from global markfilelist
6338" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")")
6339 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
6340" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">")
6341 if s:netrwmarkfilelist == []
6342 unlet s:netrwmarkfilelist
6343 endif
6344 endif
6345 else
6346 " initialize new global-directory markfilelist
6347 let s:netrwmarkfilelist= []
6348 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
6349" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">")
6350 endif
6351
6352 " set up 2match'ing to netrwmarkfilemtch list
6353 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6354" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006355 if exists("g:did_drchip_netrwlist_syntax")
6356 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6357 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358 else
6359" call Decho("2match none")
6360 2match none
6361 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006362 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02006363" 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 +00006364endfun
6365
6366" ---------------------------------------------------------------------
6367" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6368" compress/decompress files using the programs
6369" in g:netrw_compress and g:netrw_uncompress,
6370" using g:netrw_compress_suffix to know which to
6371" do. By default:
6372" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006373" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374fun! s:NetrwMarkFileCompress(islocal)
6375" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006376 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377 let curdir = b:netrw_curdir
6378 let curbufnr = bufnr("%")
6379
Bram Moolenaarff034192013-04-24 18:51:19 +02006380 " sanity check
6381 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006382 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006383" call Dret("s:NetrwMarkFileCompress")
6384 return
6385 endif
6386" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6387
Bram Moolenaar446cb832008-06-24 21:56:24 +00006388 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006389
6390 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006392 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
6393" call Decho("extracted sfx<".sfx.">")
6394 if exists("g:netrw_decompress['".sfx."']")
6395 " fname has a suffix indicating that its compressed; apply associated decompression routine
6396 let exe= g:netrw_decompress[sfx]
6397" call Decho("fname<".fname."> is compressed so decompress with <".exe.">")
6398 let exe= netrw#WinPath(exe)
6399 if a:islocal
6400 if g:netrw_keepdir
6401 let fname= shellescape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006402 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006403 else
6404 let fname= shellescape(b:netrw_curdir.fname,1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006406 if executable(exe)
6407 if a:islocal
6408 call system(exe." ".fname)
6409 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006410 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaarff034192013-04-24 18:51:19 +02006411 endif
6412 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006413 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaarff034192013-04-24 18:51:19 +02006414 endif
6415 endif
6416 unlet sfx
6417
Bram Moolenaar446cb832008-06-24 21:56:24 +00006418 if exists("exe")
6419 unlet exe
6420 elseif a:islocal
6421 " fname not a compressed file, so compress it
Bram Moolenaar5c736222010-01-06 20:54:52 +01006422 call system(netrw#WinPath(g:netrw_compress)." ".shellescape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006423 else
6424 " fname not a compressed file, so compress it
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006425 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".shellescape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006427 endfor " for every file in the marked list
6428
Bram Moolenaar446cb832008-06-24 21:56:24 +00006429 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006430 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6431 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 endif
6433" call Dret("s:NetrwMarkFileCompress")
6434endfun
6435
6436" ---------------------------------------------------------------------
6437" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6438" If no marked files, then set up directory as the
6439" target. Currently does not support copying entire
6440" directories. Uses the local-buffer marked file list.
6441" Returns 1=success (used by NetrwMarkFileMove())
6442" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006443fun! s:NetrwMarkFileCopy(islocal,...)
6444" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6445
6446 if !exists("b:netrw_curdir")
6447 let b:netrw_curdir= getcwd()
6448" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)")
6449 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006450 let curdir = b:netrw_curdir
6451 let curbufnr = bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452
Bram Moolenaarff034192013-04-24 18:51:19 +02006453 " sanity check
6454 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006455 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006456" call Dret("s:NetrwMarkFileCopy")
6457 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006458 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006459" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6460
Bram Moolenaar446cb832008-06-24 21:56:24 +00006461 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006462 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006463" call Dret("s:NetrwMarkFileCopy 0")
6464 return 0
6465 endif
6466" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006467
6468 if a:islocal && s:netrwmftgt_islocal
6469 " Copy marked files, local directory to local directory
6470" call Decho("copy from local to local")
Bram Moolenaar13600302014-05-22 18:26:40 +02006471 if !executable(g:netrw_localcopycmd) && g:netrw_localcopycmd !~ '^'.expand("$COMSPEC").'\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01006472 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6473" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6474 return
6475 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006476
6477 " copy marked files while within the same directory (ie. allow renaming)
6478 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
6479 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6480 " only one marked file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006481" call Decho("case: only one marked file")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006482 let args = shellescape(b:netrw_curdir."/".s:netrwmarkfilelist_{bufnr('%')}[0])
6483 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6484 elseif a:0 == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006485" call Decho("case: handling one input argument")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006486 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
6487 let args = shellescape(b:netrw_curdir."/".a:1)
6488 let oldname = a:1
6489 else
6490 " copy multiple marked files inside the same directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006491" call Decho("case: handling a multiple marked files")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006492 let s:recursive= 1
6493 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6494 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6495 if ret == 0
6496 break
6497 endif
6498 endfor
6499 unlet s:recursive
6500 call s:NetrwUnmarkList(curbufnr,curdir)
6501" call Dret("s:NetrwMarkFileCopy ".ret)
6502 return ret
6503 endif
6504
6505 call inputsave()
6506 let newname= input("Copy ".oldname." to : ",oldname,"file")
6507 call inputrestore()
6508 if newname == ""
6509" call Dret("s:NetrwMarkFileCopy 0")
6510 return 0
6511 endif
6512 let args= shellescape(oldname)
6513 let tgt = shellescape(s:netrwmftgt.'/'.newname)
6514 else
6515 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"shellescape(b:netrw_curdir.\"/\".v:val)"))
6516 let tgt = shellescape(s:netrwmftgt)
6517 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006518 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6519 let args= substitute(args,'/','\\','g')
6520 let tgt = substitute(tgt, '/','\\','g')
6521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006522 if args =~ "'"|let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6523 if tgt =~ "'"|let tgt = substitute(tgt,"'\\(.*\\)'",'\1','') |endif
6524 if isdirectory(args)
6525" call Decho("args<".args."> is a directory")
6526 let copycmd= g:netrw_localcopydircmd
6527" call Decho("using copydircmd<".copycmd.">")
6528 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6529 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6530 " contents to a target. One must append the source directory name to the target to get xcopy to
6531 " do the right thing.
6532 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
6533" call Decho("modified tgt for xcopy")
6534 endif
6535 else
6536 let copycmd= g:netrw_localcopycmd
6537 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006538 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006539 let copycmd = substitute(copycmd,'\s.*$','','')
6540 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006541 let copycmd = netrw#WinPath(copycmd).copycmdargs
6542 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006543 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006544 endif
6545" call Decho("args <".args.">")
6546" call Decho("tgt <".tgt.">")
6547" call Decho("copycmd<".copycmd.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006548" call Decho("system(".copycmd." '".args."' '".tgt."')")
6549 call system(copycmd." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006550 if v:shell_error != 0
Bram Moolenaarff034192013-04-24 18:51:19 +02006551 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 +01006552" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".shellescape(s:netrwmftgt))
6553 return 0
6554 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006555
6556 elseif a:islocal && !s:netrwmftgt_islocal
6557 " Copy marked files, local directory to remote directory
6558" call Decho("copy from local to remote")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006559 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006560
6561 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006562 " Copy marked files, remote directory to local directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006563" call Decho("copy from remote to local")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006564 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006565
6566 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006567 " Copy marked files, remote directory to remote directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00006568" call Decho("copy from remote to remote")
6569 let curdir = getcwd()
6570 let tmpdir = s:GetTempfile("")
6571 if tmpdir !~ '/'
6572 let tmpdir= curdir."/".tmpdir
6573 endif
6574 if exists("*mkdir")
6575 call mkdir(tmpdir)
6576 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006577 call s:NetrwExe("sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006578 if v:shell_error != 0
6579 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
6580" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.shellescape(tmpdir,1) )
6581 return
6582 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006583 endif
6584 if isdirectory(tmpdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01006585 call s:NetrwLcd(tmpdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006586 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006587 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006588 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006589 if getcwd() == tmpdir
6590 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006591 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006592 endfor
Bram Moolenaara6878372014-03-22 21:02:50 +01006593 call s:NetrwLcd(curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006594 call s:NetrwExe("sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006595 if v:shell_error != 0
6596 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
6597" call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".shellescape(tmpdir,1) )
6598 return
6599 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006600 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006601 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006602 endif
6603 endif
6604 endif
6605
6606 " -------
6607 " cleanup
6608 " -------
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006609" call Decho("cleanup")
6610 if !exists("s:recursive")
6611 " remove markings from local buffer
6612 call s:NetrwUnmarkList(curbufnr,curdir)
6613 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006614
6615 " refresh buffers
6616 if !s:netrwmftgt_islocal
6617 call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6618 endif
6619 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006620 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006621 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006622 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006623 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01006624 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006625
6626" call Dret("s:NetrwMarkFileCopy 1")
6627 return 1
6628endfun
6629
6630" ---------------------------------------------------------------------
6631" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6632" invoke vim's diff mode on the marked files.
6633" Either two or three files can be so handled.
6634" Uses the global marked file list.
6635fun! s:NetrwMarkFileDiff(islocal)
6636" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6637 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006638
Bram Moolenaarff034192013-04-24 18:51:19 +02006639 " sanity check
6640 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006641 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006642" call Dret("s:NetrwMarkFileDiff")
6643 return
6644 endif
6645" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6646
Bram Moolenaara6878372014-03-22 21:02:50 +01006647 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006648 let cnt = 0
6649 let curdir = b:netrw_curdir
6650 for fname in s:netrwmarkfilelist
6651 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006652 if cnt == 1
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006653" call Decho("diffthis: fname<".fname.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006654 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006655 diffthis
6656 elseif cnt == 2 || cnt == 3
6657 vsplit
6658 wincmd l
6659" call Decho("diffthis: ".fname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006660 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006661 diffthis
6662 else
6663 break
6664 endif
6665 endfor
6666 call s:NetrwUnmarkList(curbufnr,curdir)
6667 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006668
Bram Moolenaar446cb832008-06-24 21:56:24 +00006669" call Dret("s:NetrwMarkFileDiff")
6670endfun
6671
6672" ---------------------------------------------------------------------
6673" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6674" Uses global markfilelist
6675fun! s:NetrwMarkFileEdit(islocal)
6676" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6677
6678 let curdir = b:netrw_curdir
6679 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006680
6681 " sanity check
6682 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006683 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006684" call Dret("s:NetrwMarkFileEdit")
6685 return
6686 endif
6687" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6688
Bram Moolenaar446cb832008-06-24 21:56:24 +00006689 if exists("s:netrwmarkfilelist_{curbufnr}")
6690 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006691 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006692 " unmark markedfile list
6693" call s:NetrwUnmarkList(curbufnr,curdir)
6694 call s:NetrwUnmarkAll()
Bram Moolenaaradc21822011-04-01 18:03:16 +02006695" call Decho("exe sil args ".flist)
6696 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006697 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006698 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00006699
6700" call Dret("s:NetrwMarkFileEdit")
6701endfun
6702
6703" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02006704" s:NetrwMarkFileQFEL: convert a quickfix-error list into a marked file list {{{2
6705fun! s:NetrwMarkFileQFEL(islocal,qfel)
6706" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6707 call s:NetrwUnmarkAll()
6708 let curbufnr= bufnr("%")
6709
6710 if !empty(a:qfel)
6711 for entry in a:qfel
6712 let bufnmbr= entry["bufnr"]
6713" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"])
6714 if !exists("s:netrwmarkfilelist_{curbufnr}")
6715" call Decho("case: no marked file list")
6716 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6717 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6718 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6719 " So, this test lets two or more hits on the same pattern to be ignored.
6720" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list")
6721 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6722 else
6723" call Decho("case: ".bufname(bufnmbr)." already in marked file list")
6724 endif
6725 endfor
6726 echo "(use me to edit marked files)"
6727 else
6728 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6729 endif
6730
6731" call Dret("s:NetrwMarkFileQFEL")
6732endfun
6733
6734" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006735" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6736" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6737" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6738fun! s:NetrwMarkFileExe(islocal,enbloc)
6739" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006741 let curdir = b:netrw_curdir
6742 let curbufnr = bufnr("%")
6743
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006744 if a:enbloc == 0
6745 " individually apply command to files, one at a time
6746 " sanity check
6747 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6748 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
6749" call Dret("s:NetrwMarkFileExe")
6750 return
6751 endif
6752" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaarff034192013-04-24 18:51:19 +02006753
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006754 if exists("s:netrwmarkfilelist_{curbufnr}")
6755 " get the command
6756 call inputsave()
6757 let cmd= input("Enter command: ","","file")
6758 call inputrestore()
6759" call Decho("cmd<".cmd.">")
6760 if cmd == ""
6761" call Dret("s:NetrwMarkFileExe : early exit, empty command")
6762 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006763 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006764
6765 " apply command to marked files, individually. Substitute: filename -> %
6766 " If no %, then append a space and the filename to the command
6767 for fname in s:netrwmarkfilelist_{curbufnr}
6768 if a:islocal
6769 if g:netrw_keepdir
6770 let fname= shellescape(netrw#WinPath(s:ComposePath(curdir,fname)))
6771 endif
6772 else
6773 let fname= shellescape(netrw#WinPath(b:netrw_curdir.fname))
6774 endif
6775 if cmd =~ '%'
6776 let xcmd= substitute(cmd,'%',fname,'g')
6777 else
6778 let xcmd= cmd.' '.fname
6779 endif
6780 if a:islocal
6781" call Decho("local: xcmd<".xcmd.">")
6782 let ret= system(xcmd)
6783 else
6784" call Decho("remote: xcmd<".xcmd.">")
6785 let ret= s:RemoteSystem(xcmd)
6786 endif
6787 if v:shell_error < 0
6788 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6789 break
6790 else
6791 echo ret
6792 endif
6793 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006794
6795 " unmark marked file list
6796 call s:NetrwUnmarkList(curbufnr,curdir)
6797
6798 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006799 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6800 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006801 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006803 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006804
6805 else " apply command to global list of files, en bloc
6806
6807 call inputsave()
6808 let cmd= input("Enter command: ","","file")
6809 call inputrestore()
6810" call Decho("cmd<".cmd.">")
6811 if cmd == ""
6812" call Dret("s:NetrwMarkFileExe : early exit, empty command")
6813 return
6814 endif
6815 if cmd =~ '%'
6816 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'shellescape(v:val)'),' '),'g')
6817 else
6818 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'shellescape(v:val)'),' ')
6819 endif
6820 if a:islocal
6821 call system(cmd)
6822 if v:shell_error < 0
6823 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6824 endif
6825 else
6826 let ret= s:RemoteSystem(cmd)
6827 endif
6828 call s:NetrwUnmarkAll()
6829
6830 " refresh the listing
6831 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6832 NetrwKeepj call netrw#RestorePosn(svpos)
6833
6834 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006835
6836" call Dret("s:NetrwMarkFileExe")
6837endfun
6838
6839" ---------------------------------------------------------------------
6840" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6841" as the marked file(s) (toggles suffix presence)
6842" Uses the local marked file list.
6843fun! s:NetrwMarkHideSfx(islocal)
6844" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006845 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00006846 let curbufnr = bufnr("%")
6847
6848 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6849 if exists("s:netrwmarkfilelist_{curbufnr}")
6850
6851 for fname in s:netrwmarkfilelist_{curbufnr}
6852" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6853 " construct suffix pattern
6854 if fname =~ '\.'
6855 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6856 else
6857 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6858 endif
6859 " determine if its in the hiding list or not
6860 let inhidelist= 0
6861 if g:netrw_list_hide != ""
6862 let itemnum = 0
6863 let hidelist= split(g:netrw_list_hide,',')
6864 for hidepat in hidelist
6865 if sfxpat == hidepat
6866 let inhidelist= 1
6867 break
6868 endif
6869 let itemnum= itemnum + 1
6870 endfor
6871 endif
6872" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6873 if inhidelist
6874 " remove sfxpat from list
6875 call remove(hidelist,itemnum)
6876 let g:netrw_list_hide= join(hidelist,",")
6877 elseif g:netrw_list_hide != ""
6878 " append sfxpat to non-empty list
6879 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6880 else
6881 " set hiding list to sfxpat
6882 let g:netrw_list_hide= sfxpat
6883 endif
6884 endfor
6885
6886 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006887 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6888 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006890 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891 endif
6892
6893" call Dret("s:NetrwMarkHideSfx")
6894endfun
6895
6896" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006897" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02006898" Uses the local marked-file list.
6899fun! s:NetrwMarkFileVimCmd(islocal)
6900" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006901 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006902 let curdir = b:netrw_curdir
6903 let curbufnr = bufnr("%")
6904
Bram Moolenaarff034192013-04-24 18:51:19 +02006905 " sanity check
6906 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006907 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006908" call Dret("s:NetrwMarkFileVimCmd")
6909 return
6910 endif
6911" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
6912
Bram Moolenaar15146672011-10-20 22:22:38 +02006913 if exists("s:netrwmarkfilelist_{curbufnr}")
6914 " get the command
6915 call inputsave()
6916 let cmd= input("Enter vim command: ","","file")
6917 call inputrestore()
6918" call Decho("cmd<".cmd.">")
6919 if cmd == ""
6920" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
6921 return
6922 endif
6923
6924 " apply command to marked files. Substitute: filename -> %
6925 " If no %, then append a space and the filename to the command
6926 for fname in s:netrwmarkfilelist_{curbufnr}
6927" call Decho("fname<".fname.">")
6928 if a:islocal
6929 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006930 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02006931" call Decho("local<".fname.">: exe ".cmd)
6932 exe cmd
6933 exe "sil! keepalt wq!"
6934 else
Bram Moolenaar15146672011-10-20 22:22:38 +02006935" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006936 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02006937 endif
6938 endfor
6939
6940 " unmark marked file list
6941 call s:NetrwUnmarkList(curbufnr,curdir)
6942
6943 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006944 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6945 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02006946 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006947 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02006948 endif
6949
6950" call Dret("s:NetrwMarkFileVimCmd")
6951endfun
6952
6953" ---------------------------------------------------------------------
6954" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
6955" as the marked file(s) (toggles suffix presence)
6956" Uses the local marked file list.
6957fun! s:NetrwMarkHideSfx(islocal)
6958" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01006959 let svpos = netrw#SavePosn()
Bram Moolenaar15146672011-10-20 22:22:38 +02006960 let curbufnr = bufnr("%")
6961
6962 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
6963 if exists("s:netrwmarkfilelist_{curbufnr}")
6964
6965 for fname in s:netrwmarkfilelist_{curbufnr}
6966" call Decho("s:NetrwMarkFileCopy: fname<".fname.">")
6967 " construct suffix pattern
6968 if fname =~ '\.'
6969 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
6970 else
6971 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
6972 endif
6973 " determine if its in the hiding list or not
6974 let inhidelist= 0
6975 if g:netrw_list_hide != ""
6976 let itemnum = 0
6977 let hidelist= split(g:netrw_list_hide,',')
6978 for hidepat in hidelist
6979 if sfxpat == hidepat
6980 let inhidelist= 1
6981 break
6982 endif
6983 let itemnum= itemnum + 1
6984 endfor
6985 endif
6986" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">")
6987 if inhidelist
6988 " remove sfxpat from list
6989 call remove(hidelist,itemnum)
6990 let g:netrw_list_hide= join(hidelist,",")
6991 elseif g:netrw_list_hide != ""
6992 " append sfxpat to non-empty list
6993 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
6994 else
6995 " set hiding list to sfxpat
6996 let g:netrw_list_hide= sfxpat
6997 endif
6998 endfor
6999
7000 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007001 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7002 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007003 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007004 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007005 endif
7006
7007" call Dret("s:NetrwMarkHideSfx")
7008endfun
7009
7010" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007011" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7012" Uses the global markfilelist
7013fun! s:NetrwMarkFileGrep(islocal)
7014" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007015 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007016 let curbufnr = bufnr("%")
7017
7018 if exists("s:netrwmarkfilelist")
7019" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007020 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007021 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007022 else
7023" call Decho('no marked files, using "*"')
7024 let netrwmarkfilelist= "*"
7025 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007026
Bram Moolenaarff034192013-04-24 18:51:19 +02007027 " ask user for pattern
7028 call inputsave()
7029 let pat= input("Enter pattern: ","")
7030 call inputrestore()
7031 let patbang = ""
7032 if pat =~ '^!'
7033 let patbang = "!"
7034 let pat= strpart(pat,2)
7035 endif
7036 if pat =~ '^\i'
7037 let pat = escape(pat,'/')
7038 let pat = '/'.pat.'/'
7039 else
7040 let nonisi = pat[0]
7041 endif
7042
7043 " use vimgrep for both local and remote
7044" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist)
7045 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007046 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007047 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007048 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007049" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7050 return
7051 endtry
7052 echo "(use :cn, :cp to navigate, :Rex to return)"
7053
7054 2match none
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007055 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007056
7057 if exists("nonisi")
7058 " original, user-supplied pattern did not begin with a character from isident
7059" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg")
7060 if pat =~ nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
7061 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007063 endif
7064
7065" call Dret("s:NetrwMarkFileGrep")
7066endfun
7067
7068" ---------------------------------------------------------------------
7069" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7070" uses the global marked file list
7071" s:netrwmfloc= 0: target directory is remote
7072" = 1: target directory is local
7073fun! s:NetrwMarkFileMove(islocal)
7074" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
7075 let curdir = b:netrw_curdir
7076 let curbufnr = bufnr("%")
7077
7078 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007079 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007080 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007081" call Dret("s:NetrwMarkFileMove")
7082 return
7083 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007084" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
7085
Bram Moolenaar446cb832008-06-24 21:56:24 +00007086 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007087 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088" call Dret("s:NetrwMarkFileCopy 0")
7089 return 0
7090 endif
7091" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">")
7092
7093 if a:islocal && s:netrwmftgt_islocal
7094 " move: local -> local
7095" call Decho("move from local to local")
Bram Moolenaara6878372014-03-22 21:02:50 +01007096" call Decho("local to local move")
Bram Moolenaar13600302014-05-22 18:26:40 +02007097 if !executable(g:netrw_localmovecmd) && g:netrw_localmovecmd !~ '^'.expand("$COMSPEC").'\s'
Bram Moolenaar97d62492012-11-15 21:28:22 +01007098 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7099" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7100 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007101 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007102 let tgt = shellescape(s:netrwmftgt)
7103" call Decho("tgt<".tgt.">")
7104 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7105 let tgt = substitute(tgt, '/','\\','g')
7106" call Decho("windows exception: tgt<".tgt.">")
7107 if g:netrw_localmovecmd =~ '\s'
7108 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7109 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7110 let movecmd = netrw#WinPath(movecmd).movecmdargs
7111" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)")
7112 else
7113 let movecmd = netrw#WinPath(movecmd)
7114" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)")
7115 endif
7116 else
7117 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
7118" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)")
7119 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007120 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007121" call Decho("system(".movecmd." ".shellescape(fname)." ".tgt.")")
7122 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7123 let fname= substitute(fname,'/','\\','g')
7124 endif
7125 let ret= system(g:netrw_localmovecmd." ".shellescape(fname)." ".tgt)
7126 if v:shell_error != 0
7127 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 +01007128 break
7129 endif
7130 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131
7132 elseif a:islocal && !s:netrwmftgt_islocal
7133 " move: local -> remote
7134" call Decho("move from local to remote")
7135" call Decho("copy")
7136 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007137 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007138" call Decho("remove")
7139 for fname in mflist
7140 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7141 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7142 endfor
7143 unlet mflist
7144
7145 elseif !a:islocal && s:netrwmftgt_islocal
7146 " move: remote -> local
7147" call Decho("move from remote to local")
7148" call Decho("copy")
7149 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007150 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007151" call Decho("remove")
7152 for fname in mflist
7153 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7154 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7155 endfor
7156 unlet mflist
7157
7158 elseif !a:islocal && !s:netrwmftgt_islocal
7159 " move: remote -> remote
7160" call Decho("move from remote to remote")
7161" call Decho("copy")
7162 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007163 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007164" call Decho("remove")
7165 for fname in mflist
7166 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7167 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7168 endfor
7169 unlet mflist
7170 endif
7171
7172 " -------
7173 " cleanup
7174 " -------
7175" call Decho("cleanup")
7176
7177 " remove markings from local buffer
7178 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7179
7180 " refresh buffers
7181 if !s:netrwmftgt_islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02007182" call Decho("refresh netrwmftgt<".s:netrwmftgt.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007183 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007184 endif
7185 if a:islocal
Bram Moolenaaradc21822011-04-01 18:03:16 +02007186" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007187 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007188 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007189 if g:netrw_fastbrowse <= 1
Bram Moolenaaradc21822011-04-01 18:03:16 +02007190" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007191 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007192 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007193
7194" call Dret("s:NetrwMarkFileMove")
7195endfun
7196
7197" ---------------------------------------------------------------------
7198" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7199" using the hardcopy command. Local marked-file list only.
7200fun! s:NetrwMarkFilePrint(islocal)
7201" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7202 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007203
7204 " sanity check
7205 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007207" call Dret("s:NetrwMarkFilePrint")
7208 return
7209 endif
7210" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007211 if exists("s:netrwmarkfilelist_{curbufnr}")
7212 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
7213 let curdir = b:netrw_curdir
7214 call s:NetrwUnmarkList(curbufnr,curdir)
7215 for fname in netrwmarkfilelist
7216 if a:islocal
7217 if g:netrw_keepdir
7218 let fname= s:ComposePath(curdir,fname)
7219 endif
7220 else
7221 let fname= curdir.fname
7222 endif
7223 1split
7224 " the autocmds will handle both local and remote files
Bram Moolenaaradc21822011-04-01 18:03:16 +02007225" call Decho("exe sil e ".escape(fname,' '))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007227" call Decho("hardcopy")
7228 hardcopy
7229 q
7230 endfor
7231 2match none
7232 endif
7233" call Dret("s:NetrwMarkFilePrint")
7234endfun
7235
7236" ---------------------------------------------------------------------
7237" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7238" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007239" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007240fun! s:NetrwMarkFileRegexp(islocal)
7241" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7242
7243 " get the regular expression
7244 call inputsave()
7245 let regexp= input("Enter regexp: ","","file")
7246 call inputrestore()
7247
7248 if a:islocal
7249 " get the matching list of files using local glob()
7250" call Decho("handle local regexp")
Bram Moolenaarff034192013-04-24 18:51:19 +02007251 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
7252 let files = glob(s:ComposePath(dirname,regexp))
Bram Moolenaar5c736222010-01-06 20:54:52 +01007253" call Decho("files<".files.">")
7254 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255
7256 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007257 for fname in filelist
7258" call Decho("fname<".fname.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007259 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
Bram Moolenaar5c736222010-01-06 20:54:52 +01007260 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261
7262 else
7263" call Decho("handle remote regexp")
7264
7265 " convert displayed listing into a filelist
7266 let eikeep = &ei
7267 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007268 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007269 setl ei=all ma
7270" call Decho("setl ei=all ma")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007272 NetrwKeepj call s:NetrwEnew()
7273 NetrwKeepj call s:NetrwSafeOptions()
7274 sil NetrwKeepj norm! "ap
7275 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007277 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007278 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007280 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007281 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007283 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007284 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007285 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007286 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7287 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007288 call histdel("/",-1)
7289 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 endif
7291 " convert regexp into the more usual glob-style format
7292 let regexp= substitute(regexp,'\*','.*','g')
7293" call Decho("regexp<".regexp.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007294 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007295 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007296 let filelist= getline(1,line("$"))
7297 q!
7298 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007299 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 endfor
7301 unlet filelist
7302 let @a = areg
7303 let &ei = eikeep
7304 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007305 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007306
7307" call Dret("s:NetrwMarkFileRegexp")
7308endfun
7309
7310" ---------------------------------------------------------------------
7311" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7312" Uses the local marked file list.
7313fun! s:NetrwMarkFileSource(islocal)
7314" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7315 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007316
7317 " sanity check
7318 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007319 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007320" call Dret("s:NetrwMarkFileSource")
7321 return
7322 endif
7323" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007324 if exists("s:netrwmarkfilelist_{curbufnr}")
7325 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
7326 let curdir = b:netrw_curdir
7327 call s:NetrwUnmarkList(curbufnr,curdir)
7328 for fname in netrwmarkfilelist
7329 if a:islocal
7330 if g:netrw_keepdir
7331 let fname= s:ComposePath(curdir,fname)
7332 endif
7333 else
7334 let fname= curdir.fname
7335 endif
7336 " the autocmds will handle sourcing both local and remote files
Bram Moolenaarc236c162008-07-13 17:41:49 +00007337" call Decho("exe so ".fnameescape(fname))
7338 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339 endfor
7340 2match none
7341 endif
7342" call Dret("s:NetrwMarkFileSource")
7343endfun
7344
7345" ---------------------------------------------------------------------
7346" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7347" Uses the global markfilelist
7348fun! s:NetrwMarkFileTag(islocal)
7349" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007350 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351 let curdir = b:netrw_curdir
7352 let curbufnr = bufnr("%")
7353
Bram Moolenaarff034192013-04-24 18:51:19 +02007354 " sanity check
7355 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007356 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007357" call Dret("s:NetrwMarkFileTag")
7358 return
7359 endif
7360" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}))
7361
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 if exists("s:netrwmarkfilelist")
7363" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">")
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007364 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "shellescape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365 call s:NetrwUnmarkAll()
7366
7367 if a:islocal
7368 if executable(g:netrw_ctags)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")")
7370 call system(g:netrw_ctags." ".netrwmarkfilelist)
7371 else
7372 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7373 endif
7374 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007375 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007376 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377 let curdir= b:netrw_curdir
7378 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007379 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
7381" call Decho("curdir<".curdir."> path<".path.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007383 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 wq!
7385 endif
7386 2match none
7387 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007388 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 endif
7390
7391" call Dret("s:NetrwMarkFileTag")
7392endfun
7393
7394" ---------------------------------------------------------------------
7395" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
7396" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007397" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007399" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400fun! s:NetrwMarkFileTgt(islocal)
7401" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007402 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 let curdir = b:netrw_curdir
7404 let hadtgt = exists("s:netrwmftgt")
7405 if !exists("w:netrw_bannercnt")
7406 let w:netrw_bannercnt= b:netrw_bannercnt
7407 endif
7408
7409 " set up target
7410 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007411 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7412 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
7413" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target")
7414 unlet s:netrwmftgt s:netrwmftgt_islocal
7415 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007416 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007417 endif
7418 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007419 call netrw#RestorePosn(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007420" call Dret("s:NetrwMarkFileTgt : removed target")
7421 return
7422 else
7423 let s:netrwmftgt= b:netrw_curdir
7424" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">")
7425 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007426
7427 else
7428 " get word under cursor.
7429 " * If directory, use it for the target.
7430 " * If file, use b:netrw_curdir for the target
7431 let curword= s:NetrwGetWord()
7432 let tgtdir = s:ComposePath(curdir,curword)
7433 if a:islocal && isdirectory(tgtdir)
7434 let s:netrwmftgt = tgtdir
7435" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">")
7436 elseif !a:islocal && tgtdir =~ '/$'
7437 let s:netrwmftgt = tgtdir
7438" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">")
7439 else
7440 let s:netrwmftgt = curdir
7441" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">")
7442 endif
7443 endif
7444 if a:islocal
7445 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7446 let s:netrwmftgt= simplify(s:netrwmftgt)
7447" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">")
7448 endif
7449 if g:netrw_cygwin
7450 let s:netrwmftgt= substitute(system("cygpath ".shellescape(s:netrwmftgt)),'\n$','','')
7451 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7452 endif
7453 let s:netrwmftgt_islocal= a:islocal
7454
Bram Moolenaar5c736222010-01-06 20:54:52 +01007455 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007456 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007457 endif
7458 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007459 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007460 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007461 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007462 endif
7463
7464" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
7465endfun
7466
7467" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007468" s:NetrwOpenFile: query user for a filename and open it {{{2
7469fun! s:NetrwOpenFile(islocal)
7470" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007471 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007472 call inputsave()
7473 let fname= input("Enter filename: ")
7474 call inputrestore()
7475 if fname !~ '[/\\]'
7476 if exists("b:netrw_curdir")
7477 if exists("g:netrw_quiet")
7478 let netrw_quiet_keep = g:netrw_quiet
7479 endif
7480 let g:netrw_quiet = 1
7481 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007483 else
7484 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7485 endif
7486 if exists("netrw_quiet_keep")
7487 let g:netrw_quiet= netrw_quiet_keep
7488 else
7489 unlet g:netrw_quiet
7490 endif
7491 endif
7492 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007494 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007495 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007496" call Dret("s:NetrwOpenFile")
7497endfun
7498
7499" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007500" 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 +02007501" User access provided by the <mu> mapping. (see :help netrw-mu)
7502" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503fun! s:NetrwUnmarkList(curbufnr,curdir)
7504" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7505
7506 " remove all files in local marked-file list from global list
7507 if exists("s:netrwmarkfilelist_{a:curbufnr}")
7508 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7509 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7510 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7511 call remove(s:netrwmarkfilelist,idx) " remove from global list
7512 endfor
7513 if s:netrwmarkfilelist == []
7514 unlet s:netrwmarkfilelist
7515 endif
7516
7517 " getting rid of the local marked-file lists is easy
7518 unlet s:netrwmarkfilelist_{a:curbufnr}
7519 endif
7520 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7521 unlet s:netrwmarkfilemtch_{a:curbufnr}
7522 endif
7523 2match none
7524" call Dret("s:NetrwUnmarkList")
7525endfun
7526
7527" ---------------------------------------------------------------------
7528" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7529fun! s:NetrwUnmarkAll()
7530" call Dfunc("s:NetrwUnmarkAll()")
7531 if exists("s:netrwmarkfilelist")
7532 unlet s:netrwmarkfilelist
7533 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007534 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007535 2match none
7536" call Dret("s:NetrwUnmarkAll")
7537endfun
7538
7539" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007540" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541fun! s:NetrwUnmarkAll2()
7542" call Dfunc("s:NetrwUnmarkAll2()")
7543 redir => netrwmarkfilelist_let
7544 let
7545 redir END
7546 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
7547 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
7548 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7549 for flist in netrwmarkfilelist_list
7550 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7551 unlet s:netrwmarkfilelist_{curbufnr}
7552 unlet s:netrwmarkfilemtch_{curbufnr}
7553 endfor
7554" call Dret("s:NetrwUnmarkAll2")
7555endfun
7556
7557" ---------------------------------------------------------------------
7558" s:NetrwUnMarkFile: {{{2
7559fun! s:NetrwUnMarkFile(islocal)
7560" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaara6878372014-03-22 21:02:50 +01007561 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007562 let curbufnr = bufnr("%")
7563
7564 " unmark marked file list (although I expect s:NetrwUpload()
7565 " to do it, I'm just making sure)
7566 if exists("s:netrwmarkfilelist_{bufnr('%')}")
7567" call Decho("unlet'ing: s:netrwmarkfile[list|mtch]_".bufnr("%"))
7568 unlet s:netrwmarkfilelist
7569 unlet s:netrwmarkfilelist_{curbufnr}
7570 unlet s:netrwmarkfilemtch_{curbufnr}
7571 2match none
7572 endif
7573
7574" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaara6878372014-03-22 21:02:50 +01007575 call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007576" call Dret("s:NetrwUnMarkFile")
7577endfun
7578
7579" ---------------------------------------------------------------------
7580" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7581fun! s:NetrwMenu(domenu)
7582
7583 if !exists("g:NetrwMenuPriority")
7584 let g:NetrwMenuPriority= 80
7585 endif
7586
Bram Moolenaaradc21822011-04-01 18:03:16 +02007587 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7589
7590 if !exists("s:netrw_menu_enabled") && a:domenu
7591" call Decho("initialize menu")
7592 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007593 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7594 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7595 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7596 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7597 if g:netrw_dirhistmax > 0
7598 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7599 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7600 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7601 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7602 else
7603 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7604 endif
7605 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7606 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7607 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7608 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7609 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7610 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7611 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7612 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7613 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7614 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7615 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7616 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7617 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7618 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7619 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007620 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02007621 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7622 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7623 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7624 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7625 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7626 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7627 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7628 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7629 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7630 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7631 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7632 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7633 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7634 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7635 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7636 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7637 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7638 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7639 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7640 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7641 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7642 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7643 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7644 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7645 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7646 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7647 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7648 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7649 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7650 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>'
7651 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>'
7652 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>'
7653 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7654 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>'
7655 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>'
7656 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>'
7657 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7658 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007659 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007660 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7661 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007662
7663 elseif !a:domenu
7664 let s:netrwcnt = 0
7665 let curwin = winnr()
7666 windo if getline(2) =~ "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
7667 exe curwin."wincmd w"
7668
7669 if s:netrwcnt <= 1
7670" call Decho("clear menus")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007671 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaaradc21822011-04-01 18:03:16 +02007672" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007673 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674 endif
7675 endif
7676" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007677 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007678 endif
7679
7680endfun
7681
7682" ---------------------------------------------------------------------
7683" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7684" Used by the O maps (as <SID>NetrwObtain())
7685fun! s:NetrwObtain(islocal)
7686" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7687
Bram Moolenaar97d62492012-11-15 21:28:22 +01007688 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007689 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar5c736222010-01-06 20:54:52 +01007690 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\+://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007691 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007692 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7693 else
Bram Moolenaara6878372014-03-22 21:02:50 +01007694 call netrw#Obtain(a:islocal,expand("<cWORD>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007695 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007696 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007697
7698" call Dret("NetrwObtain")
7699endfun
7700
7701" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007702" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7703" If there's only one window, then the window will first be split.
7704" Returns:
7705" choice = 0 : didn't have to choose
7706" choice = 1 : saved modified file in window first
7707" choice = 2 : didn't save modified file, opened window
7708" choice = 3 : cancel open
7709fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007710" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007711
Bram Moolenaar97d62492012-11-15 21:28:22 +01007712 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007713 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01007714 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007715
7716 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01007717 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007718 let lastwinnr = winnr("$")
7719 let curword = s:NetrwGetWord()
7720 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007721 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01007722 let curdir = s:treedir
7723" call Decho("winnr($)#".lastwinnr." curword<".curword.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007724
Bram Moolenaar8d043172014-01-23 14:24:41 +01007725 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007726 if lastwinnr == 1
7727 " if only one window, open a new one first
Bram Moolenaara6878372014-03-22 21:02:50 +01007728" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007729 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007730 " vertically split preview window
Bram Moolenaar15146672011-10-20 22:22:38 +02007731 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007732" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007733 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007735 " horizontally split preview window
Bram Moolenaar15146672011-10-20 22:22:38 +02007736 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara6878372014-03-22 21:02:50 +01007737" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar15146672011-10-20 22:22:38 +02007738 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007740 let didsplit = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007741" call Decho("did split")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007742
7743 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007744 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01007745 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01007746 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00007747 wincmd p
Bram Moolenaara6878372014-03-22 21:02:50 +01007748" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007749
7750 " prevwinnr: the window number of the "prev" window
7751 " prevbufnr: the buffer number of the buffer in the "prev" window
7752 " bnrcnt : the qty of windows open on the "prev" buffer
7753 let prevwinnr = winnr()
7754 let prevbufnr = bufnr("%")
7755 let prevbufname = bufname("%")
7756 let prevmod = &mod
7757 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007758 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01007759" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007760
7761 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762 " and it doesn't appear in any other extant window, then ask the
7763 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01007764 if prevmod
Bram Moolenaara6878372014-03-22 21:02:50 +01007765" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01007766 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01007767" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007768 exe prevwinnr."wincmd w"
7769
7770 if bnrcnt == 1 && &hidden == 0
7771 " only one copy of the modified buffer in a window, and
7772 " hidden not set, so overwriting will lose the modified file. Ask first...
7773 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
7774" call Decho("(NetrwPrevWinOpen) prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr())
7775 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007776
7777 if choice == 1
7778 " Yes -- write file & then browse
7779 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02007780 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00007781 if v:errmsg != ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01007782 call netrw#ErrorMsg(s:ERROR,"unable to write <".prevbufname.">!",30)
7783 exe origwin."wincmd w"
7784 let &ei = eikeep
7785 let @@ = ykeep
7786" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 return choice
7788 endif
7789
7790 elseif choice == 2
7791 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara6878372014-03-22 21:02:50 +01007792" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")")
Bram Moolenaar8d043172014-01-23 14:24:41 +01007793 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007794
7795 else
7796 " Cancel -- don't do this
Bram Moolenaara6878372014-03-22 21:02:50 +01007797" call Decho("cancel, don't browse, switch to win#".origwin)
Bram Moolenaar8d043172014-01-23 14:24:41 +01007798 exe origwin."wincmd w"
7799 let &ei= eikeep
7800 let @@ = ykeep
7801" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007802 return choice
7803 endif
7804 endif
7805 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01007806 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007807 endif
7808
7809 " restore b:netrw_curdir (window split/enew may have lost it)
7810 let b:netrw_curdir= curdir
7811 if a:islocal < 2
7812 if a:islocal
7813 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
7814 else
7815 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
7816 endif
7817 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007818 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01007819" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820 return choice
7821endfun
7822
7823" ---------------------------------------------------------------------
7824" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
7825" Always assumed to be local -> remote
7826" call s:NetrwUpload(filename, target)
7827" call s:NetrwUpload(filename, target, fromdirectory)
7828fun! s:NetrwUpload(fname,tgt,...)
7829" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
7830
7831 if a:tgt =~ '^\a\+://'
7832 let tgtdir= substitute(a:tgt,'^\a\+://[^/]\+/\(.\{-}\)$','\1','')
7833 else
7834 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
7835 endif
7836" call Decho("tgtdir<".tgtdir.">")
7837
7838 if a:0 > 0
7839 let fromdir= a:1
7840 else
7841 let fromdir= getcwd()
7842 endif
7843" call Decho("fromdir<".fromdir.">")
7844
7845 if type(a:fname) == 1
7846 " handle uploading a single file using NetWrite
7847" call Decho("handle uploading a single file via NetWrite")
7848 1split
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007849" call Decho("exe e ".fnameescape(a:fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007850 exe "NetrwKeepj e ".fnameescape(a:fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007851" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines")
7852 if a:tgt =~ '/$'
7853 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaarc236c162008-07-13 17:41:49 +00007854" call Decho("exe w! ".fnameescape(wfname))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007855 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007857" call Decho("writing local->remote: exe w ".fnameescape(a:tgt))
7858 exe "w ".fnameescape(a:tgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859" call Decho("done writing local->remote")
7860 endif
7861 q!
7862
7863 elseif type(a:fname) == 3
7864 " handle uploading a list of files via scp
7865" call Decho("handle uploading a list of files via scp")
7866 let curdir= getcwd()
7867 if a:tgt =~ '^scp:'
Bram Moolenaara6878372014-03-22 21:02:50 +01007868 call s:NetrwLcd(fromdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007869 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
7870 let args = join(map(filelist,"shellescape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007871 if exists("g:netrw_port") && g:netrw_port != ""
7872 let useport= " ".g:netrw_scpport." ".g:netrw_port
7873 else
7874 let useport= ""
7875 endif
7876 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
7877 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007878 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.shellescape(useport,1)." ".args." ".shellescape(machine.":".tgt,1))
Bram Moolenaara6878372014-03-22 21:02:50 +01007879 call s:NetrwLcd(curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880
7881 elseif a:tgt =~ '^ftp:'
7882 call s:NetrwMethod(a:tgt)
7883
7884 if b:netrw_method == 2
7885 " handle uploading a list of files via ftp+.netrc
7886 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 sil NetrwKeepj new
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888" call Decho("filter input window#".winnr())
7889
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007890 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaar446cb832008-06-24 21:56:24 +00007891" call Decho("filter input: ".getline('$'))
7892
7893 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007894 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895" call Decho("filter input: ".getline('$'))
7896 endif
7897
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007898 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007899" call Decho("filter input: ".getline('$'))
7900
Bram Moolenaaradc21822011-04-01 18:03:16 +02007901 if tgtdir == ""
7902 let tgtdir= '/'
7903 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007904 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007905" call Decho("filter input: ".getline('$'))
7906
7907 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007908 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909" call Decho("filter input: ".getline('$'))
7910 endfor
7911
7912 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 call s:NetrwExe(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 +00007914 else
7915" call Decho("filter input window#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 endif
7918 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007919 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007920 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7922 call netrw#ErrorMsg(s:ERROR,getline(1),14)
7923 else
7924 bw!|q
7925 endif
7926
7927 elseif b:netrw_method == 3
7928 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
7929 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007930 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007932 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00007933
7934 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007935 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936" call Decho("filter input: ".getline('$'))
7937 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007938 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar446cb832008-06-24 21:56:24 +00007939" call Decho("filter input: ".getline('$'))
7940 endif
7941
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007942 if exists("g:netrw_uid") && g:netrw_uid != ""
7943 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007944 NetrwKeepj put =g:netrw_uid
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007945" call Decho("filter input: ".getline('$'))
7946 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007947 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007948 endif
7949" call Decho("filter input: ".getline('$'))
7950 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007951 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007952" call Decho("filter input: ".getline('$'))
7953 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954 endif
7955
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007956 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957" call Decho("filter input: ".getline('$'))
7958
7959 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961" call Decho("filter input: ".getline('$'))
7962 endif
7963
7964 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007965 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00007966" call Decho("filter input: ".getline('$'))
7967 endif
7968
7969 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007970 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971" call Decho("filter input: ".getline('$'))
7972 endfor
7973
7974 " perform ftp:
7975 " -i : turns off interactive prompting from ftp
7976 " -n unix : DON'T use <.netrc>, even though it exists
7977 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007978 NetrwKeepj norm! 1Gdd
7979 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007981 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007982 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
7984 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02007985 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986 call netrw#ErrorMsg(s:ERROR,getline(1),15)
7987 let &debug = debugkeep
7988 let mod = 1
7989 else
7990 bw!|q
7991 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007992 elseif !exists("b:netrw_method") || b:netrw_method < 0
7993" call Dfunc("netrw#NetrwUpload : unsupported method")
7994 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 endif
7996 else
7997 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
7998 endif
7999 endif
8000
8001" call Dret("s:NetrwUpload")
8002endfun
8003
8004" ---------------------------------------------------------------------
8005" s:NetrwPreview: {{{2
8006fun! s:NetrwPreview(path) range
8007" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008008 let ykeep= @@
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008009 NetrwKeepj call s:NetrwOptionSave("s:")
8010 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008011 if has("quickfix")
8012 if !isdirectory(a:path)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008013 if g:netrw_preview && !g:netrw_alto
Bram Moolenaar15146672011-10-20 22:22:38 +02008014 let pvhkeep = &pvh
8015 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8016 let &pvh = winwidth(0) - winsz
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008017 endif
8018 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
8019 if exists("pvhkeep")
8020 let &pvh= pvhkeep
8021 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008023 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 endif
8025 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008029 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030" call Dret("NetrwPreview")
8031endfun
8032
8033" ---------------------------------------------------------------------
8034" s:NetrwRefresh: {{{2
8035fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008038 setl ma noro
8039" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040" call Decho("clear buffer<".expand("%")."> with :%d")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008041 let ykeep = @@
Bram Moolenaar13600302014-05-22 18:26:40 +02008042
8043 " save the cursor position before refresh.
Bram Moolenaara6878372014-03-22 21:02:50 +01008044 let screenposn = netrw#SavePosn()
Bram Moolenaar13600302014-05-22 18:26:40 +02008045" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">")
Bram Moolenaarff034192013-04-24 18:51:19 +02008046" call Decho("clearing buffer prior to refresh")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008047 sil! NetrwKeepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008050 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008051 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008053
8054 " restore position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 NetrwKeepj call netrw#RestorePosn(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056
8057 " restore file marks
8058 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8059" call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
8060 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8061 else
8062" call Decho("2match none")
8063 2match none
8064 endif
8065
Bram Moolenaar97d62492012-11-15 21:28:22 +01008066" restore
8067 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008068" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069endfun
8070
8071" ---------------------------------------------------------------------
8072" s:NetrwRefreshDir: refreshes a directory by name {{{2
8073" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008074" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008076" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008077 if g:netrw_fastbrowse == 0
8078 " slowest mode (keep buffers refreshed, local or remote)
8079" call Decho("slowest mode: keep buffers refreshed, local or remote")
8080 let tgtwin= bufwinnr(a:dirname)
8081" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin)
8082
8083 if tgtwin > 0
8084 " tgtwin is being displayed, so refresh it
8085 let curwin= winnr()
8086" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")")
8087 exe tgtwin."wincmd w"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008088 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008089 exe curwin."wincmd w"
8090
8091 elseif bufnr(a:dirname) > 0
8092 let bn= bufnr(a:dirname)
8093" call Decho("bd bufnr(".a:dirname.")=".bn)
Bram Moolenaaradc21822011-04-01 18:03:16 +02008094 exe "sil bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 endif
8096
8097 elseif g:netrw_fastbrowse <= 1
8098" call Decho("medium-speed mode: refresh local buffers only")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008099 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 endif
8101" call Dret("s:NetrwRefreshDir")
8102endfun
8103
8104" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008105" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8106" window number to do its editing in.
8107" Supports [count]C where the count, if present, is used to specify
8108" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008109fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008110" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008111 if a:0 > 0
8112" call Decho("a:1<".a:1.">")
8113 if a:1 == "" " :NetrwC win#
8114 let g:netrw_chgwin= winnr()
8115 else " :NetrwC
8116 let g:netrw_chgwin= a:1
8117 endif
8118 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008119 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008120 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008121 let g:netrw_chgwin= winnr()
8122 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008123" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008124endfun
8125
8126" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8128" What this function does is to compute a priority for the patterns
8129" in the g:netrw_sort_sequence. It applies a substitute to any
8130" "files" that satisfy each pattern, putting the priority / in
8131" front. An "*" pattern handles the default priority.
8132fun! s:NetrwSetSort()
8133" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008134 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 if w:netrw_liststyle == s:LONGLIST
8136 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8137 else
8138 let seqlist = g:netrw_sort_sequence
8139 endif
8140 " sanity check -- insure that * appears somewhere
8141 if seqlist == ""
8142 let seqlist= '*'
8143 elseif seqlist !~ '\*'
8144 let seqlist= seqlist.',*'
8145 endif
8146 let priority = 1
8147 while seqlist != ""
8148 if seqlist =~ ','
8149 let seq = substitute(seqlist,',.*$','','e')
8150 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8151 else
8152 let seq = seqlist
8153 let seqlist = ""
8154 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008156 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008158 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008160 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008161 endif
8162" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">")
8163
8164 " sanity check
8165 if w:netrw_bannercnt > line("$")
8166 " apparently no files were left after a Hiding pattern was used
8167" call Dret("SetSort : no files left after hiding")
8168 return
8169 endif
8170 if seq == '*'
8171 let starpriority= spriority
8172 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008174 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175 " sometimes multiple sorting patterns will match the same file or directory.
8176 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008177 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8178 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008179 endif
8180 let priority = priority + 1
8181 endwhile
8182 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008183 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8184 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185 endif
8186
8187 " Following line associated with priority -- items that satisfy a priority
8188 " pattern get prefixed by ###/ which permits easy sorting by priority.
8189 " Sometimes files can satisfy multiple priority patterns -- only the latest
8190 " priority pattern needs to be retained. So, at this point, these excess
8191 " priority prefixes need to be removed, but not directories that happen to
8192 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008193 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8194 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008195 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008196
8197" call Dret("SetSort")
8198endfun
8199
Bram Moolenaarff034192013-04-24 18:51:19 +02008200" ---------------------------------------------------------------------
8201" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8202" Implements [count]Tb (bookhist<b>)
8203" [count]Th (bookhist<h>)
8204" See :help netrw-qb for how to make the choice.
8205fun! s:NetrwSetTgt(bookhist,choice)
8206" call Dfunc("s:NetrwSetTgt(bookhist<".a:bookhist."> choice#".a:choice.")")
8207
8208 if a:bookhist == 'b'
8209 " supports choosing a bookmark as a target using a qb-generated list
8210 let choice= a:choice - 1
8211 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008212 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008213 else
8214 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8215 endif
8216
8217 elseif a:bookhist == 'h'
8218 " supports choosing a history stack entry as a target using a qb-generated list
8219 let choice= (a:choice % g:netrw_dirhistmax) + 1
8220 if exists("g:netrw_dirhist_".choice)
8221 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008222 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008223 else
8224 echomsg "Sorry, history#".a:choice." not available!"
8225 endif
8226 endif
8227
8228" call Dret("s:NetrwSetTgt")
8229endfun
8230
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231" =====================================================================
8232" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
8233fun! s:NetrwSortStyle(islocal)
8234" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008235 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaara6878372014-03-22 21:02:50 +01008236 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237
8238 let g:netrw_sort_by= (g:netrw_sort_by =~ 'n')? 'time' : (g:netrw_sort_by =~ 't')? 'size' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008239 NetrwKeepj norm! 0
8240 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8241 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008242
8243" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
8244endfun
8245
8246" ---------------------------------------------------------------------
8247" s:NetrwSplit: mode {{{2
8248" =0 : net and o
8249" =1 : net and t
8250" =2 : net and v
8251" =3 : local and o
8252" =4 : local and t
8253" =5 : local and v
8254fun! s:NetrwSplit(mode)
8255" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
8256
Bram Moolenaar97d62492012-11-15 21:28:22 +01008257 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258 call s:SaveWinVars()
8259
8260 if a:mode == 0
8261 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008262 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008263 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02008264" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02008265 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008266 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008267 NetrwKeepj call s:RestoreWinVars()
8268 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008269 unlet s:didsplit
8270
8271 elseif a:mode == 1
8272 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01008273 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008274" call Decho("tabnew")
8275 tabnew
8276 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008277 NetrwKeepj call s:RestoreWinVars()
8278 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008279 unlet s:didsplit
8280
8281 elseif a:mode == 2
8282 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008283 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008284 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02008285" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02008286 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008287 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008288 NetrwKeepj call s:RestoreWinVars()
8289 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008290 unlet s:didsplit
8291
8292 elseif a:mode == 3
8293 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008294 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008295 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02008296" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s")
Bram Moolenaar251e1912011-06-19 05:09:16 +02008297 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008299 NetrwKeepj call s:RestoreWinVars()
8300 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008301 unlet s:didsplit
8302
8303 elseif a:mode == 4
8304 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008305 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008306 let eikeep = &ei
8307 let netrw_winnr = winnr()
8308 let netrw_line = line(".")
8309 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008310 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008311 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008312 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008313 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8314 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008315 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008316 let netrw_curdir= s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008317" call Decho("tabnew")
8318 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008319 let b:netrw_curdir = netrw_curdir
8320 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008321 NetrwKeepj call s:RestoreWinVars()
8322 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008323 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008324 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008325 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8326 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008327 let &ei= eikeep
8328 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008329 unlet s:didsplit
8330
8331 elseif a:mode == 5
8332 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008333 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008334 if winsz == 0|let winsz= ""|endif
Bram Moolenaar15146672011-10-20 22:22:38 +02008335" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v")
Bram Moolenaar251e1912011-06-19 05:09:16 +02008336 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008337 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008338 NetrwKeepj call s:RestoreWinVars()
8339 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
8340 "call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008341 unlet s:didsplit
8342
8343 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008344 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008345 endif
8346
Bram Moolenaar97d62492012-11-15 21:28:22 +01008347 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008348" call Dret("s:NetrwSplit")
8349endfun
8350
8351" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008352" s:NetrwTgtMenu: {{{2
8353fun! s:NetrwTgtMenu()
8354 if !exists("s:netrw_menucnt")
8355 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008356 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008357" call Dfunc("s:NetrwTgtMenu()")
8358
8359 " the following test assures that gvim is running, has menus available, and has menus enabled.
8360 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8361 if exists("g:NetrwTopLvlMenu")
8362" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
8363 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8364 endif
8365 if !exists("s:netrw_initbookhist")
8366 call s:NetrwBookHistRead()
8367 endif
8368
8369 " target bookmarked places
8370 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
8371" call Decho("installing bookmarks as easy targets")
8372 let cnt= 1
8373 for bmd in g:netrw_bookmarklist
8374 let ebmd= escape(bmd,g:netrw_menu_escape)
8375 " show bookmarks for goto menu
8376" call Decho("menu: Targets: ".bmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01008377 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 +02008378 let cnt= cnt + 1
8379 endfor
8380 endif
8381
8382 " target directory browsing history
8383 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
8384" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")")
8385 let histcnt = 1
8386 while histcnt <= g:netrw_dirhistmax
8387 let priority = g:netrw_dirhist_cnt + histcnt
8388 if exists("g:netrw_dirhist_{histcnt}")
8389 let histentry = g:netrw_dirhist_{histcnt}
8390 let ehistentry = escape(histentry,g:netrw_menu_escape)
8391" call Decho("menu: Targets: ".histentry)
Bram Moolenaara6878372014-03-22 21:02:50 +01008392 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 +02008393 endif
8394 let histcnt = histcnt + 1
8395 endwhile
8396 endif
8397 endif
8398" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399endfun
8400
8401" ---------------------------------------------------------------------
8402" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8403" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008404fun! s:NetrwTreeDir(islocal)
8405" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") 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 +00008406
Bram Moolenaar8d043172014-01-23 14:24:41 +01008407 if exists("s:treedir")
8408 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8409 let treedir= s:treedir
8410 unlet s:treedir
8411" call Dret("s:NetrwTreeDir ".treedir)
8412 return treedir
8413 endif
8414 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8415 let b:netrw_curdir= getcwd()
8416 endif
8417 let treedir = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01008418" call Decho("set initial treedir<".treedir.">")
8419 let s:treecurpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420
8421 if w:netrw_liststyle == s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01008422" call Decho("w:netrw_liststyle is TREELIST:")
8423" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008424
8425 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008426 let curline= substitute(getline('.'),"\t -->.*$",'','')
8427 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008428" call Decho("extract tree subdirectory from current line")
8429 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01008430" call Decho("treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008431 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008432" call Decho("do not extract tree subdirectory from current line and set treedir to empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008433 let treedir= ""
8434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008435
8436 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008437" call Decho("check if user is attempting to close treeroot")
8438" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
8439" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~ '^'.s:treedepthstring)? '=~' : '!~').' ^'.s:treedepthstring)
8440 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
8441" call Decho(".user may have attempted to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008442 " now force a refresh
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008443" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d")
8444 sil! NetrwKeepj %d
Bram Moolenaar8d043172014-01-23 14:24:41 +01008445" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01008447" else " Decho
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008448" call Decho(".user did not attempt to close treeroot")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 endif
8450
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008451" call Decho("islocal=".a:islocal." curline<".curline.">")
8452" call Decho("after subst<".substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)$','\1','').">")
8453 let potentialdir= substitute(curline,'^'.s:treedepthstring.'* \(.*\)@$','\1','')
8454" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir))
8455
8456 if a:islocal && curline =~ '@$' && isdirectory(potentialdir)
8457 let newdir = w:netrw_treetop.'/'.potentialdir
8458 let treedir = s:NetrwTreePath(newdir)
8459 let w:netrw_treetop = newdir
8460" call Decho("newdir <".newdir.">")
8461 else
8462 let treedir = s:NetrwTreePath(w:netrw_treetop)
8463 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008465
8466 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008467 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008468" call Decho("treedir<".treedir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469
Bram Moolenaar8d043172014-01-23 14:24:41 +01008470" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".string(s:treecurpos).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471 return treedir
8472endfun
8473
8474" ---------------------------------------------------------------------
8475" s:NetrwTreeDisplay: recursive tree display {{{2
8476fun! s:NetrwTreeDisplay(dir,depth)
8477" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
8478
8479 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008480 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481
8482 " install ../ and shortdir
8483 if a:depth == ""
8484 call setline(line("$")+1,'../')
8485" call Decho("setline#".line("$")." ../ (depth is zero)")
8486 endif
8487 if a:dir =~ '^\a\+://'
8488 if a:dir == w:netrw_treetop
8489 let shortdir= a:dir
8490 else
8491 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8492 endif
8493 call setline(line("$")+1,a:depth.shortdir)
8494 else
8495 let shortdir= substitute(a:dir,'^.*/','','e')
8496 call setline(line("$")+1,a:depth.shortdir.'/')
8497 endif
8498" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">")
8499
8500 " append a / to dir if its missing one
8501 let dir= a:dir
8502 if dir !~ '/$'
8503 let dir= dir.'/'
8504 endif
8505
8506 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008507 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008508
8509" call Decho("display subtrees with depth<".depth."> and current leaves")
8510 for entry in w:netrw_treedict[a:dir]
8511 let direntry= substitute(dir.entry,'/$','','e')
8512" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">")
8513 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
8514" call Decho("<".direntry."> is a key in treedict - display subtree for it")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008515 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008516 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
8517" call Decho("<".direntry."/> is a key in treedict - display subtree for it")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008518 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519 else
8520" call Decho("<".entry."> is not a key in treedict (no subtree)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008521 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008522 endif
8523 endfor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008524
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525" call Dret("NetrwTreeDisplay")
8526endfun
8527
8528" ---------------------------------------------------------------------
8529" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
8530fun! s:NetrwTreeListing(dirname)
8531 if w:netrw_liststyle == s:TREELIST
8532" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01008533" call Decho("curdir<".a:dirname.">")
8534" 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"))
8535" 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 +00008536
8537 " update the treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01008538" call Decho("update the treetop")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008539 if !exists("w:netrw_treetop")
8540 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01008541" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008542 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
8543 let w:netrw_treetop= a:dirname
Bram Moolenaara6878372014-03-22 21:02:50 +01008544" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545 endif
8546
8547 " insure that we have at least an empty treedict
8548 if !exists("w:netrw_treedict")
8549 let w:netrw_treedict= {}
8550 endif
8551
8552 " update the directory listing for the current directory
Bram Moolenaara6878372014-03-22 21:02:50 +01008553" call Decho("updating dictionary with ".a:dirname.":[..directory listing..]")
8554" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008555 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008556 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008557" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008558 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008559
8560 " if past banner, record word
8561 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8562 let fname= expand("<cword>")
8563 else
8564 let fname= ""
8565 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008566" call Decho("fname<".fname.">")
8567" 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 +00008568
8569 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008570 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008571" call Decho("s:NetrwTreeDisplay) setl noma nomod ro")
8572
8573 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8574 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara6878372014-03-22 21:02:50 +01008575" call Decho("deleting blank line")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008576 1d
8577 endwhile
8578
Bram Moolenaar13600302014-05-22 18:26:40 +02008579 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008580
8581" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008582 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 endif
8584endfun
8585
8586" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01008587" s:NetrwTreePath: returns path to current file in tree listing {{{2
8588" Normally, treetop is w:netrw_treetop, but a
8589" user of the function ( netrw#SetTreetop() )
8590" wipes that out prior to calling this function
8591fun! s:NetrwTreePath(treetop)
8592" call Dfunc("s:NetrwTreePath() line#".line(".")."<".getline(".").">")
8593 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
8594" call Decho("(s:NetrwTreePath) depth<".depth."> 1st subst")
8595 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8596" call Decho("(s:NetrwTreePath) depth<".depth."> 2nd subst (first depth removed)")
8597 if getline('.') =~ '/$'
8598" call Decho("extract tree directory from current line")
8599 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8600" call Decho("(s:NetrwTreePath) treedir<".treedir.">")
8601 else
8602" call Decho("(s:NetrwTreePath) do not extract tree directory from current line and set treedir to empty")
8603 let treedir= ""
8604 endif
8605 " construct treedir by searching backwards at correct depth
8606" call Decho("(s:NetrwTreePath) construct treedir by searching backwards for correct depth")
8607" call Decho("(s:NetrwTreePath) initial treedir<".treedir."> depth<".depth.">")
8608 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
8609 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
8610 let treedir= dirname.treedir
8611 let depth = substitute(depth,'^'.s:treedepthstring,'','')
8612" call Decho("(s:NetrwTreePath) constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">")
8613 endwhile
8614 if a:treetop =~ '/$'
8615 let treedir= a:treetop.treedir
8616 else
8617 let treedir= a:treetop.'/'.treedir
8618 endif
8619 let treedir= substitute(treedir,'//$','/','')
8620" call Dret("s:NetrwTreePath <".treedir.">")
8621 return treedir
8622endfun
8623
8624" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625" s:NetrwWideListing: {{{2
8626fun! s:NetrwWideListing()
8627
8628 if w:netrw_liststyle == s:WIDELIST
8629" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
8630 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008631 " cpf: characters per filename
8632 " fpl: filenames per line
8633 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02008634 setl ma noro
8635" call Decho("setl ma noro")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 let b:netrw_cpf= 0
8637 if line("$") >= w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008638 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
8639 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 else
8641" call Dret("NetrwWideListing")
8642 return
8643 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008644 let b:netrw_cpf= b:netrw_cpf + 2
8645" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008646
8647 " determine qty files per line (fpl)
8648 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
8649 if w:netrw_fpl <= 0
8650 let w:netrw_fpl= 1
8651 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008652" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653
8654 " make wide display
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008655 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'s",submatch(0)),"\\")/'
8656 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
8658 let newcolstart = w:netrw_bannercnt + fpc
8659 let newcolend = newcolstart + fpc - 1
8660" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008661 if has("clipboard")
8662 sil! let keepregstar = @*
8663 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 while line("$") >= newcolstart
8665 if newcolend > line("$") | let newcolend= line("$") | endif
8666 let newcolqty= newcolend - newcolstart
8667 exe newcolstart
8668 if newcolqty == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008669 exe "sil! NetrwKeepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008671 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008673 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d'
8674 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008675 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01008676 if has("clipboard")
8677 sil! let @*= keepregstar
8678 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008679 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
8680 NetrwKeepj call histdel("/",-1)
8681 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
8682 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008683" call Decho("NetrwWideListing) setl noma nomod ro")
Bram Moolenaar13600302014-05-22 18:26:40 +02008684 exe "setl ".g:netrw_bufsettings
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008685" 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 +00008686" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008687 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008688 else
8689 if hasmapto("w","n")
8690 sil! nunmap <buffer> w
8691 endif
8692 if hasmapto("b","n")
8693 sil! nunmap <buffer> b
8694 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695 endif
8696
8697endfun
8698
8699" ---------------------------------------------------------------------
8700" s:PerformListing: {{{2
8701fun! s:PerformListing(islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008702" call Dfunc("s:PerformListing(islocal=".a:islocal.") bufnr(%)=".bufnr("%")."<".bufname("%").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01008703" 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 +00008704
Bram Moolenaar15146672011-10-20 22:22:38 +02008705 " set up syntax highlighting {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008706" call Decho("set up syntax highlighting (ie. setl ft=netrw)")
8707 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02008708
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008709 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01008710 setl noro ma
8711" call Decho("setl noro ma bh=".&bh)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712
8713" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008714" call Decho("(netrw) Processing your browsing request...")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715" endif " Decho
8716
8717" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
8718 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
8719 " force a refresh for tree listings
Bram Moolenaara6878372014-03-22 21:02:50 +01008720" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008721 sil! NetrwKeepj %d
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722 endif
8723
8724 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008725 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726
8727 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008728 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008729" call Decho("set up banner")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008730 NetrwKeepj call setline(1,'" ============================================================================')
8731 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008732 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008733 NetrwKeepj call setline(3,'" '.substitute(b:netrw_curdir,'/','\\','g'))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008735 NetrwKeepj call setline(3,'" '.b:netrw_curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02008736 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008737 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008738 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008739 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008740 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01008741 let w:netrw_bannercnt= 1
8742 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008743" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744
8745 let sortby= g:netrw_sort_by
8746 if g:netrw_sort_direction =~ "^r"
8747 let sortby= sortby." reversed"
8748 endif
8749
8750 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008751 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008752" call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008753 if g:netrw_sort_by =~ "^n"
Bram Moolenaara6878372014-03-22 21:02:50 +01008754" call Decho("directories will be sorted by name")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008755 " sorted by name
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008756 NetrwKeepj put ='\" Sorted by '.sortby
8757 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01008758 let w:netrw_bannercnt= w:netrw_bannercnt + 2
8759 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008760" call Decho("directories will be sorted by size or time")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008761 " sorted by size or date
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008762 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01008763 let w:netrw_bannercnt= w:netrw_bannercnt + 1
8764 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008765 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01008766" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008767" 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 +00008768 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008769
8770 " show copy/move target, if any
Bram Moolenaar5c736222010-01-06 20:54:52 +01008771 if g:netrw_banner
8772 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara6878372014-03-22 21:02:50 +01008773" call Decho("show copy/move target<".s:netrwmftgt.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008774 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01008775 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008776 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008777 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008778 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008779 endif
8780 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 else
Bram Moolenaara6878372014-03-22 21:02:50 +01008782" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008784 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786
8787 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01008788 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01008789" 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 +01008790 if g:netrw_list_hide != "" && g:netrw_hide
8791 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008792 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008793 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008794 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01008795 endif
8796 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008797 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008798 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008799
8800" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
8801 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
8802" call Decho("quickhelp =".quickhelp)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008803 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara6878372014-03-22 21:02:50 +01008804" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008805 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01008806 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01008807" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008808" 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 +00008809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810
8811 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01008812 if g:netrw_banner
8813 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008815" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008816" else " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01008817" 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 +01008818 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008819
Bram Moolenaar446cb832008-06-24 21:56:24 +00008820 " get list of files
Bram Moolenaara6878372014-03-22 21:02:50 +01008821" call Decho("Get list of files - islocal=".a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008823 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01008826 if badresult
8827" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">")
8828" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
8829 return
8830 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
8833 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008834 if !exists("w:netrw_bannercnt")
8835 let w:netrw_bannercnt= 0
8836 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008837" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)")
8838" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
8839
Bram Moolenaar5c736222010-01-06 20:54:52 +01008840 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008841" call Decho("manipulate directory listing (hide)")
8842" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008844 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008846 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01008847" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848
8849 if g:netrw_sort_by =~ "^n"
8850 " sort by name
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008851 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852
Bram Moolenaar5c736222010-01-06 20:54:52 +01008853 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008854" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 if g:netrw_sort_direction =~ 'n'
8856 " normal direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008857 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 else
8859 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 endif
8862 endif
8863 " remove priority pattern prefix
Bram Moolenaara6878372014-03-22 21:02:50 +01008864" call Decho("remove priority pattern prefix")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
8866 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867
8868 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01008869 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara6878372014-03-22 21:02:50 +01008870" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871 if g:netrw_sort_direction =~ 'n'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008872" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort')
8873 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008875" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!')
8876 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008878 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
8879 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01008880 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881 endif
8882
8883 elseif g:netrw_sort_direction =~ 'r'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008884" call Decho('(s:PerformListing) reverse the sorted listing')
Bram Moolenaar5c736222010-01-06 20:54:52 +01008885 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01008887 call histdel("/",-1)
8888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 endif
8890 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01008891" 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 +00008892
8893 " convert to wide/tree listing {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008894" call Decho("modify display if wide/tree listing style")
8895" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01008896 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01008897" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01008898 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01008899" 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 +00008900
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008901 " resolve symbolic links if local and (thin or tree)
8902 if a:islocal && (w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:TREELIST)
8903 g/@$/call s:ShowLink()
8904 endif
8905
Bram Moolenaar5c736222010-01-06 20:54:52 +01008906 if exists("w:netrw_bannercnt") && (line("$") > w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 " place cursor on the top-left corner of the file listing
Bram Moolenaara6878372014-03-22 21:02:50 +01008908" call Decho("place cursor on top-left corner of file listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
8910 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008911 endif
8912
8913 " record previous current directory
8914 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01008915" call Decho("record netrw_prvdir<".w:netrw_prvdir.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916
8917 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01008918" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01008919 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara6878372014-03-22 21:02:50 +01008920" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01008921 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01008922" 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 +00008923
8924 " set display to netrw display settings
Bram Moolenaara6878372014-03-22 21:02:50 +01008925" call Decho("set display to netrw display settings (".g:netrw_bufsettings.")")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02008926 exe "setl ".g:netrw_bufsettings
Bram Moolenaara6878372014-03-22 21:02:50 +01008927" 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 +01008928 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara6878372014-03-22 21:02:50 +01008929" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008930 exe "setl ts=".(g:netrw_maxfilenamelen+1)
8931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932
Bram Moolenaar8d043172014-01-23 14:24:41 +01008933 if exists("s:treecurpos")
Bram Moolenaara6878372014-03-22 21:02:50 +01008934" 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)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008935 NetrwKeepj call netrw#RestorePosn(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 unlet s:treecurpos
8937 endif
8938
Bram Moolenaara6878372014-03-22 21:02:50 +01008939" 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 +00008940" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
8941endfun
8942
8943" ---------------------------------------------------------------------
8944" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008945fun! s:SetupNetrwStatusLine(statline)
8946" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
8947
8948 if !exists("s:netrw_setup_statline")
8949 let s:netrw_setup_statline= 1
8950" call Decho("do first-time status line setup")
8951
8952 if !exists("s:netrw_users_stl")
8953 let s:netrw_users_stl= &stl
8954 endif
8955 if !exists("s:netrw_users_ls")
8956 let s:netrw_users_ls= &laststatus
8957 endif
8958
8959 " set up User9 highlighting as needed
8960 let keepa= @a
8961 redir @a
8962 try
8963 hi User9
8964 catch /^Vim\%((\a\+)\)\=:E411/
8965 if &bg == "dark"
8966 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
8967 else
8968 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
8969 endif
8970 endtry
8971 redir END
8972 let @a= keepa
8973 endif
8974
8975 " set up status line (may use User9 highlighting)
8976 " insure that windows have a statusline
8977 " make sure statusline is displayed
8978 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02008979 setl laststatus=2
Bram Moolenaar9964e462007-05-05 17:54:07 +00008980" call Decho("stl=".&stl)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008981 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00008982
8983" call Dret("SetupNetrwStatusLine : stl=".&stl)
8984endfun
8985
8986" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008987" Remote Directory Browsing Support: {{{1
8988" ===========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00008989
8990" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01008991" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
8992" This function assumes that a long listing will be received. Size, time,
8993" and reverse sorts will be requested of the server but not otherwise
8994" enforced here.
8995fun! s:NetrwRemoteFtpCmd(path,listcmd)
8996" 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 : "???")))
8997" call Decho("line($)=".line("$")." w:netrw_bannercnt=".w:netrw_bannercnt)
8998 " sanity check: {{{3
8999 if !exists("w:netrw_method")
9000 if exists("b:netrw_method")
9001 let w:netrw_method= b:netrw_method
9002 else
9003 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9004" call Dret("NetrwRemoteFtpCmd")
9005 return
9006 endif
9007 endif
9008
9009 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9010 let ffkeep= &ff
9011 setl ma ff=unix noro
9012" call Decho("setl ma ff=unix noro")
9013
9014 " clear off any older non-banner lines " {{{3
9015 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009016" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d (clear off old non-banner lines)")
9017 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d"
Bram Moolenaara6878372014-03-22 21:02:50 +01009018
9019 ".........................................
9020 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9021 " ftp + <.netrc>: Method #2
9022 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009023 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009024 endif
9025 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009026 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara6878372014-03-22 21:02:50 +01009027" call Decho("filter input: ".getline('.'))
9028 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009029 NetrwKeepj call setline(line("$")+1,a:listcmd)
9030" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009031 if exists("g:netrw_port") && g:netrw_port != ""
9032" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009033 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009034 else
9035" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009036 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009037 endif
9038
9039 ".........................................
9040 elseif w:netrw_method == 3 " {{{3
9041 " ftp + machine,id,passwd,filename: Method #3
9042 setl ff=unix
9043 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009044 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009045 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009046 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009047 endif
9048
9049 " handle userid and password
9050 let host= substitute(g:netrw_machine,'\..*$','','')
9051" call Decho("host<".host.">")
9052 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9053 call NetUserPass("ftp:".host)
9054 endif
9055 if exists("g:netrw_uid") && g:netrw_uid != ""
9056 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009057 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009058 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009059 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009060 endif
9061 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009062 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009063 endif
9064 endif
9065
9066 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009067 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009068 endif
9069 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009070 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara6878372014-03-22 21:02:50 +01009071" call Decho("filter input: ".getline('.'))
9072 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009073 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009074
9075 " perform ftp:
9076 " -i : turns off interactive prompting from ftp
9077 " -n unix : DON'T use <.netrc>, even though it exists
9078 " -n win32: quit being obnoxious about password
9079 if exists("w:netrw_bannercnt")
9080" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009081 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009082" else " Decho
9083" call Decho("WARNING: w:netrw_bannercnt doesn't exist!")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009084" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."))
Bram Moolenaara6878372014-03-22 21:02:50 +01009085 endif
9086
9087 ".........................................
9088 elseif w:netrw_method == 9 " {{{3
9089 " sftp username@machine: Method #9
9090 " s:netrw_sftp_cmd
9091 setl ff=unix
9092
9093 " restore settings
9094 let &ff= ffkeep
9095" call Dret("NetrwRemoteFtpCmd")
9096 return
9097
9098 ".........................................
9099 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009101 endif
9102
9103 " cleanup for Windows " {{{3
9104 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009105 sil! NetrwKeepj %s/\r$//e
9106 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009107 endif
9108 if a:listcmd == "dir"
9109 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009110 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9111 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9112 NetrwKeepj call histdel("/",-1)
9113 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009114 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009115 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9116 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009117 endif
9118 endif
9119
9120 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9121 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009122 exe 'NetrwKeepj '.w:netrw_bannercnt
9123 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009124 endif
9125 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009126 exe 'NetrwKeepj '.w:netrw_bannercnt
9127 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009128 endif
9129
9130 " restore settings " {{{3
9131 let &ff= ffkeep
9132" call Dret("NetrwRemoteFtpCmd")
9133endfun
9134
9135" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136" s:NetrwRemoteListing: {{{2
9137fun! s:NetrwRemoteListing()
9138" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">)")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009139
Bram Moolenaara6878372014-03-22 21:02:50 +01009140 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9141 let w:netrw_bannercnt= s:bannercnt
9142 endif
9143 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
9144 let w:netrw_bannercnt= s:bannercnt
9145 endif
9146
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009148
Bram Moolenaar446cb832008-06-24 21:56:24 +00009149 " sanity check:
9150 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaar8d043172014-01-23 14:24:41 +01009151" call Decho("b:netrw_method=".b:netrw_method)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 if !executable("ftp")
Bram Moolenaara6878372014-03-22 21:02:50 +01009153" call Decho("ftp is not executable")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154 if !exists("g:netrw_quiet")
9155 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9156 endif
9157 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009158" call Dret("s:NetrwRemoteListing -1")
9159 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009160 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009161
Bram Moolenaar8d043172014-01-23 14:24:41 +01009162 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara6878372014-03-22 21:02:50 +01009163" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009165 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009166 NetrwKeepj 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 +00009167 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009168 NetrwKeepj 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 +00009169 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009170 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009171
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009172 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009173" call Dret("s:NetrwRemoteListing -1")
9174 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175 endif " (remote handling sanity check)
Bram Moolenaara6878372014-03-22 21:02:50 +01009176" call Decho("passed remote listing sanity checks")
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009177
Bram Moolenaar446cb832008-06-24 21:56:24 +00009178 if exists("b:netrw_method")
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009179" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009180 let w:netrw_method= b:netrw_method
9181 endif
9182
Bram Moolenaar13600302014-05-22 18:26:40 +02009183 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009184 " use ftp to get remote file listing {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00009185" call Decho("use ftp to get remote file listing")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009186 let s:method = "ftp"
9187 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009188 if g:netrw_sort_by =~ '^t'
9189 let listcmd= g:netrw_ftp_timelist_cmd
9190 elseif g:netrw_sort_by =~ '^s'
9191 let listcmd= g:netrw_ftp_sizelist_cmd
9192 endif
9193" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)")
9194 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009195" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009196
Bram Moolenaara6878372014-03-22 21:02:50 +01009197 " report on missing file or directory messages
9198 if search('[Nn]o such file or directory\|Failed to change directory')
9199 let mesg= getline(".")
9200 if exists("w:netrw_bannercnt")
9201 setl ma
9202 exe w:netrw_bannercnt.",$d"
9203 setl noma
9204 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009205 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009206 call netrw#ErrorMsg(s:WARNING,mesg,96)
9207" call Dret("s:NetrwRemoteListing : -1")
9208 return -1
9209 endif
9210
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || w:netrw_liststyle == s:TREELIST
9212 " shorten the listing
9213" call Decho("generate short listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009214 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215
9216 " cleanup
9217 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009218 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9219 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009220 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 sil! NetrwKeepj %s/\r$//e
9222 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009223
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009224 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009226 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009227 let line2= search('\.\.\/\%(\s\|$\)','cnW')
9228" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 if line2 == 0
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009230" call Decho("netrw is putting ../ into listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009231 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009232 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 exe "sil! NetrwKeepj ".line1
9234 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235
9236" call Decho("line1=".line1." line2=".line2." line(.)=".line("."))
9237 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
9238" call Decho("M$ ftp cleanup")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009239 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9240 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241 else " normal ftp cleanup
9242" call Decho("normal ftp cleanup")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009243 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9244 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9245 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9246 NetrwKeepj call histdel("/",-1)
9247 NetrwKeepj call histdel("/",-1)
9248 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 endif
9250 endif
9251
Bram Moolenaar13600302014-05-22 18:26:40 +02009252 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 " use ssh to get remote file listing {{{3
9254" call Decho("use ssh to get remote file listing: s:path<".s:path.">")
9255 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
9256" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)")
9257 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009258" call Decho("1: exe r! ".shellescape(listcmd.s:path, 1))
9259 exe "NetrwKeepj r! ".listcmd.shellescape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9262 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9263 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9264 NetrwKeepj call histdel("/",-1)
9265 NetrwKeepj call histdel("/",-1)
9266 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009268 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9269 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270 endif
9271 else
9272 if s:path == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009273" call Decho("2: exe r! ".listcmd)
9274 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276" call Decho("3: exe r! ".listcmd.' '.shellescape(fnameescape(s:path),1))
9277 exe "NetrwKeepj keepalt r! ".listcmd.' '.shellescape(fnameescape(s:path),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278" call Decho("listcmd<".listcmd."> path<".s:path.">")
9279 endif
9280 endif
9281
9282 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009283 if g:netrw_ssh_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d")
9285 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9286 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 endif
9288 endif
9289
9290 if w:netrw_liststyle == s:LONGLIST
9291 " do a long listing; these substitutions need to be done prior to sorting {{{3
9292" call Decho("fix long listing:")
9293
9294 if s:method == "ftp"
9295 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009296 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009297 while getline('.') =~ g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009300 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009301 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009302 sil! NetrwKeepj 1
9303 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009304 let line2= line(".")
9305 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009307 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 endif
9309 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009310 exe "sil! NetrwKeepj ".line1
9311 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009312 endif
9313
9314 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
9315" call Decho("M$ ftp site listing cleanup")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009316 exe 'sil! NetrwKeepj '.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 +00009317 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
9318" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009319 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
9320 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2\t\1/e'
9321 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9322 NetrwKeepj call histdel("/",-1)
9323 NetrwKeepj call histdel("/",-1)
9324 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 endif
9326 endif
9327
9328" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009329" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009331
9332" call Dret("s:NetrwRemoteListing 0")
9333 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009334endfun
9335
Bram Moolenaar446cb832008-06-24 21:56:24 +00009336" ---------------------------------------------------------------------
9337" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9338fun! s:NetrwRemoteRm(usrhost,path) range
9339" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
9340" call Decho("firstline=".a:firstline." lastline=".a:lastline)
Bram Moolenaara6878372014-03-22 21:02:50 +01009341 let svpos= netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009342
9343 let all= 0
9344 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9345 " remove all marked files
Bram Moolenaar5c736222010-01-06 20:54:52 +01009346" call Decho("remove all marked files with bufnr#".bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009347 for fname in s:netrwmarkfilelist_{bufnr("%")}
9348 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
9349 if ok =~ 'q\%[uit]'
9350 break
9351 elseif ok =~ 'a\%[ll]'
9352 let all= 1
9353 endif
9354 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009355 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009356
9357 else
9358 " remove files specified by range
Bram Moolenaar5c736222010-01-06 20:54:52 +01009359" call Decho("remove files specified by range")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009360
9361 " preparation for removing multiple files/directories
9362 let ctr= a:firstline
9363
9364 " remove multiple files and directories
9365 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009366 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009367 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
9368 if ok =~ 'q\%[uit]'
9369 break
9370 elseif ok =~ 'a\%[ll]'
9371 let all= 1
9372 endif
9373 let ctr= ctr + 1
9374 endwhile
9375 endif
9376
9377 " refresh the (remote) directory listing
9378" call Decho("refresh remote directory listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009379 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
9380 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009381
9382" call Dret("s:NetrwRemoteRm")
9383endfun
9384
9385" ---------------------------------------------------------------------
9386" s:NetrwRemoteRmFile: {{{2
9387fun! s:NetrwRemoteRmFile(path,rmfile,all)
9388" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9389
9390 let all= a:all
9391 let ok = ""
9392
9393 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9394 " attempt to remove file
9395" call Decho("attempt to remove file (all=".all.")")
9396 if !all
9397 echohl Statement
9398" call Decho("case all=0:")
9399 call inputsave()
9400 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9401 call inputrestore()
9402 echohl NONE
9403 if ok == ""
9404 let ok="no"
9405 endif
9406 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9407 if ok =~ 'a\%[ll]'
9408 let all= 1
9409 endif
9410 endif
9411
9412 if all || ok =~ 'y\%[es]' || ok == ""
9413" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""))
9414 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
9415" call Decho("case ftp:")
9416 let path= a:path
9417 if path =~ '^\a\+://'
9418 let path= substitute(path,'^\a\+://[^/]\+/','','')
9419 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009420 sil! NetrwKeepj .,$d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9422 else
9423" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">")
9424 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
9425" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
9426 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009427 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009428 let ok="q"
9429 else
9430 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
9431" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">")
9432" call Decho("remotedir<".remotedir.">")
9433" call Decho("rmfile<".a:rmfile.">")
9434 if remotedir != ""
9435 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(remotedir.a:rmfile))
9436 else
9437 let netrw_rm_cmd= netrw_rm_cmd." ".shellescape(fnameescape(a:rmfile))
9438 endif
9439" call Decho("call system(".netrw_rm_cmd.")")
9440 let ret= system(netrw_rm_cmd)
9441 if ret != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009442 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 endif
9444" call Decho("returned=".ret." errcode=".v:shell_error)
9445 endif
9446 endif
9447 elseif ok =~ 'q\%[uit]'
9448" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 endif
9450
9451 else
9452 " attempt to remove directory
9453" call Decho("attempt to remove directory")
9454 if !all
9455 call inputsave()
9456 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9457 call inputrestore()
9458 if ok == ""
9459 let ok="no"
9460 endif
9461 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
9462 if ok =~ 'a\%[ll]'
9463 let all= 1
9464 endif
9465 endif
9466
9467 if all || ok =~ 'y\%[es]' || ok == ""
9468 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009469 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470 else
9471 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009472 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.shellescape(netrw#WinPath(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")")
Bram Moolenaarc236c162008-07-13 17:41:49 +00009474 let ret= system(netrw_rmdir_cmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475" call Decho("returned=".ret." errcode=".v:shell_error)
9476
9477 if v:shell_error != 0
Bram Moolenaarc236c162008-07-13 17:41:49 +00009478" call Decho("v:shell_error not 0")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009479 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 +00009480" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")")
9481 let ret= system(netrw_rmf_cmd)
9482" call Decho("returned=".ret." errcode=".v:shell_error)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009483
9484 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009485 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009486 endif
9487 endif
9488 endif
9489
9490 elseif ok =~ 'q\%[uit]'
Bram Moolenaarff034192013-04-24 18:51:19 +02009491" call Decho("ok==".ok)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009492 endif
9493 endif
9494
9495" call Dret("s:NetrwRemoteRmFile ".ok)
9496 return ok
9497endfun
9498
9499" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500" s:NetrwRemoteRename: rename a remote file or directory {{{2
9501fun! s:NetrwRemoteRename(usrhost,path) range
9502" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
9503
9504 " preparation for removing multiple files/directories
Bram Moolenaara6878372014-03-22 21:02:50 +01009505 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506 let ctr = a:firstline
9507 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
9508
9509 " rename files given by the markfilelist
9510 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9511 for oldname in s:netrwmarkfilelist_{bufnr("%")}
9512" call Decho("oldname<".oldname.">")
9513 if exists("subfrom")
9514 let newname= substitute(oldname,subfrom,subto,'')
9515" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9516 else
9517 call inputsave()
9518 let newname= input("Moving ".oldname." to : ",oldname)
9519 call inputrestore()
9520 if newname =~ '^s/'
9521 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9522 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9523 let newname = substitute(oldname,subfrom,subto,'')
9524" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
9525 endif
9526 endif
9527
9528 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009529 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00009531 let oldname= shellescape(a:path.oldname)
9532 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009533" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
9534 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535 endif
9536
9537 endfor
9538 call s:NetrwUnMarkFile(1)
9539
9540 else
9541
9542 " attempt to rename files/directories
9543 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009544 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009545
9546 let oldname= s:NetrwGetWord()
9547" call Decho("oldname<".oldname.">")
9548
9549 call inputsave()
9550 let newname= input("Moving ".oldname." to : ",oldname)
9551 call inputrestore()
9552
9553 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
9554 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
9555 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00009556 let oldname= shellescape(a:path.oldname)
9557 let newname= shellescape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009558" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")")
9559 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009560 endif
9561
9562 let ctr= ctr + 1
9563 endwhile
9564 endif
9565
9566 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009567 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
9568 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009569
9570" call Dret("NetrwRemoteRename")
9571endfun
9572
9573" ---------------------------------------------------------------------
9574" Local Directory Browsing Support: {{{1
9575" ==========================================
9576
9577" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009578" netrw#FileUrlRead: handles reading file://* files {{{2
9579" Should accept: file://localhost/etc/fstab
9580" file:///etc/fstab
9581" file:///c:/WINDOWS/clock.avi
9582" file:///c|/WINDOWS/clock.avi
9583" file://localhost/c:/WINDOWS/clock.avi
9584" file://localhost/c|/WINDOWS/clock.avi
9585" file://c:/foo.txt
9586" file:///c:/foo.txt
9587" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
9588fun! netrw#FileUrlRead(fname)
9589" call Dfunc("netrw#FileUrlRead(fname<".a:fname.">)")
9590 let fname = a:fname
9591 if fname =~ '^file://localhost/'
9592" call Decho('converting file://localhost/ -to- file:///')
9593 let fname= substitute(fname,'^file://localhost/','file:///','')
9594" call Decho("fname<".fname.">")
9595 endif
9596 if (has("win32") || has("win95") || has("win64") || has("win16"))
9597 if fname =~ '^file:///\=\a[|:]/'
9598" call Decho('converting file:///\a|/ -to- file://\a:/')
9599 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
9600" call Decho("fname<".fname.">")
9601 endif
9602 endif
9603 let fname2396 = netrw#RFC2396(fname)
9604 let fname2396e= fnameescape(fname2396)
9605 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
9606 if (has("win32") || has("win95") || has("win64") || has("win16"))
9607" call Decho("windows exception for plainfname")
9608 if plainfname =~ '^/\+\a:'
9609" call Decho('removing leading "/"s')
9610 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
9611 endif
9612 endif
9613" call Decho("fname2396<".fname2396.">")
9614" call Decho("plainfname<".plainfname.">")
9615 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009616 exe 'NetrwKeepj r '.plainfname
Bram Moolenaarff034192013-04-24 18:51:19 +02009617 exe 'sil! bdelete '.plainfname
9618 exe 'keepalt file! '.plainfname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009619 NetrwKeepj 1d
Bram Moolenaara6878372014-03-22 21:02:50 +01009620" call Decho("setl nomod")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009621 setl nomod
Bram Moolenaara6878372014-03-22 21:02:50 +01009622" 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 +01009623" call Dret("netrw#FileUrlRead")
9624 exe "sil doau BufReadPost ".fname2396e
9625endfun
9626
9627" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009628" netrw#LocalBrowseCheck: {{{2
9629fun! netrw#LocalBrowseCheck(dirname)
9630 " unfortunate interaction -- split window debugging can't be
9631 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
9632 " event triggers another call to LocalBrowseCheck() when attempts
9633 " to write to the DBG buffer are made.
9634 " The &ft == "netrw" test was installed because the BufEnter event
9635 " would hit when re-entering netrw windows, creating unexpected
9636 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaara6878372014-03-22 21:02:50 +01009637" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">")
9638" call Decho("isdir<".a:dirname.">=".isdirectory(a:dirname).((exists("s:treeforceredraw")? " treeforceredraw" : "")))
9639" 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)
9640" call Dredir("ls!","ls!")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009641 norm! m`
Bram Moolenaara6878372014-03-22 21:02:50 +01009642
Bram Moolenaar97d62492012-11-15 21:28:22 +01009643 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644 if isdirectory(a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01009645" 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)
9646 let svposn= netrw#SavePosn()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009647
Bram Moolenaar97d62492012-11-15 21:28:22 +01009648 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009649" call Decho("case 1 : ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009650 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
9651 NetrwKeepj keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009652
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara6878372014-03-22 21:02:50 +01009654" call Decho("case 2 (ft≡netrw && line($)≡1)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009655 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
9656 NetrwKeepj keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009657
Bram Moolenaar5c736222010-01-06 20:54:52 +01009658 elseif exists("s:treeforceredraw")
Bram Moolenaara6878372014-03-22 21:02:50 +01009659" call Decho("case 3 (treeforceredraw)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01009660 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009661 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
9662 NetrwKeepj keepalt call netrw#RestorePosn(svposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009664
Bram Moolenaara6878372014-03-22 21:02:50 +01009665" call Dret("netrw#LocalBrowseCheck")
9666 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009668
Bram Moolenaar97d62492012-11-15 21:28:22 +01009669 " following code wipes out currently unused netrw buffers
9670 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
9671 " AND IF the listing style is not a tree listing
9672 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara6878372014-03-22 21:02:50 +01009673" call Decho("wiping out currently unused netrw buffers")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009674 let ibuf = 1
9675 let buflast = bufnr("$")
9676 while ibuf <= buflast
9677 if bufwinnr(ibuf) == -1 && isdirectory(bufname(ibuf))
Bram Moolenaarff034192013-04-24 18:51:19 +02009678 exe "sil! keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009679 endif
9680 let ibuf= ibuf + 1
9681 endwhile
9682 endif
9683 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009684" 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 +00009685 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +01009686" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009687endfun
9688
9689" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009690" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691" performed any shell command. The idea is to cause all local-browsing
9692" buffers to be refreshed after a user has executed some shell command,
9693" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +01009694fun! s:LocalBrowseRefresh()
9695" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
9696" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'))
9697" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'))
9698
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699 " determine which buffers currently reside in a tab
9700 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009701" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 return
9703 endif
9704 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +01009705" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009706 return
9707 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009708 if exists("s:netrw_events") && s:netrw_events == 1
9709 " s:LocalFastBrowser gets called (indirectly) from a
9710 let s:netrw_events= 2
9711" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
9712 return
Bram Moolenaar5c736222010-01-06 20:54:52 +01009713 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714 let itab = 1
9715 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +01009716 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717 while itab <= tabpagenr("$")
9718 let buftablist = buftablist + tabpagebuflist()
9719 let itab = itab + 1
9720 tabn
9721 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009722" call Decho("buftablist".string(buftablist))
9723" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
9725 " | refresh any netrw window
9726 " | wipe out any non-displaying netrw buffer
9727 let curwin = winnr()
9728 let ibl = 0
9729 for ibuf in s:netrw_browselist
Bram Moolenaara6878372014-03-22 21:02:50 +01009730" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
9732 " wipe out any non-displaying netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009733" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009734 exe "sil! bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009735 call remove(s:netrw_browselist,ibl)
Bram Moolenaara6878372014-03-22 21:02:50 +01009736" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737 continue
9738 elseif index(tabpagebuflist(),ibuf) != -1
9739 " refresh any netrw buffer
Bram Moolenaara6878372014-03-22 21:02:50 +01009740" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 if getline(".") =~ 'Quick Help'
9743 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
9744 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
9745 let g:netrw_quickhelp= g:netrw_quickhelp - 1
9746 endif
9747" call Decho("#3: quickhelp=".g:netrw_quickhelp)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009748 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009749 endif
9750 let ibl= ibl + 1
9751 endfor
9752 exe curwin."wincmd w"
Bram Moolenaar97d62492012-11-15 21:28:22 +01009753 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009754
Bram Moolenaara6878372014-03-22 21:02:50 +01009755" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009756endfun
9757
9758" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009759" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
9760"
9761" g:netrw_ Directory Is
9762" fastbrowse Local Remote
9763" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
9764" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
9765" fast 2 H H
9766"
9767" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
9768" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +01009769" (re-using a buffer may not be as accurate)
9770"
9771" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
9772" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
9773" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
9774" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
9775" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009776fun! s:LocalFastBrowser()
Bram Moolenaara6878372014-03-22 21:02:50 +01009777" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
9778" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'))
9779" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "installed" : "not installed"))
9780" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "installed" : "not installed"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009781
9782 " initialize browselist, a list of buffer numbers that the local browser has used
9783 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +01009784" call Decho("initialize s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009785 let s:netrw_browselist= []
9786 endif
9787
9788 " append current buffer to fastbrowse list
9789 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara6878372014-03-22 21:02:50 +01009790" call Decho("appendng current buffer to browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009791 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009792" call Decho("browselist=".string(s:netrw_browselist))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009793 endif
9794
9795 " enable autocmd events to handle refreshing/removing local browser buffers
9796 " If local browse buffer is currently showing: refresh it
9797 " If local browse buffer is currently hidden : wipe it
9798 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
9799 " =1 : medium speed, re-use directory listing for remote only
9800 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +01009801 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
9802 let s:netrw_events= 1
9803 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009804 au!
9805 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009806" call Decho("installing autocmd: ShellCmdPost")
9807 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009808 else
Bram Moolenaara6878372014-03-22 21:02:50 +01009809" call Decho("installing autocmds: ShellCmdPost FocusGained")
9810 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +01009811 endif
9812 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +01009813
9814 " user must have changed fastbrowse to its fast setting, so remove
9815 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +01009816 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
9817" call Decho("remove AuNetrwEvent autcmd group")
9818 unlet s:netrw_events
9819 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009820 au!
9821 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +01009822 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +01009823 endif
9824
9825" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
9826endfun
9827
9828" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009829" s:LocalListing: does the job of "ls" for local directories {{{2
9830fun! s:LocalListing()
9831" call Dfunc("s:LocalListing()")
9832" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
9833" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
9834
9835" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist") |endif
9836" 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
9837" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9838
9839 " get the list of files contained in the current directory
9840 let dirname = b:netrw_curdir
9841 let dirnamelen = strlen(b:netrw_curdir)
9842 let filelist = glob(s:ComposePath(dirname,"*"),0,1)
9843 let filelist = filelist + glob(s:ComposePath(dirname,".*"),0,1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009844" call Decho("filelist=".string(filelist))
Bram Moolenaara6878372014-03-22 21:02:50 +01009845
9846 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
9847" call Decho("filelist=".string(filelist))
9848 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
9849 " include ../ in the glob() entry if its missing
9850" call Decho("forcibly including on \"..\"")
9851 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
9852" call Decho("filelist=".string(filelist))
9853 endif
9854
9855" call Decho("before while: dirname<".dirname.">")
9856" call Decho("before while: dirnamelen<".dirnamelen.">")
9857" call Decho("before while: filelist=".string(filelist))
9858
9859 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
9860 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
9861 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
9862" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy))
9863" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen)
9864 endif
9865" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")")
9866
9867 for filename in filelist
9868" call Decho(" ")
9869" call Decho("for filename in filelist: filename<".filename.">")
9870
9871 if getftype(filename) == "link"
9872 " indicate a symbolic link
9873" call Decho("indicate <".filename."> is a symbolic link with trailing @")
9874 let pfile= filename."@"
9875
9876 elseif getftype(filename) == "socket"
9877 " indicate a socket
9878" call Decho("indicate <".filename."> is a socket with trailing =")
9879 let pfile= filename."="
9880
9881 elseif getftype(filename) == "fifo"
9882 " indicate a fifo
9883" call Decho("indicate <".filename."> is a fifo with trailing |")
9884 let pfile= filename."|"
9885
9886 elseif isdirectory(filename)
9887 " indicate a directory
9888" call Decho("indicate <".filename."> is a directory with trailing /")
9889 let pfile= filename."/"
9890
9891 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(filename)
9892 if (has("win32") || has("win95") || has("win64") || has("win16"))
9893 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
9894 " indicate an executable
9895" call Decho("indicate <".filename."> is executable with trailing *")
9896 let pfile= filename."*"
9897 else
9898 " normal file
9899 let pfile= filename
9900 endif
9901 elseif executable(filename)
9902 " indicate an executable
9903" call Decho("indicate <".filename."> is executable with trailing *")
9904 let pfile= filename."*"
9905 else
9906 " normal file
9907 let pfile= filename
9908 endif
9909
9910 else
9911 " normal file
9912 let pfile= filename
9913 endif
9914" call Decho("pfile<".pfile."> (after *@/ appending)")
9915
9916 if pfile =~ '//$'
9917 let pfile= substitute(pfile,'//$','/','e')
9918" call Decho("change // to /: pfile<".pfile.">")
9919 endif
9920 let pfile= strpart(pfile,dirnamelen)
9921 let pfile= substitute(pfile,'^[/\\]','','e')
9922" call Decho("filename<".filename.">")
9923" call Decho("pfile <".pfile.">")
9924
9925 if w:netrw_liststyle == s:LONGLIST
9926 let sz = getfsize(filename)
9927 let fsz = strpart(" ",1,15-strlen(sz)).sz
9928 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
9929" call Decho("sz=".sz." fsz=".fsz)
9930 endif
9931
9932 if g:netrw_sort_by =~ "^t"
9933 " sort by time (handles time up to 1 quintillion seconds, US)
9934" call Decho("getftime(".filename.")=".getftime(filename))
9935 let t = getftime(filename)
9936 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937" call Decho("exe NetrwKeepj put ='".ft.'/'.filename."'")
Bram Moolenaara6878372014-03-22 21:02:50 +01009938 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009939 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +01009940
9941 elseif g:netrw_sort_by =~ "^s"
9942 " sort by size (handles file sizes up to 1 quintillion bytes, US)
9943" call Decho("getfsize(".filename.")=".getfsize(filename))
9944 let sz = getfsize(filename)
9945 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'")
Bram Moolenaara6878372014-03-22 21:02:50 +01009947 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +01009949
9950 else
9951 " sort by name
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952" call Decho("exe NetrwKeepj put ='".pfile."'")
9953 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +01009954 endif
9955 endfor
9956
9957 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 sil! NetrwKeepj g/^$/d
9959 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +01009960 call histdel("/",-1)
9961" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1))
9962 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9963
9964" call Dret("s:LocalListing")
9965endfun
9966
9967" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +01009968" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
9969fun! s:NetrwLocalExecute(cmd)
9970" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
9971 let ykeep= @@
9972 " sanity check
9973 if !executable(a:cmd)
9974 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
9975 let @@= ykeep
9976" call Dret("s:NetrwLocalExecute")
9977 return
9978 endif
9979
9980 let optargs= input(":!".a:cmd,"","file")
9981" call Decho("optargs<".optargs.">")
9982 let result= system(a:cmd.optargs)
Bram Moolenaara6878372014-03-22 21:02:50 +01009983" call Decho("result)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009984
9985 " strip any ansi escape sequences off
9986 let result = substitute(result,"\e\\[[0-9;]*m","","g")
9987
9988 " show user the result(s)
9989 echomsg result
9990 let @@= ykeep
9991
9992" call Dret("s:NetrwLocalExecute")
9993endfun
9994
9995" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009996" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +01009997fun! s:NetrwLocalRename(path) range
9998" call Dfunc("NetrwLocalRename(path<".a:path.">)")
9999
10000 " preparation for removing multiple files/directories
10001 let ykeep = @@
10002 let ctr = a:firstline
Bram Moolenaara6878372014-03-22 21:02:50 +010010003 let svpos = netrw#SavePosn()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010004
10005 " rename files given by the markfilelist
10006 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10007 for oldname in s:netrwmarkfilelist_{bufnr("%")}
10008" call Decho("oldname<".oldname.">")
10009 if exists("subfrom")
10010 let newname= substitute(oldname,subfrom,subto,'')
10011" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
10012 else
10013 call inputsave()
10014 let newname= input("Moving ".oldname." to : ",oldname)
10015 call inputrestore()
10016 if newname =~ '^s/'
10017 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10018 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10019" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">")
10020 let newname = substitute(oldname,subfrom,subto,'')
10021 endif
10022 endif
10023 call rename(oldname,newname)
10024 endfor
10025 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
10026
10027 else
10028
10029 " attempt to rename files/directories
10030 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010032
10033 " sanity checks
10034 if line(".") < w:netrw_bannercnt
10035 let ctr= ctr + 1
10036 continue
10037 endif
10038 let curword= s:NetrwGetWord()
10039 if curword == "./" || curword == "../"
10040 let ctr= ctr + 1
10041 continue
10042 endif
10043
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010044 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010045 let oldname= s:ComposePath(a:path,curword)
10046" call Decho("oldname<".oldname.">")
10047
10048 call inputsave()
10049 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10050 call inputrestore()
10051
10052 call rename(oldname,newname)
10053" call Decho("renaming <".oldname."> to <".newname.">")
10054
10055 let ctr= ctr + 1
10056 endwhile
10057 endif
10058
10059 " refresh the directory
10060" call Decho("refresh the directory listing")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010061 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
10062 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010063 let @@= ykeep
10064
10065" call Dret("NetrwLocalRename")
10066endfun
10067
10068" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010069" s:NetrwLocalRm: {{{2
10070fun! s:NetrwLocalRm(path) range
10071" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
10072" call Decho("firstline=".a:firstline." lastline=".a:lastline)
10073
10074 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010075 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010076 let ret = 0
10077 let all = 0
Bram Moolenaara6878372014-03-22 21:02:50 +010010078 let svpos = netrw#SavePosn()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010079
10080 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10081 " remove all marked files
10082" call Decho("remove all marked files")
10083 for fname in s:netrwmarkfilelist_{bufnr("%")}
10084 let ok= s:NetrwLocalRmFile(a:path,fname,all)
10085 if ok =~ 'q\%[uit]' || ok == "no"
10086 break
10087 elseif ok =~ 'a\%[ll]'
10088 let all= 1
10089 endif
10090 endfor
10091 call s:NetrwUnMarkFile(1)
10092
10093 else
10094 " remove (multiple) files and directories
10095" call Decho("remove files in range [".a:firstline.",".a:lastline."]")
10096
10097 let ctr = a:firstline
10098 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010099 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010100
10101 " sanity checks
10102 if line(".") < w:netrw_bannercnt
10103 let ctr= ctr + 1
10104 continue
10105 endif
10106 let curword= s:NetrwGetWord()
10107 if curword == "./" || curword == "../"
10108 let ctr= ctr + 1
10109 continue
10110 endif
10111 let ok= s:NetrwLocalRmFile(a:path,curword,all)
10112 if ok =~ 'q\%[uit]' || ok == "no"
10113 break
10114 elseif ok =~ 'a\%[ll]'
10115 let all= 1
10116 endif
10117 let ctr= ctr + 1
10118 endwhile
10119 endif
10120
10121 " refresh the directory
10122" call Decho("bufname<".bufname("%").">")
10123 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
10125 NetrwKeepj call netrw#RestorePosn(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010126 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010127 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010128
10129" call Dret("s:NetrwLocalRm")
10130endfun
10131
10132" ---------------------------------------------------------------------
10133" s:NetrwLocalRmFile: remove file fname given the path {{{2
10134" Give confirmation prompt unless all==1
10135fun! s:NetrwLocalRmFile(path,fname,all)
10136" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
10137
10138 let all= a:all
10139 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010140 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141 let rmfile= s:ComposePath(a:path,a:fname)
10142" call Decho("rmfile<".rmfile.">")
10143
10144 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10145 " attempt to remove file
10146" call Decho("attempt to remove file<".rmfile.">")
10147 if !all
10148 echohl Statement
10149 call inputsave()
10150 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10151 call inputrestore()
10152 echohl NONE
10153 if ok == ""
10154 let ok="no"
10155 endif
10156" call Decho("response: ok<".ok.">")
10157 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10158" call Decho("response: ok<".ok."> (after sub)")
10159 if ok =~ 'a\%[ll]'
10160 let all= 1
10161 endif
10162 endif
10163
10164 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010165 let ret= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010166" call Decho("errcode=".v:shell_error." ret=".ret)
10167 endif
10168
10169 else
10170 " attempt to remove directory
10171 if !all
10172 echohl Statement
10173 call inputsave()
10174 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10175 call inputrestore()
10176 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10177 if ok == ""
10178 let ok="no"
10179 endif
10180 if ok =~ 'a\%[ll]'
10181 let all= 1
10182 endif
10183 endif
10184 let rmfile= substitute(rmfile,'[\/]$','','e')
10185
10186 if all || ok =~ 'y\%[es]' || ok == ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010187" call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.shellescape(rmfile).')')
10188 call system(netrw#WinPath(g:netrw_localrmdir).' '.shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010189" call Decho("v:shell_error=".v:shell_error)
10190
10191 if v:shell_error != 0
10192" call Decho("2nd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +000010193 let errcode= s:NetrwDelete(rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010194" call Decho("errcode=".errcode)
10195
10196 if errcode != 0
10197 if has("unix")
10198" call Decho("3rd attempt to remove directory<".rmfile.">")
Bram Moolenaarc236c162008-07-13 17:41:49 +000010199 call system("rm ".shellescape(rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010200 if v:shell_error != 0 && !exists("g:netrw_quiet")
10201 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
10202 let ok="no"
10203 endif
10204 elseif !exists("g:netrw_quiet")
10205 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
10206 let ok="no"
10207 endif
10208 endif
10209 endif
10210 endif
10211 endif
10212
10213" call Dret("s:NetrwLocalRmFile ".ok)
10214 return ok
10215endfun
10216
10217" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010218" Support Functions: {{{1
10219
Bram Moolenaar488c6512005-08-11 20:09:58 +000010220" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010221" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10222" 0: marked file list of current buffer
10223" 1: marked file target
10224fun! netrw#Access(ilist)
10225 if a:ilist == 0
10226 if exists("s:netrwmarkfilelist_".bufnr('%'))
10227 return s:netrwmarkfilelist_{bufnr('%')}
10228 else
10229 return "no-list-buf#".bufnr('%')
10230 endif
10231 elseif a:ilist == 1
10232 return s:netrwmftgt
10233endfun
10234
10235" ------------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010236" netrw#RestorePosn: restores the cursor and file position as saved by netrw#SavePosn() {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +010010237fun! netrw#RestorePosn(...)
10238" 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))
10239 let eikeep= &ei
10240 setl ei=all
10241 if expand("%") == "NetrwMessage"
10242 if exists("s:winBeforeErr")
10243 exe s:winBeforeErr."wincmd w"
10244 endif
10245 endif
10246
10247 if a:0 > 0
10248 exe "keepj ".a:1
10249 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250" "call Decho("a:1 = ".((a:0 > 0)? a:1 : 'n/a'))
10251" "call Decho("liststyle = ".(exists("liststyle")? liststyle : 'n/a'). " w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'))
Bram Moolenaar13600302014-05-22 18:26:40 +020010252 if exists("liststyle") && exists("w:netrw_liststyle") && liststyle != w:netrw_liststyle
10253 let usesrch= 1
10254 else
10255 let usesrch= 0
10256 endif
10257
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258" "call Decho("winh = ".(exists("w:netrw_winh")? w:netrw_winh : -1))
10259" "call Decho("winw = ".(exists("w:netrw_winw")? w:netrw_winw : -1))
10260" "call Decho("cur winheight=".winheight(0)." winwidth=".winwidth(0))
10261" "call Decho("w:netrw_winfile = ".(exists("w:netrw_winfile")? w:netrw_winfile : 'n/a'))
Bram Moolenaara6878372014-03-22 21:02:50 +010010262
10263 " restore window
10264 if exists("w:netrw_winnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265" "call Decho("restore window: exe sil! ".w:netrw_winnr."wincmd w")
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 exe "sil! ".w:netrw_winnr."wincmd w"
10267 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268" if v:shell_error == 0
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 " as suggested by Bram M: redraw on no error
10270 " allows protocol error messages to remain visible
10271" redraw!
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010272" endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010273
10274 " restore top-of-screen line
10275 if exists("w:netrw_hline")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276" "call Decho("restore topofscreen: exe keepj norm! ".w:netrw_hline."G0z")
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 exe "keepj norm! ".w:netrw_hline."G0z\<CR>"
10278 endif
10279
10280 " restore position
Bram Moolenaar13600302014-05-22 18:26:40 +020010281 " when the window's height x width has changed, the line,col is no longer useful
10282 if w:netrw_winh == winheight(0) && w:netrw_winw == winwidth(0) && exists("w:netrw_line") && exists("w:netrw_col") && !usesrch
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010283" "call Decho("using posn: exe keepj norm! ".w:netrw_line."G0".w:netrw_col."|")
Bram Moolenaara6878372014-03-22 21:02:50 +010010284 exe "keepj norm! ".w:netrw_line."G0".w:netrw_col."\<bar>"
Bram Moolenaar13600302014-05-22 18:26:40 +020010285
10286 elseif exists("w:netrw_winfile")
10287 if !search('\<'.escape(w:netrw_winfile,g:netrw_fname_escape),'cw')
10288 if exists("w:netrw_bannercnt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289" "call Decho("using bannercnt: win#".winnr()." ".winheight(0)."x".winwidth(0)." w:netrw_winfile<".w:netrw_winfile.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010290 exe "keepj ".w:netrw_bannercnt
10291 norm! 0
10292 else
10293 " go to upper left corner
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294" "call Decho("goto ulc: win#".winnr()." ".winheight(0)."x".winwidth(0)." w:netrw_winfile<".w:netrw_winfile.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010295 keepj 1
10296 norm! 0
10297 endif
10298 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299" "call Decho("used search: w:netrw_winfile<".w:netrw_winfile.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010300 endif
10301
10302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303" "call Decho("goto ulc: win#".winnr()." ".winheight(0)."x".winwidth(0))
Bram Moolenaar13600302014-05-22 18:26:40 +020010304 keepj 1
10305 norm! 0
Bram Moolenaara6878372014-03-22 21:02:50 +010010306 endif
10307
10308 let &ei= eikeep
10309" call Dret("netrw#RestorePosn : line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
10310endfun
10311
10312" ---------------------------------------------------------------------
10313" netrw#RFC2396: converts %xx into characters {{{2
10314fun! netrw#RFC2396(fname)
10315" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
10316 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
10317" call Dret("netrw#RFC2396 ".fname)
10318 return fname
10319endfun
10320
10321" ---------------------------------------------------------------------
10322" netrw#SavePosn: saves position of cursor on screen {{{2
10323fun! netrw#SavePosn()
10324" call Dfunc("netrw#SavePosn() line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol())
10325 " Save current line and column
10326 let w:netrw_winnr= winnr()
10327 let w:netrw_line = line(".")
10328 let w:netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329" "call Decho("currently, win#".w:netrw_winnr." line#".w:netrw_line." col#".w:netrw_col)
Bram Moolenaara6878372014-03-22 21:02:50 +010010330
Bram Moolenaar13600302014-05-22 18:26:40 +020010331 " save filename under cursor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332" "call Decho("line#".line(".")." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'))
Bram Moolenaar13600302014-05-22 18:26:40 +020010333 if exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt && &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010334 let winfile = "|let w:netrw_winfile=\"".fnameescape(s:NetrwGetWord())."\""
Bram Moolenaar13600302014-05-22 18:26:40 +020010335 else
10336 let winfile= ""
10337 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010338" "call Decho("winfile<".winfile.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010339 if exists("w:netrw_liststyle")
10340 let liststyle = "|let liststyle=".w:netrw_liststyle
10341 else
10342 let liststyle= ""
10343 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344" "call Decho("liststyle=".liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +020010345
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 " Save top-of-screen line
10347 keepj norm! H0
10348 let w:netrw_hline= line(".")
10349
Bram Moolenaar13600302014-05-22 18:26:40 +020010350 " save up alternate position information
10351 " use this when window height x width has changed
10352 let w:netrw_winh = winheight(0)
10353 let w:netrw_winw = winwidth(0)
10354
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 " set up string holding position parameters
Bram Moolenaar13600302014-05-22 18:26:40 +020010356 let ret = "let w:netrw_winnr=".w:netrw_winnr."|let w:netrw_line=".w:netrw_line."|let w:netrw_col=".w:netrw_col."|let w:netrw_hline=".w:netrw_hline."|let w:netrw_winh=".w:netrw_winh."|let w:netrw_winw=".w:netrw_winw.liststyle.winfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010357
10358 keepj call netrw#RestorePosn()
10359" 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"))
10360 return ret
10361endfun
10362
10363" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010364" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10365fun! netrw#WinPath(path)
10366" call Dfunc("netrw#WinPath(path<".a:path.">)")
10367 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
10368 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010369 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010370 " remove trailing slash (Win95)
10371 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10372 " remove escaped spaces
10373 let path = substitute(path, '\ ', ' ', 'g')
10374 " convert slashes to backslashes
10375 let path = substitute(path, '/', '\', 'g')
10376 else
10377 let path= a:path
10378 endif
10379" call Dret("netrw#WinPath <".path.">")
10380 return path
10381endfun
10382
10383" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010384" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10385fun! s:ComposePath(base,subdir)
10386" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10387
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010388 if has("amiga")
Bram Moolenaarc236c162008-07-13 17:41:49 +000010389" call Decho("amiga")
Bram Moolenaar5c736222010-01-06 20:54:52 +010010390 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010391 if ec != '/' && ec != ':'
10392 let ret = a:base . "/" . a:subdir
10393 else
10394 let ret = a:base . a:subdir
10395 endif
10396
10397 elseif a:subdir =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
10398" call Decho("windows")
10399 let ret= a:subdir
10400
Bram Moolenaar5c736222010-01-06 20:54:52 +010010401 elseif a:base =~ '^\a:[/\\][^/\\]' && (has("win32") || has("win95") || has("win64") || has("win16"))
10402" call Decho("windows")
10403 if a:base =~ '[/\\]$'
10404 let ret= a:base.a:subdir
10405 else
10406 let ret= a:base."/".a:subdir
10407 endif
10408
Bram Moolenaarc236c162008-07-13 17:41:49 +000010409 elseif a:base =~ '^\a\+://'
10410" call Decho("remote linux/macos")
10411 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10412 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10413 if a:subdir == '../'
10414 if curpath =~ '[^/]/[^/]\+/$'
10415 let curpath= substitute(curpath,'[^/]\+/$','','')
10416 else
10417 let curpath=""
10418 endif
10419 let ret= urlbase.curpath
10420 else
10421 let ret= urlbase.curpath.a:subdir
10422 endif
10423" call Decho("urlbase<".urlbase.">")
10424" call Decho("curpath<".curpath.">")
10425" call Decho("ret<".ret.">")
10426
10427 else
10428" call Decho("local linux/macos")
10429 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10430 if a:base =~ '^//'
10431 " keeping initial '//' for the benefit of network share listing support
10432 let ret= '/'.ret
10433 endif
10434 let ret= simplify(ret)
10435 endif
10436
10437" call Dret("s:ComposePath ".ret)
10438 return ret
10439endfun
10440
10441" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10443" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10444fun! s:DeleteBookmark(fname)
10445" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10446 call s:MergeBookmarks()
10447
10448 if exists("g:netrw_bookmarklist")
10449 let indx= index(g:netrw_bookmarklist,a:fname)
10450 if indx == -1
10451 let indx= 0
10452 while indx < len(g:netrw_bookmarklist)
10453 if g:netrw_bookmarklist[indx] =~ a:fname
10454 call remove(g:netrw_bookmarklist,indx)
10455 let indx= indx - 1
10456 endif
10457 let indx= indx + 1
10458 endwhile
10459 else
10460 " remove exact match
10461 call remove(g:netrw_bookmarklist,indx)
10462 endif
10463 endif
10464
10465" call Dret("s:DeleteBookmark")
10466endfun
10467
10468" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010469" s:FileReadable: o/s independent filereadable {{{2
10470fun! s:FileReadable(fname)
10471" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10472
10473 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +010010474 let ret= filereadable(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/',''))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010475 else
10476 let ret= filereadable(a:fname)
10477 endif
10478
10479" call Dret("s:FileReadable ".ret)
10480 return ret
10481endfun
10482
10483" ---------------------------------------------------------------------
10484" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10485" Places correct suffix on end of temporary filename,
10486" using the suffix provided with fname
10487fun! s:GetTempfile(fname)
10488" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10489
10490 if !exists("b:netrw_tmpfile")
10491 " get a brand new temporary filename
10492 let tmpfile= tempname()
10493" call Decho("tmpfile<".tmpfile."> : from tempname()")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494
Bram Moolenaarc236c162008-07-13 17:41:49 +000010495 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010496" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497
Bram Moolenaar9964e462007-05-05 17:54:07 +000010498 " sanity check -- does the temporary file's directory exist?
10499 if !isdirectory(substitute(tmpfile,'[^/]\+$','','e'))
Bram Moolenaara6878372014-03-22 21:02:50 +010010500" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010501 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010502" call Dret("s:GetTempfile getcwd<".getcwd().">")
10503 return ""
10504 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505
Bram Moolenaar9964e462007-05-05 17:54:07 +000010506 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010507 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaar9964e462007-05-05 17:54:07 +000010508" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509
Bram Moolenaar9964e462007-05-05 17:54:07 +000010510 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010512 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010513 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 if !exists("+shellslash") || !&ssl
10515 let tmpfile = substitute(tmpfile,'/','\','g')
10516 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010517 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010519 endif
10520 let b:netrw_tmpfile= tmpfile
10521" call Decho("o/s dependent fixed tempname<".tmpfile.">")
10522 else
10523 " re-use temporary filename
10524 let tmpfile= b:netrw_tmpfile
10525" call Decho("tmpfile<".tmpfile."> re-using")
10526 endif
10527
10528 " use fname's suffix for the temporary file
10529 if a:fname != ""
10530 if a:fname =~ '\.[^./]\+$'
10531" call Decho("using fname<".a:fname.">'s suffix")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010532 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010533 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010534 elseif a:fname =~ '.txz$'
10535 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010536 else
10537 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
10538 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010539" call Decho("suffix<".suffix.">")
10540 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
10541" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)")
10542 let tmpfile .= suffix
10543" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">")
10544 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
10545 endif
10546 endif
10547
Bram Moolenaara6878372014-03-22 21:02:50 +010010548" 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 +000010549" call Dret("s:GetTempfile <".tmpfile.">")
10550 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010551endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000010552
10553" ---------------------------------------------------------------------
10554" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000010555" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000010556fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010558 if s:user == ""
10559 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
10560 else
10561 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
10562 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010563 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010564 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010565 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010566 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010567 else
10568 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
10569 endif
10570" call Dret("s:MakeSshCmd <".sshcmd.">")
10571 return sshcmd
10572endfun
10573
10574" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010575" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
10576fun! s:MakeBookmark(fname)
10577" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
10578
10579 if !exists("g:netrw_bookmarklist")
10580 let g:netrw_bookmarklist= []
10581 endif
10582
10583 if index(g:netrw_bookmarklist,a:fname) == -1
10584 " curdir not currently in g:netrw_bookmarklist, so include it
10585 if isdirectory(a:fname) && a:fname !~ '/$'
10586 call add(g:netrw_bookmarklist,a:fname.'/')
10587 elseif a:fname !~ '/'
10588 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
10589 else
10590 call add(g:netrw_bookmarklist,a:fname)
10591 endif
10592 call sort(g:netrw_bookmarklist)
10593 endif
10594
10595" call Dret("s:MakeBookmark")
10596endfun
10597
10598" ---------------------------------------------------------------------
10599" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
10600fun! s:MergeBookmarks()
10601" call Dfunc("s:MergeBookmarks()")
10602 " get bookmarks from .netrwbook file
10603 let savefile= s:NetrwHome()."/.netrwbook"
10604 if filereadable(savefile)
10605" call Decho("merge bookmarks (active and file)")
10606 NetrwKeepj call s:NetrwBookHistSave()
10607" call Decho("bookmark delete savefile<".savefile.">")
10608 NetrwKeepj call delete(savefile)
10609 endif
10610" call Dret("s:MergeBookmarks")
10611endfun
10612
10613" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010614" s:NetrwBMShow: {{{2
10615fun! s:NetrwBMShow()
10616" call Dfunc("s:NetrwBMShow()")
10617 redir => bmshowraw
10618 menu
10619 redir END
10620 let bmshowlist = split(bmshowraw,'\n')
10621 if bmshowlist != []
10622 let bmshowfuncs= filter(bmshowlist,'v:val =~ "<SNR>\\d\\+_BMShow()"')
10623 if bmshowfuncs != []
10624 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
10625 if bmshowfunc =~ '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010626 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000010627 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000010630" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
10631endfun
10632
10633" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020010634" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
10635fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010636 if !exists("w:netrw_liststyle")
10637 let w:netrw_liststyle= g:netrw_liststyle
10638 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020010639" 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 +020010640
10641 if &ft != "netrw"
10642 " if the current window isn't a netrw directory listing window, then use user cursorline/column
10643 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaar15146672011-10-20 22:22:38 +020010644" call Decho("case ft!=netrw: use user cul,cuc")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010645 let &l:cursorline = s:netrw_usercul
10646 let &l:cursorcolumn = s:netrw_usercuc
10647
10648 elseif g:netrw_cursor == 4
10649 " all styles: cursorline, cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +020010650" call Decho("case g:netrw_cursor==4: setl cul cuc")
10651 setl cursorline
10652 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020010653
10654 elseif g:netrw_cursor == 3
10655 " thin-long-tree: cursorline, user's cursorcolumn
10656 " wide : cursorline, cursorcolumn
10657 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +020010658" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc")
Bram Moolenaar15146672011-10-20 22:22:38 +020010659 setl cursorline
10660 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020010661 else
Bram Moolenaarff034192013-04-24 18:51:19 +020010662" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)")
Bram Moolenaar15146672011-10-20 22:22:38 +020010663 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010664 let &l:cursorcolumn = s:netrw_usercuc
10665 endif
10666
10667 elseif g:netrw_cursor == 2
10668 " thin-long-tree: cursorline, user's cursorcolumn
10669 " wide : cursorline, user's cursorcolumn
Bram Moolenaarff034192013-04-24 18:51:19 +020010670" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010671 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020010672 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010673
10674 elseif g:netrw_cursor == 1
10675 " thin-long-tree: user's cursorline, user's cursorcolumn
10676 " wide : cursorline, user's cursorcolumn
10677 let &l:cursorcolumn = s:netrw_usercuc
10678 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaarff034192013-04-24 18:51:19 +020010679" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010680 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020010681 else
Bram Moolenaar15146672011-10-20 22:22:38 +020010682" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010683 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010684 endif
10685
10686 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020010687 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaar15146672011-10-20 22:22:38 +020010688" call Decho("default: (use user's cul,cuc)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010689 let &l:cursorline = s:netrw_usercul
10690 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010691 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020010692
10693" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010694endfun
10695
10696" ---------------------------------------------------------------------
10697" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
10698fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010010699" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020010700 if exists("s:netrw_usercul")
10701 let &l:cursorline = s:netrw_usercul
10702 endif
10703 if exists("s:netrw_usercuc")
10704 let &l:cursorcolumn = s:netrw_usercuc
10705 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010706" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
10707endfun
10708
10709" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010710" s:NetrwDelete: Deletes a file. {{{2
10711" Uses Steve Hall's idea to insure that Windows paths stay
10712" acceptable. No effect on Unix paths.
10713" Examples of use: let result= s:NetrwDelete(path)
10714fun! s:NetrwDelete(path)
10715" call Dfunc("s:NetrwDelete(path<".a:path.">)")
10716
Bram Moolenaar5c736222010-01-06 20:54:52 +010010717 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010718 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
10719 if exists("+shellslash")
10720 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020010721 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000010722 let result = delete(path)
10723 let &shellslash = sskeep
10724 else
10725" call Decho("exe let result= ".a:cmd."('".path."')")
10726 let result= delete(path)
10727 endif
10728 else
10729" call Decho("let result= delete(".path.")")
10730 let result= delete(path)
10731 endif
10732 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010733 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010734 endif
10735
10736" call Dret("s:NetrwDelete ".result)
10737 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000010738endfun
10739
10740" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010741" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010010742fun! s:NetrwEnew(...)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010743" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010744" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010745
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746 " grab a function-local-variable copy of buffer variables
Bram Moolenaara6878372014-03-22 21:02:50 +010010747" call Decho("make function-local copy of netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010748 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
10749 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
10750 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
10751 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
10752 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
10753 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
10754 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
10755 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
10756 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
10757 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
10758 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
10759 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
10760 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
10761 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
10762 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
10763 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
10764
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010765 NetrwKeepj call s:NetrwOptionRestore("w:")
10766" call Decho("generate a buffer with NetrwKeepj keepalt enew!")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010767 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010768 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010769 let &l:diff= netrw_keepdiff
Bram Moolenaara6878372014-03-22 21:02:50 +010010770" call Decho("bufnr($)=".bufnr("$")." winnr($)=".winnr("$"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010771 NetrwKeepj call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010772
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara6878372014-03-22 21:02:50 +010010774" call Decho("copy function-local variables back to buffer netrw variables")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010775 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
10776 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
10777 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
10778 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
10779 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
10780 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
10781 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
10782 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
10783 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
10784 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
10785 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
10786 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
10787 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
10788 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
10789 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
10790 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
10791
Bram Moolenaar5c736222010-01-06 20:54:52 +010010792 if a:0 > 0
10793 let b:netrw_curdir= a:1
10794 if b:netrw_curdir =~ '/$'
10795 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10796 file NetrwTreeListing
Bram Moolenaara6878372014-03-22 21:02:50 +010010797 setl bt=nowrite noswf bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020010798 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
10799 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010010800 else
Bram Moolenaar00a927d2010-05-14 23:24:24 +020010801 exe "sil! keepalt file ".fnameescape(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010802 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010803 endif
10804 endif
10805
Bram Moolenaar8d043172014-01-23 14:24:41 +010010806" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010807endfun
10808
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010809" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010810" s:NetrwExe: executes a string using "!" {{{2
10811fun! s:NetrwExe(cmd)
10812" call Dfunc("s:NetrwExe(a:cmd)")
10813 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
10814 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
10815 set shell& shellcmdflag& shellxquote& shellxescape&
10816 set shellquote& shellpipe& shellredir& shellslash&
10817 exe a:cmd
10818 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
10819 else
10820 exe a:cmd
10821 endif
10822" call Dret("s:NetrwExe")
10823endfun
10824
10825" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010826" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
10827fun! s:NetrwInsureWinVars()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010829 if !exists("w:netrw_liststyle")
10830 let curbuf = bufnr("%")
10831 let curwin = winnr()
10832 let iwin = 1
10833 while iwin <= winnr("$")
10834 exe iwin."wincmd w"
10835 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
10836 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
10837 let winvars= w:
10838 break
10839 endif
10840 let iwin= iwin + 1
10841 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020010842 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010843 if exists("winvars")
10844" call Decho("copying w#".iwin." window variables to w#".curwin)
10845 for k in keys(winvars)
10846 let w:{k}= winvars[k]
10847 endfor
10848 endif
10849 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010851endfun
10852
Bram Moolenaara6878372014-03-22 21:02:50 +010010853" ---------------------------------------------------------------------
10854" s:NetrwLcd: handles changing the (local) directory {{{2
10855fun! s:NetrwLcd(newdir)
10856" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
10857
10858 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010859 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010010860 catch /^Vim\%((\a\+)\)\=:E344/
10861 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
10862 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
10863 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
10864 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
10865 " forward slashes by earlier code; so check for both.
10866 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
10867 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
10868 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010869 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010010870 endif
10871 endif
10872 catch /^Vim\%((\a\+)\)\=:E472/
10873 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
10874 if exists("w:netrw_prvdir")
10875 let a:newdir= w:netrw_prvdir
10876 else
10877 call s:NetrwOptionRestore("w:")
10878" call Decho("setl noma nomod nowrap")
Bram Moolenaar13600302014-05-22 18:26:40 +020010879 exe "setl ".g:netrw_bufsettings
Bram Moolenaara6878372014-03-22 21:02:50 +010010880" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
10881 let a:newdir= dirname
10882" call Dret("s:NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
10883 return
10884 endif
10885 endtry
10886
10887" call Dret("s:NetrwLcd")
10888endfun
10889
Bram Moolenaar9964e462007-05-05 17:54:07 +000010890" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010891" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
10892" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
10893fun! s:NetrwSaveWordPosn()
10894" call Dfunc("NetrwSaveWordPosn()")
10895 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
10896" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
10897endfun
10898
10899" ---------------------------------------------------------------------
10900" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
10901" changed sorting, etc. Also see s:NetrwSaveWordPosn().
10902fun! s:NetrwRestoreWordPosn()
10903" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020010904 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010905" call Dret("NetrwRestoreWordPosn")
10906endfun
10907
10908" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010909" s:RestoreBufVars: {{{2
10910fun! s:RestoreBufVars()
10911" call Dfunc("s:RestoreBufVars()")
10912
10913 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
10914 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
10915 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
10916 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
10917 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
10918 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
10919
10920" call Dret("s:RestoreBufVars")
10921endfun
10922
10923" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010924" s:RemotePathAnalysis: {{{2
10925fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020010926" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000010927
Bram Moolenaara6878372014-03-22 21:02:50 +010010928 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010010929 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010930 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010010931 let s:user = substitute(a:dirname,dirpat,'\3','')
10932 let s:machine = substitute(a:dirname,dirpat,'\4','')
10933 let s:port = substitute(a:dirname,dirpat,'\5','')
10934 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020010935 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010010936 if s:machine =~ '@'
10937 let dirpat = '^\(.*\)@\(.\{-}\)$'
10938 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
10939 let s:machine = substitute(s:machine,dirpat,'\2','')
10940 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010941
10942" call Decho("set up s:method <".s:method .">")
10943" call Decho("set up s:user <".s:user .">")
10944" call Decho("set up s:machine<".s:machine.">")
10945" call Decho("set up s:port <".s:port.">")
10946" call Decho("set up s:path <".s:path .">")
10947" call Decho("set up s:fname <".s:fname .">")
10948
10949" call Dret("s:RemotePathAnalysis")
10950endfun
10951
10952" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010953" s:RemoteSystem: runs a command on a remote host using ssh {{{2
10954" Returns status
10955" Runs system() on
10956" [cd REMOTEDIRPATH;] a:cmd
10957" Note that it doesn't do shellescape(a:cmd)!
10958fun! s:RemoteSystem(cmd)
10959" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
10960 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010961 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010962 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010963 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000010964 else
10965 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
10966 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
10967 if remotedir != ""
10968 let cmd= cmd.' cd '.shellescape(remotedir).";"
10969 else
10970 let cmd= cmd.' '
10971 endif
10972 let cmd= cmd.a:cmd
10973" call Decho("call system(".cmd.")")
10974 let ret= system(cmd)
10975 endif
10976" call Dret("s:RemoteSystem ".ret)
10977 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000010978endfun
10979
10980" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010982fun! s:RestoreWinVars()
10983" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000010984 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010985 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
10986 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
10987 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
10988 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
10989 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
10990 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
10991 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
10992 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
10993 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
10994 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
10995 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
10996 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000010997 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
10998 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010999 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11000 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11001 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11002" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011003endfun
11004
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011005" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011006" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11007"
11008" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11009" is true) and a command, :Rexplore, which call this function.
11010"
11011" s:nbcd_curpos_{bufnr('%')} is set up by s:NetrwBrowseChgDir()
11012fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011013 if exists("s:netrwdrag")
11014 return
11015 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011016" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir.">")
Bram Moolenaara6878372014-03-22 21:02:50 +010011017" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">")
11018
11019 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011020 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011021" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011022 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011023 unlet w:netrw_rexfile
11024" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011025 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011026" else " Decho
11027" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"))
11028" call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">")
Bram Moolenaar15146672011-10-20 22:22:38 +020011029 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011030
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011031 " ---------------------------
11032 " :Rex issued while in a file
11033 " ---------------------------
11034
Bram Moolenaara6878372014-03-22 21:02:50 +010011035 " record current file so :Rex can return to it from netrw
11036 let w:netrw_rexfile= expand("%")
11037
11038 if !exists("w:netrw_rexlocal")
11039" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft.")")
11040 return
11041 endif
11042" 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 +020011043 if w:netrw_rexlocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011044 if g:netrw_keepj =~ "keepj"
11045 keepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
11046 else
11047 call netrw#LocalBrowseCheck(w:netrw_rexdir)
11048 endif
11049 elseif g:netrw_keepj =~ "keepj"
Bram Moolenaaradc21822011-04-01 18:03:16 +020011050 keepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011051 else
11052 call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011053 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011054 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011055 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011056 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011057 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011058" call Decho("restore posn, then unlet s:rexposn_".bufnr('%'))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011059 if g:netrw_keepj =~ "keepj"
11060 keepj call netrw#RestorePosn(s:rexposn_{bufnr('%')})
11061 else
11062 call netrw#RestorePosn(s:rexposn_{bufnr('%')})
11063 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011064 unlet s:rexposn_{bufnr('%')}
11065 else
Bram Moolenaara6878372014-03-22 21:02:50 +010011066" call Decho("s:rexposn_".bufnr('%')." doesn't exist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011067 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011068
Bram Moolenaar5c736222010-01-06 20:54:52 +010011069 if exists("s:explore_match")
11070 exe "2match netrwMarkFile /".s:explore_match."/"
11071 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011072
11073" 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)
11074" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011075endfun
11076
11077" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011078" s:SaveBufVars: save selected b: variables to s: variables {{{2
11079" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011080fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011081" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011082
11083 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11084 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11085 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11086 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11087 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11088 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11089
11090" call Dret("s:SaveBufVars")
11091endfun
11092
11093" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011094" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011095fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011096" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011097 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11098 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11099 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11100 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11101 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11102 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11103 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11104 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11105 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11106 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11107 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11108 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11109 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11110 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11111 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11112 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11113 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11114 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11115" call Dret("s:SaveWinVars")
11116endfun
11117
11118" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011119" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011120" To allow separate windows to have their own activities, such as
11121" Explore **/pattern, several variables have been made window-oriented.
11122" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011123" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011124" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011125fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011126" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011127 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11128 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11129 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11130 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11131 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11132 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11133 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11134 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11135 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11136 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11137" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011138endfun
11139
11140" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011141" s:SetRexDir: set directory for :Rexplore {{{2
11142fun! s:SetRexDir(islocal,dirname)
11143" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011144 let w:netrw_rexdir = a:dirname
11145 let w:netrw_rexlocal = a:islocal
Bram Moolenaar97d62492012-11-15 21:28:22 +010011146" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011147endfun
11148
11149" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011150" s:ShowLink: used to modify thin and tree listings to show links {{{2
11151fun! s:ShowLink()
11152" " call Dfunc("s:ShowLink()")
11153" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
11154" " call Decho(printf("line#%4d: %s",line("."),getline(".")))
11155 if exists("b:netrw_curdir")
11156 norm! $?\a
11157 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
11158 let resname = resolve(fname)
11159 if resname =~ '^\M'.b:netrw_curdir
11160 let dirlen = strlen(b:netrw_curdir)
11161 let resname = strpart(resname,dirlen+1)
11162" " call Decho("resname<".resname."> (b:netrw_curdir elided)")
11163" " else " Decho
11164" " call Decho("resname<".fname.">")
11165 endif
11166 let modline = getline(".")."\t --> ".resname
11167" " call Decho("fname <".fname.">")
11168" " call Decho("modline<".modline.">")
11169 setl noro ma
11170 call setline(".",modline)
11171 setl ro noma nomod
11172 endif
11173" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
11174endfun
11175
11176" ---------------------------------------------------------------------
11177" s:ShowStyle: {{{2
11178fun! s:ShowStyle()
11179 if !exists("w:netrw_liststyle")
11180 let liststyle= g:netrw_liststyle
11181 else
11182 let liststyle= w:netrw_liststyle
11183 endif
11184 if liststyle == s:THINLIST
11185 return s:THINLIST.":thin"
11186 elseif liststyle == s:LONGLIST
11187 return s:LONGLIST.":long"
11188 elseif liststyle == s:WIDELIST
11189 return s:WIDELIST.":wide"
11190 elseif liststyle == s:TREELIST
11191 return s:TREELIST.":tree"
11192 else
11193 return 'n/a'
11194 endif
11195endfun
11196
11197" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011198" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11199" Solution from Nicolai Weibull, vim docs (:help strlen()),
11200" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011201fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011202" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11203
11204 if v:version >= 703 && exists("*strdisplaywidth")
11205 let ret= strdisplaywidth(a:x)
11206
11207 elseif type(g:Align_xstrlen) == 1
11208 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11209 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
11210
11211 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011212 " number of codepoints (Latin a + combining circumflex is two codepoints)
11213 " (comment from TM, solution from NW)
11214 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011215
11216 elseif g:Align_xstrlen == 2
11217 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011218 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11219 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011220 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
11221
11222 elseif g:Align_xstrlen == 3
11223 " virtual length (counting, for instance, tabs as anything between 1 and
11224 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011225 " preceded by lam, one otherwise, etc.)
11226 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011227 let modkeep= &l:mod
11228 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011229 call setline(line("."),a:x)
11230 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011231 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011232 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011233 let &l:mod= modkeep
11234
Bram Moolenaar446cb832008-06-24 21:56:24 +000011235 else
11236 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011237 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011238 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011239" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011240 return ret
11241endfun
11242
11243" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011244" s:TreeListMove: {{{2
11245fun! s:TreeListMove(dir)
11246" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
11247 let curline = getline('.')
11248 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11249 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11250 let curindent= substitute(curline,'^\([| ]*\).\{-}$','\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011251 let indentm1 = substitute(curindent,'^'.s:treedepthstring.' ','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011252" call Decho("prvline <".prvline."> #".line(".")-1)
11253" call Decho("curline <".curline."> #".line("."))
11254" call Decho("nxtline <".nxtline."> #".line(".")+1)
11255" call Decho("curindent<".curindent.">")
11256" call Decho("indentm1 <".indentm1.">")
11257
11258 if curline !~ '/$'
11259" call Decho('regfile')
11260 if a:dir == '[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011261 NetrwKeepj norm! 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011262 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000011263" call Decho("regfile srch back: ".nl)
11264 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011265 NetrwKeepj norm! $
Bram Moolenaar8d043172014-01-23 14:24:41 +010011266 let nl = search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from regular file
Bram Moolenaar446cb832008-06-24 21:56:24 +000011267" call Decho("regfile srch fwd: ".nl)
11268 endif
11269
11270 elseif a:dir == '[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011271 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000011272 let curline= line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010011273 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','bWe') " search backwards From directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000011274" call Decho("dir srch back ind: ".nl)
11275 if nl != 0
11276 if line(".") == curline-1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011277 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','bWe') " search backwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011278" call Decho("dir srch back ind-1: ".nl)
11279 endif
11280 endif
11281
11282 elseif a:dir == ']' && nxtline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011283 NetrwKeepj norm! $
Bram Moolenaar446cb832008-06-24 21:56:24 +000011284 let curline = line(".")
Bram Moolenaar8d043172014-01-23 14:24:41 +010011285 let nl = search('^'.curindent.'[^'.s:treedepthstring.']','We') " search forwards from directory, same indentation
Bram Moolenaar446cb832008-06-24 21:56:24 +000011286" call Decho("dir srch fwd ind: ".nl)
11287 if nl != 0
11288 if line(".") == curline+1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011289 let nl= search('^'.indentm1.'[^'.s:treedepthstring.']','We') " search forwards from directory, indentation - 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011290" call Decho("dir srch fwd ind-1: ".nl)
11291 endif
11292 endif
11293
11294 endif
11295
11296" call Dret("s:TreeListMove")
11297endfun
11298
11299" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011300" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11301" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11302" can't be called except via emenu. But due to locale, that menu line may not be called
11303" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11304fun! s:UpdateBuffersMenu()
11305" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011306 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011307 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011308 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011309 catch /^Vim\%((\a\+)\)\=:E/
11310 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011311 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011312 endtry
11313 endif
11314" call Dret("s:UpdateBuffersMenu")
11315endfun
11316
11317" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011318" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011319" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011320fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011321" call Dfunc("s:UseBufWinVars()")
11322 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011323 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11324 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11325 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11326 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11327 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11328 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11329 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11330 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11331 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 +000011332" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011333endfun
11334
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011335" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011336" Settings Restoration: {{{1
Bram Moolenaar83bab712005-08-01 21:58:57 +000011337let &cpo= s:keepcpo
11338unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011339
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340" ------------------------------------------------------------------------
Bram Moolenaar83bab712005-08-01 21:58:57 +000011341" Modelines: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342" vim:ts=8 fdm=marker