blob: f4cc89e4748e6ac7e61593de90c74b5b4e954ab1 [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 Moolenaar29634562020-01-09 21:46:04 +01003" Date: Jan 07, 2020
4" Version: 168
5" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007" Copyright: Copyright (C) 2016 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 Moolenaar91359012019-11-30 17:57:03 +010016"
17" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
18" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
19"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020020"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000021"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000022" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000023" (James 1:22 RSV)
24" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000025" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000026if &cp || exists("g:loaded_netrw")
27 finish
28endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020029
30" Check that vim has patches that netrw requires.
31" Patches needed for v7.4: 1557, and 213.
32" (netrw will benefit from vim's having patch#656, too)
33let s:needspatches=[1557,213]
34if exists("s:needspatches")
35 for ptch in s:needspatches
36 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
37 if !exists("s:needpatch{ptch}")
38 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
39 endif
40 let s:needpatch{ptch}= 1
41 finish
42 endif
43 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020044endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020045
Bram Moolenaar29634562020-01-09 21:46:04 +010046let g:loaded_netrw = "v168"
Bram Moolenaar9964e462007-05-05 17:54:07 +000047if !exists("s:NOTE")
48 let s:NOTE = 0
49 let s:WARNING = 1
50 let s:ERROR = 2
51endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000052
Bram Moolenaar1afcace2005-11-25 19:54:28 +000053let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010054setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020055"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010056"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010057"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000059" ======================
60" Netrw Variables: {{{1
61" ======================
62
Bram Moolenaar071d4272004-06-13 20:20:40 +000063" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020064" netrw#ErrorMsg: {{{2
65" 0=note = s:NOTE
66" 1=warning = s:WARNING
67" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010068" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
69" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
70" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010071" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020072fun! netrw#ErrorMsg(level,msg,errnum)
73" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
74
75 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020076" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020077 return
78 endif
79
80 if a:level == 1
81 let level= "**warning** (netrw) "
82 elseif a:level == 2
83 let level= "**error** (netrw) "
84 else
85 let level= "**note** (netrw) "
86 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010087" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088
89 if g:netrw_use_errorwindow
90 " (default) netrw creates a one-line window to show error/warning
91 " messages (reliably displayed)
92
Bram Moolenaare0fa3742016-02-20 15:47:01 +010093 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +020094 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010095" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096
97 " getting messages out reliably is just plain difficult!
98 " This attempt splits the current window, creating a one line window.
99 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100100" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200101 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100102" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100104 if type(a:msg) == 3
105 for msg in a:msg
106 NetrwKeepj call setline(line("$")+1,level.msg)
107 endfor
108 else
109 NetrwKeepj call setline(line("$")+1,level.a:msg)
110 endif
111 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100113" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114 bo 1split
115 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200116 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100118 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100119" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100121 if type(a:msg) == 3
122 for msg in a:msg
123 NetrwKeepj call setline(line("$")+1,level.msg)
124 endfor
125 else
126 NetrwKeepj call setline(line("$"),level.a:msg)
127 endif
128 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 if &fo !~ '[ta]'
132 syn clear
133 syn match netrwMesgNote "^\*\*note\*\*"
134 syn match netrwMesgWarning "^\*\*warning\*\*"
135 syn match netrwMesgError "^\*\*error\*\*"
136 hi link netrwMesgWarning WarningMsg
137 hi link netrwMesgError Error
138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200140 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141
142 else
143 " (optional) netrw will show messages using echomsg. Even if the
144 " message doesn't appear, at least it'll be recallable via :messages
145" redraw!
146 if a:level == s:WARNING
147 echohl WarningMsg
148 elseif a:level == s:ERROR
149 echohl Error
150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100151
152 if type(a:msg) == 3
153 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100154 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100155 endfor
156 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100157 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100158 endif
159
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100160" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161 echohl None
162 endif
163
164" call Dret("netrw#ErrorMsg")
165endfun
166
167" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100168" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100169" Loosely, varname = value.
170fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100172 if !exists(a:varname)
173 if type(a:value) == 0
174 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200175 elseif type(a:value) == 1 && a:value =~ '^[{[]'
176 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100177 elseif type(a:value) == 1
178 exe "let ".a:varname."="."'".a:value."'"
179 else
180 exe "let ".a:varname."=".a:value
181 endif
182 endif
183endfun
184
185" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000186" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200187call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000188if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 call s:NetrwInit("s:THINLIST",0)
190 call s:NetrwInit("s:LONGLIST",1)
191 call s:NetrwInit("s:WIDELIST",2)
192 call s:NetrwInit("s:TREELIST",3)
193 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000194endif
195
196" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200197" Default option values: {{{2
198let g:netrw_localcopycmdopt = ""
199let g:netrw_localcopydircmdopt = ""
200let g:netrw_localmkdiropt = ""
201let g:netrw_localmovecmdopt = ""
202let g:netrw_localrmdiropt = ""
203
204" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000205" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200206call s:NetrwInit("g:netrw_use_errorwindow",1)
207
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000208if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000210 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 elseif executable("curl")
212 let g:netrw_dav_cmd = "curl"
213 else
214 let g:netrw_dav_cmd = ""
215 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000217if !exists("g:netrw_fetch_cmd")
218 if executable("fetch")
219 let g:netrw_fetch_cmd = "fetch -o"
220 else
221 let g:netrw_fetch_cmd = ""
222 endif
223endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100224if !exists("g:netrw_file_cmd")
225 if executable("elinks")
226 call s:NetrwInit("g:netrw_file_cmd","elinks")
227 elseif executable("links")
228 call s:NetrwInit("g:netrw_file_cmd","links")
229 endif
230endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000231if !exists("g:netrw_ftp_cmd")
232 let g:netrw_ftp_cmd = "ftp"
233endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200234let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200235if !exists("g:netrw_ftp_options")
236 let g:netrw_ftp_options= "-i -n"
237endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000238if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100239 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100240 let g:netrw_http_cmd = "wget"
241 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100242 elseif executable("curl")
243 let g:netrw_http_cmd = "curl"
244 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200245 elseif executable("elinks")
246 let g:netrw_http_cmd = "elinks"
247 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000248 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249 let g:netrw_http_cmd = "fetch"
250 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200251 elseif executable("links")
252 let g:netrw_http_cmd = "links"
253 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000254 else
255 let g:netrw_http_cmd = ""
256 endif
257endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100258call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100259call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
261call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200262call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200263if !exists("g:netrw_scp_cmd")
264 if executable("scp")
265 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
266 elseif executable("pscp")
267 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
268 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
269 else
270 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
271 endif
272 else
273 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
274 endif
275endif
276
Bram Moolenaar5c736222010-01-06 20:54:52 +0100277call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
278call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000279
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000280if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000281 \ && exists("g:netrw_use_nt_rcp")
282 \ && g:netrw_use_nt_rcp
283 \ && executable( $SystemRoot .'/system32/rcp.exe')
284 let s:netrw_has_nt_rcp = 1
285 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000286else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000287 let s:netrw_has_nt_rcp = 0
288 let s:netrw_rcpmode = ''
289endif
290
291" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000292" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000293" Cygwin Detection ------- {{{3
294if !exists("g:netrw_cygwin")
295 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100296 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000297 let g:netrw_cygwin= 1
298 else
299 let g:netrw_cygwin= 0
300 endif
301 else
302 let g:netrw_cygwin= 0
303 endif
304endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000305" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100306call s:NetrwInit("g:netrw_alto" , &sb)
307call s:NetrwInit("g:netrw_altv" , &spr)
308call s:NetrwInit("g:netrw_banner" , 1)
309call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200310call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100311call s:NetrwInit("g:netrw_chgwin" , -1)
312call s:NetrwInit("g:netrw_compress" , "gzip")
313call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200314if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
315 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
316 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000317endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200318call s:NetrwInit("g:netrw_cursor" , 2)
319let s:netrw_usercul = &cursorline
320let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar8d043172014-01-23 14:24:41 +0100321call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000322" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200323call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200324call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200325call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200327call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_fastbrowse" , 1)
329call 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 +0000330if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000331 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
332 let g:netrw_ftp_list_cmd = "ls -lF"
333 let g:netrw_ftp_timelist_cmd = "ls -tlF"
334 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000335 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000336 let g:netrw_ftp_list_cmd = "dir"
337 let g:netrw_ftp_timelist_cmd = "dir"
338 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000339 endif
340endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000342" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000344if !exists("g:netrw_ignorenetrc")
345 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
346 let g:netrw_ignorenetrc= 1
347 else
348 let g:netrw_ignorenetrc= 0
349 endif
350endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100351call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000352if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000353 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000354 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200355 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000356 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
357 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100358 if exists("g:netrw_list_cmd_options")
359 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
360 else
361 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
362 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200364 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100365 if exists("g:netrw_list_cmd_options")
366 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
367 else
368 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
369 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000370 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100371" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000372 let g:netrw_list_cmd= ""
373 endif
374endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100375call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000376" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200377if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200378 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200379 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
380endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100381if !exists("g:netrw_localcmdshell")
382 let g:netrw_localcmdshell= ""
383endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000384if !exists("g:netrw_localcopycmd")
385 if has("win32") || has("win95") || has("win64") || has("win16")
386 if g:netrw_cygwin
387 let g:netrw_localcopycmd= "cp"
388 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200389 let g:netrw_localcopycmd = expand("$COMSPEC")
390 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000391 endif
392 elseif has("unix") || has("macunix")
393 let g:netrw_localcopycmd= "cp"
394 else
395 let g:netrw_localcopycmd= ""
396 endif
397endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100398if !exists("g:netrw_localcopydircmd")
399 if has("win32") || has("win95") || has("win64") || has("win16")
400 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200401 let g:netrw_localcopydircmd = "cp"
402 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100403 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200404 let g:netrw_localcopydircmd = expand("$COMSPEC")
405 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100406 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200407 elseif has("unix")
408 let g:netrw_localcopydircmd = "cp"
409 let g:netrw_localcopydircmdopt= " -R"
410 elseif has("macunix")
411 let g:netrw_localcopydircmd = "cp"
412 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200414 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 endif
416endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200417if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100418 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200419 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
420endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200421if has("win32") || has("win95") || has("win64") || has("win16")
422 if g:netrw_cygwin
423 call s:NetrwInit("g:netrw_localmkdir","mkdir")
424 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 let g:netrw_localmkdir = expand("$COMSPEC")
426 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200427 endif
428else
429 call s:NetrwInit("g:netrw_localmkdir","mkdir")
430endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200431call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200432if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200433 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
435endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000436if !exists("g:netrw_localmovecmd")
437 if has("win32") || has("win95") || has("win64") || has("win16")
438 if g:netrw_cygwin
439 let g:netrw_localmovecmd= "mv"
440 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 let g:netrw_localmovecmd = expand("$COMSPEC")
442 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000443 endif
444 elseif has("unix") || has("macunix")
445 let g:netrw_localmovecmd= "mv"
446 else
447 let g:netrw_localmovecmd= ""
448 endif
449endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100450" following serves as an example for how to insert a version&patch specific test
451"if v:version < 704 || (v:version == 704 && !has("patch1107"))
452"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100453call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
454" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000455if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000456 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000457endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000458if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000459 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
460endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000461" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100462call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
463call s:NetrwInit("g:netrw_maxfilenamelen", 32)
464call s:NetrwInit("g:netrw_menu" , 1)
465call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200466call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100467call s:NetrwInit("g:netrw_retmap" , 0)
468if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
469 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
470elseif has("win32") || has("win95") || has("win64") || has("win16")
471 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
472else
473 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000474endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100475call s:NetrwInit("g:netrw_preview" , 0)
476call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100477call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100478call s:NetrwInit("g:netrw_sshport" , "-p")
479call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
480call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
481call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100482call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
483" Default values - q-s ---------- {{{3
484call s:NetrwInit("g:netrw_quickhelp",0)
485let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100486 \ "(create new) %:file d:directory",
487 \ "(windows split&open) o:horz v:vert p:preview",
488 \ "i:style qf:file info O:obtain r:reverse",
489 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
490 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
491 \ "(history) qb:list u:go up U:go down",
492 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
494call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100495if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
496 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
497else
498 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
499endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100500call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
501call s:NetrwInit("g:netrw_sort_options" , "")
502call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000503if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200505 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100506 else
507 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000508 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000509endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_special_syntax" , 0)
511call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200512call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100513call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100514call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000515" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200517if !exists("g:netrw_xstrlen")
518 if exists("g:Align_xstrlen")
519 let g:netrw_xstrlen= g:Align_xstrlen
520 elseif exists("g:drawit_xstrlen")
521 let g:netrw_xstrlen= g:drawit_xstrlen
522 elseif &enc == "latin1" || !has("multi_byte")
523 let g:netrw_xstrlen= 0
524 else
525 let g:netrw_xstrlen= 1
526 endif
527endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200530call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100531call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200532if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000533" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000534" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200536if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200537 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200538else
Bram Moolenaarff034192013-04-24 18:51:19 +0200539 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200540endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200541call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
543call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100544if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100545 let s:treedepthstring= "│ "
546else
547 let s:treedepthstring= "| "
548endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200549call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000550
551" BufEnter event ignored by decho when following variable is true
552" Has a side effect that doau BufReadPost doesn't work, so
553" files read by network transfer aren't appropriately highlighted.
554"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555
Bram Moolenaaradc21822011-04-01 18:03:16 +0200556" ======================
557" Netrw Initialization: {{{1
558" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200559if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100560" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100561 let &l:bexpr = "netrw#BalloonHelp()"
562 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100563 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
564 au VimEnter * let s:initbeval= &beval
565"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100566" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
567" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
568" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
569" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
570" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
571" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists","~".expand("<slnum>")) | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200572endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200573au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200574
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200575if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100576 com! -nargs=* NetrwKeepj keepj <args>
577else
578 let g:netrw_keepj= ""
579 com! -nargs=* NetrwKeepj <args>
580endif
581
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000582" ==============================
583" Netrw Utility Functions: {{{1
584" ==============================
585
Bram Moolenaaradc21822011-04-01 18:03:16 +0200586" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100587" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100588if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100589" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100590 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100591 if &ft != "netrw"
592 return ""
593 endif
594 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
595 let mesg= ""
596 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
597 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
598 elseif getline(v:beval_lnum) =~ '^"\s*/'
599 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
600 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100601 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100602 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
603 let mesg = "S: edit sorting sequence"
604 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
605 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
606 elseif v:beval_text == "Quick" || v:beval_text == "Help"
607 let mesg = "Help: press <F1>"
608 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
609 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
610 else
611 let mesg= ""
612 endif
613 return mesg
614 endfun
615"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100616" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
617" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
618" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
619" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
620" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists","~".expand("<slnum>")) |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200621endif
622
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200624" netrw#Explore: launch the local browser in the directory of the current file {{{2
625" indx: == -1: Nexplore
626" == -2: Pexplore
627" == +: this is overloaded:
628" * If Nexplore/Pexplore is in use, then this refers to the
629" indx'th item in the w:netrw_explore_list[] of items which
630" matched the */pattern **/pattern *//pattern **//pattern
631" * If Hexplore or Vexplore, then this will override
632" g:netrw_winsize to specify the qty of rows or columns the
633" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100634" 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 +0200635" dosplit==1: the window will be split before running the local browser
636" style == 0: Explore style == 1: Explore!
637" == 2: Hexplore style == 3: Hexplore!
638" == 4: Vexplore style == 5: Vexplore!
639" == 6: Texplore
640fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100641" 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("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100642" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200643 if !exists("b:netrw_curdir")
644 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100645" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200646 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100647
648 " record current file for Rexplore's benefit
649 if &ft != "netrw"
650 let w:netrw_rexfile= expand("%:p")
651 endif
652
653 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200654 let curdir = simplify(b:netrw_curdir)
655 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200656 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
657 let curdir= substitute(curdir,'\','/','g')
658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100659" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100660
661 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
662 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
663 " try Explore again.
664 if a:0 > 0
665" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100666 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
667 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
668 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
669 \ '~'.expand("<slnum>"))
670 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
671" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100672 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
673" call Dret("netrw#Explore : returning from retry")
674 return
675" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100676" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100677 endif
678 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200679
680 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100681 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100682" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100683 sil! let keepregstar = @*
684 sil! let keepregplus = @+
685 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200686 sil! let keepregslash= @/
687
Bram Moolenaar8d043172014-01-23 14:24:41 +0100688 " if dosplit
689 " -or- file has been modified AND file not hidden when abandoned
690 " -or- Texplore used
691 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100692" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200693 call s:SaveWinVars()
694 let winsz= g:netrw_winsize
695 if a:indx > 0
696 let winsz= a:indx
697 endif
698
699 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100700" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200701 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200702 if winsz == 0|let winsz= ""|endif
703 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100704" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200705
706 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100707" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200708 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200709 if winsz == 0|let winsz= ""|endif
710 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100711" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200712
713 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100714" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200715 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200716 if winsz == 0|let winsz= ""|endif
717 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100718" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200719
720 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200723 if winsz == 0|let winsz= ""|endif
724 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100725" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200726
727 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200730 if winsz == 0|let winsz= ""|endif
731 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733
734 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
738 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
741 elseif a:style == 6 " Texplore
742 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 call s:RestoreBufVars()
747 endif
748 call s:RestoreWinVars()
749" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100752 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
763 if dirname !~ '/$'
764 let dirname= dirname."/"
765 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200771 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let dirname= a:1
778 endif
779 else
780 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 call s:NetrwClearExplore()
783" call Dret("netrw#Explore : cleared list")
784 return
785 endif
786
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 if dirname =~ '\.\./\=$'
789 let dirname= simplify(fnamemodify(dirname,':p:h'))
790 elseif dirname =~ '\.\.' || dirname == '.'
791 let dirname= simplify(fnamemodify(dirname,':p'))
792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794
795 if dirname =~ '^\*//'
796 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
799 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
802
803 elseif dirname =~ '^\*\*//'
804 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 let pattern= substitute(dirname,'^\*\*//','','')
807 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809
810 elseif dirname =~ '/\*\*/'
811 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100812" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
814 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
815 let b:netrw_curdir = prefixdir
816 else
817 let b:netrw_curdir= getcwd().'/'.prefixdir
818 endif
819 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
820 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
822" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200825 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828
829 elseif dirname=~ '^\*\*/'
830 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
831 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833
834 else
835 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 endif
838
839 if starpat == 0 && a:indx >= 0
840 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 if dirname == ""
843 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100844" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200845 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200846 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200847 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200848 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200849 if dirname == ""
850 let dirname= getcwd()
851 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100853 " depending on whether backslashes have been converted to forward slashes by earlier code).
854 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200855 let dirname= b:netrw_curdir."/".dirname
856 endif
857 elseif dirname !~ '^/'
858 let dirname= b:netrw_curdir."/".dirname
859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
863" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 endif
865 if exists("w:netrw_bannercnt")
866 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
867 " If one wants to return the same place in the netrw window, use :Rex instead.
868 exe w:netrw_bannercnt
869 endif
870
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 " ---------------------------------------------------------------------
873 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
874" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100875" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200876" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100877" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200878" endif
879 " ---------------------------------------------------------------------
880
881 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
882 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
883 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
884 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
885 elseif a:indx <= 0
886 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 let s:didstarstar= 1
891 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
892 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
893 endif
894
895 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100896" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200897 if !exists("w:netrw_explore_indx")
898 let w:netrw_explore_indx= 0
899 endif
900
901 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100902" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200903
904 if indx == -1
905 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100906" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200907 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100908 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 +0100909 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100910" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100911 if @* != keepregstar | sil! let @* = keepregstar | endif
912 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100913 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 sil! let @/ = keepregslash
915" call Dret("netrw#Explore")
916 return
917 endif
918 let indx= w:netrw_explore_indx
919 if indx < 0 | let indx= 0 | endif
920 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
921 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
924 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 endwhile
927 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 elseif indx == -2
931 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 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 +0100935 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100936" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100937 if @* != keepregstar | sil! let @* = keepregstar | endif
938 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 sil! let @/ = keepregslash
941" call Dret("netrw#Explore")
942 return
943 endif
944 let indx= w:netrw_explore_indx
945 if indx < 0 | let indx= 0 | endif
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
947 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 while indx >= 0 && curfile == w:netrw_explore_list[indx]
950 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 endwhile
953 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 else
957 " Explore -- initialize
958 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100959" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200961 let w:netrw_explore_indx= 0
962 if !exists("b:netrw_curdir")
963 let b:netrw_curdir= getcwd()
964 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100965" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200966
967 " switch on starpat to build the w:netrw_explore_list of files
968 if starpat == 1
969 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100970" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
971" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200972 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100973 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 catch /^Vim\%((\a\+)\)\=:E480/
975 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
976" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
977 return
978 endtry
979 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
980 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
981
982 elseif starpat == 2
983 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
985" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200986 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100987 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 catch /^Vim\%((\a\+)\)\=:E480/
989 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
990 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100991 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100992" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100993 if @* != keepregstar | sil! let @* = keepregstar | endif
994 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100995 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 sil! let @/ = keepregslash
997" call Dret("netrw#Explore : no files matched pattern")
998 return
999 endtry
1000 let s:netrw_curdir = b:netrw_curdir
1001 let w:netrw_explore_list = getqflist()
1002 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1003 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1004
1005 elseif starpat == 3
1006 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001007" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 let filepat= substitute(dirname,'^\*/','','')
1009 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001010" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1011" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1013 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1014
1015 elseif starpat == 4
1016 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001017" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1019 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1020 endif " switch on starpat to build w:netrw_explore_list
1021
1022 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001023" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1024" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001025
1026 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001027 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +01001028 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001029" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001030 if @* != keepregstar | sil! let @* = keepregstar | endif
1031 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001032 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001033 sil! let @/ = keepregslash
1034" call Dret("netrw#Explore : no files matched")
1035 return
1036 endif
1037 endif " if indx ... endif
1038
1039 " NetrwStatusLine support - for exploring support
1040 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001041" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001042
1043 " wrap the indx around, but issue a note
1044 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001045" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001046 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1047 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001048 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001049 endif
1050
1051 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001052" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001053 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001054" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001056" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001057 call netrw#LocalBrowseCheck(newdir)
1058 if !exists("w:netrw_liststyle")
1059 let w:netrw_liststyle= g:netrw_liststyle
1060 endif
1061 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001062 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001064 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001065 endif
1066 let w:netrw_explore_mtchcnt = indx + 1
1067 let w:netrw_explore_bufnr = bufnr("%")
1068 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001069 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071
1072 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001075 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 +02001076 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001077 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001078" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001079 if @* != keepregstar | sil! let @* = keepregstar | endif
1080 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001081 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 sil! let @/ = keepregslash
1083" call Dret("netrw#Explore : missing +path_extra")
1084 return
1085 endif
1086
1087 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001088" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1090 sil! unlet w:netrw_treedict
1091 sil! unlet w:netrw_treetop
1092 endif
1093 let newdir= dirname
1094 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001098 endif
1099 endif
1100
1101 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1103" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001104 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001105" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001107 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001108" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 let s:explore_prvdir = b:netrw_curdir
1110 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001111 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 if b:netrw_curdir !~ '/$'
1113 let dirlen= dirlen + 1
1114 endif
1115 let prvfname= ""
1116 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001117" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 if fname =~ '^'.b:netrw_curdir
1119 if s:explore_match == ""
1120 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1121 else
1122 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1123 endif
1124 elseif fname !~ '^/' && fname != prvfname
1125 if s:explore_match == ""
1126 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1127 else
1128 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1129 endif
1130 endif
1131 let prvfname= fname
1132 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001134 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1135 exe "2match netrwMarkFile /".s:explore_match."/"
1136 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 endif
1138 echo "<s-up>==Pexplore <s-down>==Nexplore"
1139 else
1140 2match none
1141 if exists("s:explore_match") | unlet s:explore_match | endif
1142 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1143 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001144" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001145 endif
1146
Bram Moolenaara6878372014-03-22 21:02:50 +01001147 " since Explore may be used to initialize netrw's browser,
1148 " there's no danger of a late FocusGained event on initialization.
1149 " Consequently, set s:netrw_events to 2.
1150 let s:netrw_events= 2
1151 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001152" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001153 if @* != keepregstar | sil! let @* = keepregstar | endif
1154 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001155 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001156 sil! let @/ = keepregslash
1157" call Dret("netrw#Explore : @/<".@/.">")
1158endfun
1159
1160" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001161" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001162fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001163" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001164 let curwin= winnr()
1165
Bram Moolenaara6878372014-03-22 21:02:50 +01001166 if a:0 > 0 && a:1 != ""
1167 " if a netrw window is already on the left-side of the tab
1168 " and a directory has been specified, explore with that
1169 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001170" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001171 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001172" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001173 exe "1wincmd w"
1174 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001175" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001176 exe "Explore ".fnameescape(a1)
1177 exe curwin."wincmd w"
1178 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001179" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001180 unlet t:netrw_lexposn
1181 endif
1182" call Dret("netrw#Lexplore")
1183 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001184 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185 exe curwin."wincmd w"
1186 else
1187 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001188" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001189 endif
1190
Bram Moolenaar8d043172014-01-23 14:24:41 +01001191 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001193 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 else
1196 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001199" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200
1201 if lexwinnr > 0
1202 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001203" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 exe lexwinnr."wincmd w"
1205 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001206 let t:netrw_lexposn = winsaveview()
1207" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 close
1210 if lexwinnr < curwin
1211 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001212 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001213 if lexwinnr != curwin
1214 exe curwin."wincmd w"
1215 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001216 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001217" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218
1219 else
1220 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001221" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222 exe "1wincmd w"
1223 let keep_altv = g:netrw_altv
1224 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 if a:count != 0
1226 let netrw_winsize = g:netrw_winsize
1227 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001230" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001234" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001237 elseif curfile =~ '^\a\{3,}://'
1238" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001239 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001240 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001241" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 endif
1244 if a:count != 0
1245 let g:netrw_winsize = netrw_winsize
1246 endif
1247 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 let g:netrw_altv = keep_altv
1249 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001250" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1251" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001254" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1255 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 unlet t:netrw_lexposn
1257 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259
1260 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001261 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 if a:rightside
1263 let g:netrw_chgwin= 1
1264 else
1265 let g:netrw_chgwin= 2
1266 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001268 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269
Bram Moolenaar8d043172014-01-23 14:24:41 +01001270" call Dret("netrw#Lexplore")
1271endfun
1272
1273" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001274" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001275" supports :NetrwClean -- remove netrw from first directory on runtimepath
1276" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001277fun! netrw#Clean(sys)
1278" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001279
1280 if a:sys
1281 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1282 else
1283 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1284 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001285" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001286 let diddel= 0
1287 let diddir= ""
1288
1289 if choice == 1
1290 for dir in split(&rtp,',')
1291 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001293 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1294 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1295 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1296 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1297 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1298 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 +00001299 let diddir= dir
1300 let diddel= diddel + 1
1301 if !a:sys|break|endif
1302 endif
1303 endfor
1304 endif
1305
1306 echohl WarningMsg
1307 if diddel == 0
1308 echomsg "netrw is either not installed or not removable"
1309 elseif diddel == 1
1310 echomsg "removed one copy of netrw from <".diddir.">"
1311 else
1312 echomsg "removed ".diddel." copies of netrw"
1313 endif
1314 echohl None
1315
Bram Moolenaara6878372014-03-22 21:02:50 +01001316" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317endfun
1318
Bram Moolenaar5c736222010-01-06 20:54:52 +01001319" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001320" netrw#MakeTgt: make a target out of the directory name provided {{{2
1321fun! netrw#MakeTgt(dname)
1322" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1323 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001324 let svpos = winsaveview()
1325" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1327" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001328 if s:netrwmftgt_islocal
1329 let netrwmftgt= simplify(a:dname)
1330 else
1331 let netrwmftgt= a:dname
1332 endif
1333 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1334 " re-selected target, so just clear it
1335 unlet s:netrwmftgt s:netrwmftgt_islocal
1336 else
1337 let s:netrwmftgt= netrwmftgt
1338 endif
1339 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001340 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001341 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001342" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1343 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001344" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001345endfun
1346
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" ---------------------------------------------------------------------
1348" netrw#Obtain: {{{2
1349" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001350" islocal=0 obtain from remote source
1351" =1 obtain from local source
1352" fname : a filename or a list of filenames
1353" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001354fun! netrw#Obtain(islocal,fname,...)
1355" 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 +02001356 " NetrwStatusLine support - for obtaining support
1357
1358 if type(a:fname) == 1
1359 let fnamelist= [ a:fname ]
1360 elseif type(a:fname) == 3
1361 let fnamelist= a:fname
1362 else
1363 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 +01001364" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001365 return
1366 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001367" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001368 if a:0 > 0
1369 let tgtdir= a:1
1370 else
1371 let tgtdir= getcwd()
1372 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001373" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001374
1375 if exists("b:netrw_islocal") && b:netrw_islocal
1376 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001378 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1379 let topath= s:ComposePath(tgtdir,"")
1380 if (has("win32") || has("win95") || has("win64") || has("win16"))
1381 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001382" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001383 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001384" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001385 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001386 if v:shell_error != 0
1387 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001388" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001389 return
1390 endif
1391 endfor
1392 else
1393 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1395 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1396" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001397 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 if v:shell_error != 0
1399 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 return
1402 endif
1403 endif
1404 elseif !exists("b:netrw_curdir")
1405 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1406 else
1407 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1408 endif
1409
1410 else
1411 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 if type(a:fname) == 1
1414 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1415 endif
1416 call s:NetrwMethod(b:netrw_curdir)
1417
1418 if b:netrw_method == 4
1419 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 if exists("g:netrw_port") && g:netrw_port != ""
1422 let useport= " ".g:netrw_scpport." ".g:netrw_port
1423 else
1424 let useport= ""
1425 endif
1426 if b:netrw_fname =~ '/'
1427 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1428 else
1429 let path= ""
1430 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001431 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".filelist." ".s:ShellEscape(tgtdir,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433
1434 elseif b:netrw_method == 2
1435 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001436" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001437 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001438 let tmpbufnr= bufnr("%")
1439 setl ff=unix
1440 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001441 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001443 endif
1444
1445 if exists("b:netrw_fname") && b:netrw_fname != ""
1446 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 endif
1449
1450 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 endif
1454 for fname in fnamelist
1455 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 endfor
1458 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001462 endif
1463 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1464 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1465 let debugkeep= &debug
1466 setl debug=msg
1467 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1468 let &debug= debugkeep
1469 endif
1470
1471 elseif b:netrw_method == 3
1472 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 let tmpbufnr= bufnr("%")
1476 setl ff=unix
1477
1478 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001480" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485
1486 if exists("g:netrw_uid") && g:netrw_uid != ""
1487 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001488 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001491 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001495 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001497 endif
1498 endif
1499
1500 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001501 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001502" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001503 endif
1504
1505 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001506 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 endif
1509
1510 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 endif
1514
1515 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523
1524 " perform ftp:
1525 " -i : turns off interactive prompting from ftp
1526 " -n unix : DON'T use <.netrc>, even though it exists
1527 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001528 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1529 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1532 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001535 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001538
1539 elseif b:netrw_method == 9
1540 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001541" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001542 if a:fname =~ '/'
1543 let localfile= substitute(a:fname,'^.*/','','')
1544 else
1545 let localfile= a:fname
1546 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001547 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1).s:ShellEscape(localfile)." ".s:ShellEscape(tgtdir))
Bram Moolenaar13600302014-05-22 18:26:40 +02001548
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001550 " probably a badly formed url; protocol not recognized
1551" call Dret("netrw#Obtain : unsupported method")
1552 return
1553
1554 else
1555 " protocol recognized but not supported for Obtain (yet?)
1556 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001557 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001558 endif
1559" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 return
1561 endif
1562
1563 " restore status line
1564 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001565 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 endif
1567
1568 endif
1569
1570 " cleanup
1571 if exists("tmpbufnr")
1572 if bufnr("%") != tmpbufnr
1573 exe tmpbufnr."bw!"
1574 else
1575 q!
1576 endif
1577 endif
1578
Bram Moolenaara6878372014-03-22 21:02:50 +01001579" call Dret("netrw#Obtain")
1580endfun
1581
1582" ---------------------------------------------------------------------
1583" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1584fun! netrw#Nread(mode,fname)
1585" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001586 let svpos= winsaveview()
1587" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001588 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001589" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1590 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001591
1592 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1593 if exists("w:netrw_bannercnt")
1594 " start with cursor just after the banner
1595 exe w:netrw_bannercnt
1596 endif
1597 endif
1598" call Dret("netrw#Nread")
1599endfun
1600
1601" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001602" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1603" Options get restored by s:NetrwOptionsRestore()
1604"
1605" Option handling:
1606" * save user's options (s:NetrwOptionsSave)
1607" * set netrw-safe options (s:NetrwOptionsSafe)
1608" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1609" * restore user's options (s:netrwOPtionsRestore)
1610" - restore a user option when != safe option (s:NetrwRestoreSetting)
1611" vt: (variable type) normally its either "w:" or "s:"
1612fun! s:NetrwOptionsSave(vt)
1613" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1614" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
1615" 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,'~'.expand("<slnum>"))
1616
1617 if !exists("{a:vt}netrw_optionsave")
1618 let {a:vt}netrw_optionsave= 1
1619 else
1620" call Dret("s:NetrwOptionsSave : options already saved")
1621 return
1622 endif
1623" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1624
1625 " Save current settings and current directory
1626" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1627 let s:yykeep = @@
1628 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1629 let {a:vt}netrw_aikeep = &l:ai
1630 let {a:vt}netrw_awkeep = &l:aw
1631 let {a:vt}netrw_bhkeep = &l:bh
1632 let {a:vt}netrw_blkeep = &l:bl
1633 let {a:vt}netrw_btkeep = &l:bt
1634 let {a:vt}netrw_bombkeep = &l:bomb
1635 let {a:vt}netrw_cedit = &cedit
1636 let {a:vt}netrw_cikeep = &l:ci
1637 let {a:vt}netrw_cinkeep = &l:cin
1638 let {a:vt}netrw_cinokeep = &l:cino
1639 let {a:vt}netrw_comkeep = &l:com
1640 let {a:vt}netrw_cpokeep = &l:cpo
1641 let {a:vt}netrw_diffkeep = &l:diff
1642 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001643 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1644 let {a:vt}netrw_ffkeep = &l:ff
1645 endif
1646 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1647 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1648 let {a:vt}netrw_hidkeep = &l:hidden
1649 let {a:vt}netrw_imkeep = &l:im
1650 let {a:vt}netrw_iskkeep = &l:isk
1651 let {a:vt}netrw_lskeep = &l:ls
1652 let {a:vt}netrw_makeep = &l:ma
1653 let {a:vt}netrw_magickeep = &l:magic
1654 let {a:vt}netrw_modkeep = &l:mod
1655 let {a:vt}netrw_nukeep = &l:nu
1656 let {a:vt}netrw_rnukeep = &l:rnu
1657 let {a:vt}netrw_repkeep = &l:report
1658 let {a:vt}netrw_rokeep = &l:ro
1659 let {a:vt}netrw_selkeep = &l:sel
1660 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001661 if !g:netrw_use_noswf
1662 let {a:vt}netrw_swfkeep = &l:swf
1663 endif
1664 let {a:vt}netrw_tskeep = &l:ts
1665 let {a:vt}netrw_twkeep = &l:tw " textwidth
1666 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1667 let {a:vt}netrw_wrapkeep = &l:wrap
1668 let {a:vt}netrw_writekeep = &l:write
1669
1670 " save a few selected netrw-related variables
1671" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1672 if g:netrw_keepdir
1673 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001674" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 endif
1676 if has("clipboard")
1677 sil! let {a:vt}netrw_starkeep = @*
1678 sil! let {a:vt}netrw_pluskeep = @+
1679 endif
1680 sil! let {a:vt}netrw_slashkeep= @/
1681
1682" 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,'~'.expand("<slnum>"))
1683" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1684endfun
1685
1686" ---------------------------------------------------------------------
1687" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1688" Use s:NetrwSaveOptions() to save user settings
1689" Use s:NetrwOptionsRestore() to restore user settings
1690fun! s:NetrwOptionsSafe(islocal)
1691" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1692" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1693" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1694 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1695 call s:NetrwSetSafeSetting("&l:ai",0)
1696 call s:NetrwSetSafeSetting("&l:aw",0)
1697 call s:NetrwSetSafeSetting("&l:bl",0)
1698 call s:NetrwSetSafeSetting("&l:bomb",0)
1699 if a:islocal
1700 call s:NetrwSetSafeSetting("&l:bt","nofile")
1701 else
1702 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1703 endif
1704 call s:NetrwSetSafeSetting("&l:ci",0)
1705 call s:NetrwSetSafeSetting("&l:cin",0)
1706 call s:NetrwSetSafeSetting("&l:bh","hide")
1707 call s:NetrwSetSafeSetting("&l:cino","")
1708 call s:NetrwSetSafeSetting("&l:com","")
1709 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1710 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1711 setl fo=nroql2
1712 call s:NetrwSetSafeSetting("&l:hid",0)
1713 call s:NetrwSetSafeSetting("&l:im",0)
1714 setl isk+=@ isk+=* isk+=/
1715 call s:NetrwSetSafeSetting("&l:magic",1)
1716 if g:netrw_use_noswf
1717 call s:NetrwSetSafeSetting("swf",0)
1718 endif
1719 call s:NetrwSetSafeSetting("&l:report",10000)
1720 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1721 call s:NetrwSetSafeSetting("&l:spell",0)
1722 call s:NetrwSetSafeSetting("&l:tw",0)
1723 call s:NetrwSetSafeSetting("&l:wig","")
1724 setl cedit&
1725 call s:NetrwCursor()
1726
1727 " allow the user to override safe options
1728" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1729 if &ft == "netrw"
1730" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1731 keepalt NetrwKeepj doau FileType netrw
1732 endif
1733
1734" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1735" 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,'~'.expand("<slnum>"))
1736" call Dret("s:NetrwOptionsSafe")
1737endfun
1738
1739" ---------------------------------------------------------------------
1740" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1741fun! s:NetrwOptionsRestore(vt)
1742" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001743" 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,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001744 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001745" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001746" 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,'~'.expand("<slnum>"))
1747" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001748" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001749 return
1750 endif
1751 unlet {a:vt}netrw_optionsave
1752
1753 if exists("+acd")
1754 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001755" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001756 let curdir = getcwd()
1757 let &l:acd = {a:vt}netrw_acdkeep
1758 unlet {a:vt}netrw_acdkeep
1759 if &l:acd
1760 call s:NetrwLcd(curdir)
1761 endif
1762 endif
1763 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001764 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1765 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1766 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1767 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1768 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1769 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1770 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1771 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1772 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1773 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1774 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1775 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1776 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1777 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1778 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001779 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001780 call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
1781 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
1782 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
1783 call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
1784 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
1785 call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
1786 call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
1787 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
1788 call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
1789 call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
1790 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
1791 call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
1792 call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
1793 call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1794 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
1795 call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
1796 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
1797 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
1798 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1799 call s:NetrwRestoreSetting("s:yykeep","@@")
1800 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1801 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1802 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1803 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1804
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 if exists("{a:vt}netrw_swfkeep")
1806 if &directory == ""
1807 " user hasn't specified a swapfile directory;
1808 " netrw will temporarily set the swapfile directory
1809 " to the current directory as returned by getcwd().
1810 let &l:directory= getcwd()
1811 sil! let &l:swf = {a:vt}netrw_swfkeep
1812 setl directory=
1813 unlet {a:vt}netrw_swfkeep
1814 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001815 if !g:netrw_use_noswf
1816 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1817 sil! let &l:swf= {a:vt}netrw_swfkeep
1818 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001819 unlet {a:vt}netrw_swfkeep
1820 endif
1821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001822 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001823 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1824 if exists("{a:vt}netrw_dirkeep")
1825 call s:NetrwLcd(dirkeep)
1826 unlet {a:vt}netrw_dirkeep
1827 endif
1828 endif
1829 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001830" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1832 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001833 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001835
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001836" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1837" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1838" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1839" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1840" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001841 " Moved the filetype detect here from NetrwGetFile() because remote files
1842 " were having their filetype detect-generated settings overwritten by
1843 " NetrwOptionRestore.
1844 if &ft != "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001845" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001846 filetype detect
1847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001848" 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,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001849" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001850endfun
1851
1852" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001853" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1854" but only when the options' value and the safe setting differ
1855" Doing this means that netrw will not come up as having changed a
1856" setting last when it really didn't actually change it.
1857"
1858" Called from s:NetrwOptionsSafe
1859" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1860fun! s:NetrwSetSafeSetting(setting,safesetting)
1861" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001862
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 if a:setting =~ '^&'
1864" call Decho("fyi: a:setting starts with &")
1865 exe "let settingval= ".a:setting
1866" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001867
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 if settingval != a:safesetting
1869" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1870 if type(a:safesetting) == 0
1871 exe "let ".a:setting."=".a:safesetting
1872 elseif type(a:safesetting) == 1
1873 exe "let ".a:setting."= '".a:safesetting."'"
1874 else
1875 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1876 endif
1877 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001878 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001879
Bram Moolenaar85850f32019-07-19 22:05:51 +02001880" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001881endfun
1882
1883" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001884" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1885" but only if the setting value differs from the associated keepvar.
1886" Doing this means that netrw will not come up as having changed a
1887" setting last when it really didn't actually change it.
1888"
1889" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1890" keepvars are set up by s:NetrwOptionsSave
1891fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001892""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001893
Bram Moolenaar85850f32019-07-19 22:05:51 +02001894 " typically called from s:NetrwOptionsRestore
1895 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1896 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1897 " Restores option (if different) from a keepvar
1898 if exists(a:keepvar)
1899 exe "let keepvarval= ".a:keepvar
1900 exe "let setting= ".a:setting
1901
1902"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1903"" call Decho("fyi: keepvarval=".keepvarval)
1904"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1905
1906 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001907"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 if type(a:setting) == 0
1909 exe "let ".a:setting."= ".keepvarval
1910 elseif type(a:setting) == 1
1911 exe "let ".a:setting."= '".keepvarval."'"
1912 else
1913 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1914 endif
1915 endif
1916
1917 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 endif
1919
Bram Moolenaar85850f32019-07-19 22:05:51 +02001920"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001921endfun
1922
1923" ---------------------------------------------------------------------
1924" NetrwStatusLine: {{{2
1925fun! NetrwStatusLine()
1926
1927" vvv NetrwStatusLine() debugging vvv
1928" let g:stlmsg=""
1929" if !exists("w:netrw_explore_bufnr")
1930" let g:stlmsg="!X<explore_bufnr>"
1931" elseif w:netrw_explore_bufnr != bufnr("%")
1932" let g:stlmsg="explore_bufnr!=".bufnr("%")
1933" endif
1934" if !exists("w:netrw_explore_line")
1935" let g:stlmsg=" !X<explore_line>"
1936" elseif w:netrw_explore_line != line(".")
1937" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1938" endif
1939" if !exists("w:netrw_explore_list")
1940" let g:stlmsg=" !X<explore_list>"
1941" endif
1942" ^^^ NetrwStatusLine() debugging ^^^
1943
1944 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")
1945 " restore user's status line
1946 let &stl = s:netrw_users_stl
1947 let &laststatus = s:netrw_users_ls
1948 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1949 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1950 return ""
1951 else
1952 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1953 endif
1954endfun
1955
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001957" Netrw Transfer Functions: {{{1
1958" ===============================
1959
Bram Moolenaar071d4272004-06-13 20:20:40 +00001960" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001961" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001962" mode: =0 read remote file and insert before current line
1963" =1 read remote file and insert after current line
1964" =2 replace with remote file
1965" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001966fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001967" 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 +00001968
Bram Moolenaar5c736222010-01-06 20:54:52 +01001969 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 call s:NetrwOptionsSave("w:")
1971 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001972 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001973 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1974 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1975 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001976" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001977
Bram Moolenaar5c736222010-01-06 20:54:52 +01001978 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001979 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001980 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001981 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001982 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001983 elseif a:mode == 2 " replace with remote file
1984 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001985 elseif a:mode == 3 " skip read of file (leave as temporary)
1986 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001987 else
1988 exe a:mode
1989 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001990 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001991 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001992" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001993
Bram Moolenaar5c736222010-01-06 20:54:52 +01001994 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001995 let tmpfile= s:GetTempfile("")
1996 if tmpfile == ""
1997" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001998 return
1999 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002002
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002003 " attempt to repeat with previous host-file-etc
2004 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002005" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002006 let choice = b:netrw_lastfile
2007 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002008
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002009 else
2010 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002011" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002012
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002013 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002014 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002015 echomsg 'NetRead Usage:'
2016 echomsg ':Nread machine:path uses rcp'
2017 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2018 echomsg ':Nread "machine id password path" uses ftp'
2019 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2020 echomsg ':Nread fetch://machine/path uses fetch'
2021 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2022 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002023 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002024 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002025 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2026 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2027 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2028 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002029 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002030 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002031
Bram Moolenaar9964e462007-05-05 17:54:07 +00002032 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002033 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002034" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002035 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002036 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002037 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002038 else
2039 " case "... ... ..."
2040 let choice = strpart(choice,1,strlen(choice)-1)
2041 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042
Bram Moolenaar9964e462007-05-05 17:54:07 +00002043 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 let wholechoice = wholechoice . " " . choice
2045 let ichoice = ichoice + 1
2046 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002047 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002048 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002049 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002050" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 return
2052 endif
2053 let choice= a:{ichoice}
2054 endwhile
2055 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2056 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 endif
2058 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002060" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062
Bram Moolenaar5c736222010-01-06 20:54:52 +01002063 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002064 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002065 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002066" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002067 return
2068 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002069 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaar8d043172014-01-23 14:24:41 +01002071 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002072" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02002073 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002074" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002075 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002076" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002081 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002082 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002083 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2084 echo "(netrw) Processing your read request..."
2085 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002086
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002088 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002091 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002093 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 " ER: the tmpfile is full path: rcp sees C:\... as host C
2095 if s:netrw_has_nt_rcp == 1
2096 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2097 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2098 else
2099 " Any way needed it machine contains a '.'
2100 let uid_machine = g:netrw_machine .'.'. $USERNAME
2101 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2104 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2105 else
2106 let uid_machine = g:netrw_machine
2107 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002109 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002110 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002114 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002116" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002117 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002118 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002119 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002120 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002121 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002122" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002123 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002124 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002125" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002126 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002127 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002128" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 endif
2134 " 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 +00002135 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002136 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002137 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002139 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002141 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002143 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2144 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002145 q!
2146 endif
2147 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002148 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002150
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002152 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2154 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002155" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002156 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002157 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002158 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002159 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002161 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002162" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002164 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002165" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002167
Bram Moolenaar97d62492012-11-15 21:28:22 +01002168 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002169 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002170 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002171" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002172 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002173 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002175" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002176 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002177 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002178" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002179 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002181
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002183 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002186 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002189 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002192
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 " perform ftp:
2194 " -i : turns off interactive prompting from ftp
2195 " -n unix : DON'T use <.netrc>, even though it exists
2196 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002197 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2200 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002202 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002203 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002204 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002207 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002209
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002211 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002215 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 else
2217 let useport= ""
2218 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002219 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2220 " This is workaround to avoid mis-handle windows local-path:
2221 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2222 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2223 else
2224 let tmpfile_get = tmpfile
2225 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002226 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002232 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002235 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002236 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002237 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002238" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002239 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002241
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002242 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2243 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002245 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002247 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002249 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002250 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002251
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002253 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002255 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2256 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2258" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2259 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002260 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 endif
2264 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002266 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002267
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002269 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002270 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaar5c736222010-01-06 20:54:52 +01002273 if !executable(g:netrw_dav_cmd)
2274 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2275" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2276 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002278 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002280 else
2281 " Construct execution string (four lines) which will be passed through filter
2282 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2283 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002284 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002285 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002286 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002288 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002289 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002290 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002291 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002293 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2294 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002295
Bram Moolenaar5c736222010-01-06 20:54:52 +01002296 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002297 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002299 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002300 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002301 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002303
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002306 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002308 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002309 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002311
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002313 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002314 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002315 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002318 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002319 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002320 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002321" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002322 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002324 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 let netrw_option= "http"
2326 else
2327 let netrw_option= "ftp"
2328 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaar446cb832008-06-24 21:56:24 +00002331 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002333 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002336
Bram Moolenaar446cb832008-06-24 21:56:24 +00002337 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002340 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002341
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002344 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002345" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2346 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002347 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002349
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002350 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002351 " NetRead: (file) NetRead Method #10 {{{3
2352 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002353" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2354 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002355 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2356 let b:netrw_lastfile = choice
2357
2358 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002360 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002361 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002362 endif
2363 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002364
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002366 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002369 unlet b:netrw_fname
2370 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002371 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002372" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002374 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002375 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002376
Bram Moolenaar9964e462007-05-05 17:54:07 +00002377" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378endfun
2379
2380" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002381" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002382fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002383" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002384
Bram Moolenaar5c736222010-01-06 20:54:52 +01002385 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002387 call s:NetrwOptionsSave("w:")
2388 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002389
Bram Moolenaar5c736222010-01-06 20:54:52 +01002390 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002391 let tmpfile= s:GetTempfile("")
2392 if tmpfile == ""
2393" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002394 return
2395 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002396
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 if a:0 == 0
2398 let ichoice = 0
2399 else
2400 let ichoice = 1
2401 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002402
Bram Moolenaar9964e462007-05-05 17:54:07 +00002403 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002405 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002406 " For binary writes, always write entire file.
2407 " (line numbers don't really make sense for that).
2408 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002410 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002411 elseif g:netrw_cygwin
2412 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002413 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002414" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002415 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002416 else
2417 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002419 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002420 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002421
Bram Moolenaar9964e462007-05-05 17:54:07 +00002422 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002423 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002424 " on the temporary file's name. Deletion of the temporary file during
2425 " cleanup then causes an error message.
2426 0file!
2427 endif
2428
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002431
Bram Moolenaar9964e462007-05-05 17:54:07 +00002432 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 " attempt to repeat with previous host-file-etc
2434 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002435" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 let choice = b:netrw_lastfile
2437 let ichoice= ichoice + 1
2438 else
2439 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaar8d043172014-01-23 14:24:41 +01002441 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002443 echomsg 'NetWrite Usage:"'
2444 echomsg ':Nwrite machine:path uses rcp'
2445 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2446 echomsg ':Nwrite "machine id password path" uses ftp'
2447 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2448 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2449 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2450 echomsg ':Nwrite rcp://machine/path uses rcp'
2451 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2452 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2453 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002456
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457 elseif match(choice,"^\"") != -1
2458 if match(choice,"\"$") != -1
2459 " case "..."
2460 let choice=strpart(choice,1,strlen(choice)-2)
2461 else
2462 " case "... ... ..."
2463 let choice = strpart(choice,1,strlen(choice)-1)
2464 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002466 while match(choice,"\"$") == -1
2467 let wholechoice= wholechoice . " " . choice
2468 let ichoice = ichoice + 1
2469 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002470 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002471 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002472 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002473" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002474 return
2475 endif
2476 let choice= a:{ichoice}
2477 endwhile
2478 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2479 endif
2480 endif
2481 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002482 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002484
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002486 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002487 if !exists("b:netrw_method") || b:netrw_method < 0
2488" call Dfunc("netrw#NetWrite : unsupported method")
2489 return
2490 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002491
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002492 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002494 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2496 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002497" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002498 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002499
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002501 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002502 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 if s:netrw_has_nt_rcp == 1
2505 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2506 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2507 else
2508 let uid_machine = g:netrw_machine .'.'. $USERNAME
2509 endif
2510 else
2511 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2512 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2513 else
2514 let uid_machine = g:netrw_machine
2515 endif
2516 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002517 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002520 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002521 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002522 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002523" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002524 let netrw_fname = b:netrw_fname
2525
2526 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2527 let bhkeep = &l:bh
2528 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002529 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002530 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002531
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002532" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002533 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002534 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002536 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002537 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002538" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002539 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002540 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002541" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002543 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002545" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2546 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 endif
2548 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2549 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002550 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002551 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002552 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002555
2556 " remove enew buffer (quietly)
2557 let filtbuf= bufnr("%")
2558 exe curbuf."b!"
2559 let &l:bh = bhkeep
2560 exe filtbuf."bw!"
2561
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002564 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002566 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002568" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 let netrw_fname = b:netrw_fname
2570 let bhkeep = &l:bh
2571
2572 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2573 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002574 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002575 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002576 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002577
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002579 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002581 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002582 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002583" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002584 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002585 if exists("g:netrw_uid") && g:netrw_uid != ""
2586 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002587 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002588" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002589 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002590 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002593 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002594 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002596 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002598 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002606 " save choice/id/password for future use
2607 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002608
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002609 " perform ftp:
2610 " -i : turns off interactive prompting from ftp
2611 " -n unix : DON'T use <.netrc>, even though it exists
2612 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002613 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2616 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002617 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002618 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002619 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002620 let mod=1
2621 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622
2623 " remove enew buffer (quietly)
2624 let filtbuf= bufnr("%")
2625 exe curbuf."b!"
2626 let &l:bh= bhkeep
2627 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002628
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002631 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002632" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002633 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002634 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 else
2636 let useport= ""
2637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002639 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002643 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002645 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2646 if executable(curl)
2647 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002649 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002650 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002651 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002652
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002654 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002655 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002657
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002659 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2660 let bhkeep = &l:bh
2661
2662 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2663 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002664 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666
Bram Moolenaarff034192013-04-24 18:51:19 +02002667 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002668 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002673 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002675 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002676 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002677
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002679 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002681
2682 " remove enew buffer (quietly)
2683 let filtbuf= bufnr("%")
2684 exe curbuf."b!"
2685 let &l:bh = bhkeep
2686 exe filtbuf."bw!"
2687
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002689
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002691 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002692 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002693" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002694 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002695 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002696
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002699 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002700" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002701 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2703 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2704 else
2705 let uid_machine = g:netrw_machine
2706 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002707
2708 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2709 let bhkeep = &l:bh
2710 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002711 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002713
Bram Moolenaarff034192013-04-24 18:51:19 +02002714 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002715 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002716" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002717 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002719 let filtbuf= bufnr("%")
2720 exe curbuf."b!"
2721 let &l:bh = bhkeep
2722 exe filtbuf."bw!"
2723 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002724
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002725 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002726 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002727 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002728 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002729 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002732
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002734" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002735 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002736" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002737 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002738 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002739 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002742 " restore modifiability; usually equivalent to set nomod
2743 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002745 elseif !exists("leavemod")
2746 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002747" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002748 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002749" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002751
Bram Moolenaar9964e462007-05-05 17:54:07 +00002752" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753endfun
2754
2755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002756" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002757" uses NetRead to get a copy of the file into a temporarily file,
2758" then sources that file,
2759" then removes that file.
2760fun! netrw#NetSource(...)
2761" call Dfunc("netrw#NetSource() a:0=".a:0)
2762 if a:0 > 0 && a:1 == '?'
2763 " give help
2764 echomsg 'NetSource Usage:'
2765 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2766 echomsg ':Nsource fetch://machine/path uses fetch'
2767 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002768 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002769 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2770 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2771 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2772 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2773 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002775 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002776 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002777 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002778" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002779 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002781 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002783 if delete(s:netrw_tmpfile)
2784 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2785 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002786 unlet s:netrw_tmpfile
2787 else
2788 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2789 endif
2790 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002791 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002792 endif
2793" call Dret("netrw#NetSource")
2794endfun
2795
Bram Moolenaar8d043172014-01-23 14:24:41 +01002796" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002797" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2798" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002799fun! netrw#SetTreetop(iscmd,...)
2800" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2801" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002802
Bram Moolenaar85850f32019-07-19 22:05:51 +02002803 " iscmd==0: netrw#SetTreetop called using gn mapping
2804 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2805" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002806 " clear out the current tree
2807 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002809 let inittreetop= w:netrw_treetop
2810 unlet w:netrw_treetop
2811 endif
2812 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002814 unlet w:netrw_treedict
2815 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002816" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002817
Bram Moolenaar85850f32019-07-19 22:05:51 +02002818 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002819 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002821 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822 if isdirectory(s:NetrwFile(a:1))
2823" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002824 let treedir= a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar8d043172014-01-23 14:24:41 +01002826 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002827" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002828 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002829 " normally the cursor is left in the message window.
2830 " However, here this results in the directory being listed in the message window, which is not wanted.
2831 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002832 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002833 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01002834 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002835 endif
2836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002837" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002838
2839 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002840 let islocal= expand("%") !~ '^\a\{3,}://'
2841" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002842
2843 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002844 if islocal
2845 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2846 else
2847 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2848 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002849
Bram Moolenaara6878372014-03-22 21:02:50 +01002850" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002851endfun
2852
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002854" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855" readcmd == %r : replace buffer with newly read file
2856" == 0r : read file at top of buffer
2857" == r : read file after current line
2858" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002859fun! s:NetrwGetFile(readcmd, tfile, method)
2860" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002861
2862 " readcmd=='t': simply do nothing
2863 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002864" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002865" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002866 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002867 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002868
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869 " get name of remote filename (ie. url and all)
2870 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002871" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002872
Bram Moolenaar9964e462007-05-05 17:54:07 +00002873 if exists("*NetReadFixup")
2874 " for the use of NetReadFixup (not otherwise used internally)
2875 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002876 endif
2877
Bram Moolenaar9964e462007-05-05 17:54:07 +00002878 if a:readcmd[0] == '%'
2879 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002881
2882 " rename the current buffer to the temp file (ie. tfile)
2883 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002885 else
2886 let tfile= a:tfile
2887 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002888 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002889
2890 " edit temporary file (ie. read the temporary file in)
2891 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002893 call zip#Browse(tfile)
2894 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002896 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002897 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002899 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002900 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002902 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002903 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002905 call tar#Browse(tfile)
2906 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002908 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002911 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002912 endif
2913
2914 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002916
Bram Moolenaar97d62492012-11-15 21:28:22 +01002917 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002918 " Note that isk must not include a "/" for scripts.vim
2919 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002920" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002921 let iskkeep= &l:isk
2922 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002923 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002925 let line1 = 1
2926 let line2 = line("$")
2927
Bram Moolenaar8d043172014-01-23 14:24:41 +01002928 elseif !&ma
2929 " 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 +01002930 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002931" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002932 return
2933
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934 elseif s:FileReadable(a:tfile)
2935 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002936" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937 let curline = line(".")
2938 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002939" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002940 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002941 let line1= curline + 1
2942 let line2= line("$") - lastline + 1
2943
2944 else
2945 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2947" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002948 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002949" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950 return
2951 endif
2952
2953 " User-provided (ie. optional) fix-it-up command
2954 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002955" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002956 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002958" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 endif
2960
Bram Moolenaaradc21822011-04-01 18:03:16 +02002961 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002962 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002963 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 endif
2965
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967
2968 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002969" redraw!
2970
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002972" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002973endfun
2974
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002976" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002977" Input:
2978" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2979" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" b:netrw_method= 1: rcp
2981" 2: ftp + <.netrc>
2982" 3: ftp + machine, id, password, and [path]filename
2983" 4: scp
2984" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002985" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" 7: rsync
2987" 8: fetch
2988" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002989" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002990" g:netrw_machine= hostname
2991" b:netrw_fname = filename
2992" g:netrw_port = optional port number (for ftp)
2993" g:netrw_choice = copy of input url (choice)
2994fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002995" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002996
Bram Moolenaar251e1912011-06-19 05:09:16 +02002997 " sanity check: choice should have at least three slashes in it
2998 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2999 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3000 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003001" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003002 return
3003 endif
3004
Bram Moolenaar5c736222010-01-06 20:54:52 +01003005 " record current g:netrw_machine, if any
3006 " curmachine used if protocol == ftp and no .netrc
3007 if exists("g:netrw_machine")
3008 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003009" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003010 else
3011 let curmachine= "N O T A HOST"
3012 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003013 if exists("g:netrw_port")
3014 let netrw_port= g:netrw_port
3015 endif
3016
3017 " insure that netrw_ftp_cmd starts off every method determination
3018 " with the current g:netrw_ftp_cmd
3019 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003020
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003021 " initialization
3022 let b:netrw_method = 0
3023 let g:netrw_machine = ""
3024 let b:netrw_fname = ""
3025 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003026 let g:netrw_choice = a:choice
3027
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003028 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003029 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003030 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3031 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003032 " rcpurm : rcp://[user@]host/filename Use rcp
3033 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003034 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003035 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003036 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003037 " rsyncurm : rsync://host[:port]/path Use rsync
3038 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3039 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003040 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003041 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3042 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003043 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3044 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003045 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003046 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003047 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003049 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003050 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003051 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003052 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003055 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003056 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003057 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003058" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003059 let b:netrw_method = 1
3060 let userid = substitute(a:choice,rcpurm,'\1',"")
3061 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3062 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003063 if userid != ""
3064 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003066
Bram Moolenaaradc21822011-04-01 18:03:16 +02003067 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003068 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003069" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003070 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003071 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3072 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3073 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003074
Bram Moolenaar15146672011-10-20 22:22:38 +02003075 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003076 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003077" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003078 let b:netrw_method = 5
3079 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3080 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003081 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003082
Bram Moolenaaradc21822011-04-01 18:03:16 +02003083 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003084 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003085" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003087 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003088 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3089 else
3090 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3091 endif
3092 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003093
Bram Moolenaaradc21822011-04-01 18:03:16 +02003094 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003095 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003096" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003097 let b:netrw_method = 7
3098 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3099 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003100
Bram Moolenaaradc21822011-04-01 18:03:16 +02003101 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003102 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003103" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003104 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3106 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3107 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003108" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 if userid != ""
3110 let g:netrw_uid= userid
3111 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003112
Bram Moolenaaradc21822011-04-01 18:03:16 +02003113 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003114 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003115 call NetUserPass("ftp:".g:netrw_machine)
3116 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003117 " if there's a change in hostname, require password re-entry
3118 unlet s:netrw_passwd
3119 endif
3120 if exists("netrw_port")
3121 unlet netrw_port
3122 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003123 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003124
Bram Moolenaar446cb832008-06-24 21:56:24 +00003125 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let b:netrw_method = 3
3127 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003128 let host= substitute(g:netrw_machine,'\..*$','','')
3129 if exists("s:netrw_hup[host]")
3130 call NetUserPass("ftp:".host)
3131
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003132 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003133" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3134" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003135 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003136 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003138 endif
3139 let b:netrw_method= 2
3140 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003141" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 let b:netrw_method= 2
3143 else
3144 if !exists("g:netrw_uid") || g:netrw_uid == ""
3145 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003146 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003148 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 endif
3150 let b:netrw_method= 3
3151 endif
3152 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaaradc21822011-04-01 18:03:16 +02003154 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let b:netrw_method = 8
3158 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3159 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3160 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3161 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaaradc21822011-04-01 18:03:16 +02003163 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3168 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003169 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003171 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003175" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003176 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003177 let b:netrw_method = 3
3178 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3179 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003180
Bram Moolenaar9964e462007-05-05 17:54:07 +00003181 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 let b:netrw_method = 2
3183 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3184 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3185 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003186
Bram Moolenaaradc21822011-04-01 18:03:16 +02003187 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 let b:netrw_method = 9
3191 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3192 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003193
Bram Moolenaaradc21822011-04-01 18:03:16 +02003194 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003195 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003197 let b:netrw_method = 1
3198 let userid = substitute(a:choice,rcphf,'\2',"")
3199 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3200 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003201" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3202" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3203" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3204" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003205 if userid != ""
3206 let g:netrw_uid= userid
3207 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003208
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003209 " Method#10: file://user@hostname/...path-to-file {{{3
3210 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003211" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003212 let b:netrw_method = 10
3213 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003214" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003215
Bram Moolenaaradc21822011-04-01 18:03:16 +02003216 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003217 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003218 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003219 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003220 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003223 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003224
Bram Moolenaar81695252004-12-29 20:58:21 +00003225 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 " remove any leading [:#] from port number
3227 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3228 elseif exists("netrw_port")
3229 " retain port number as implicit for subsequent ftp operations
3230 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003231 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003232
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003233" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3234" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3235" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3236" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003237" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003238" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003239" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003240" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003242" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003243" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003244" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246
3247" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003248" NetReadFixup: this sort of function is typically written by the user {{{2
3249" to handle extra junk that their system's ftp dumps
3250" into the transfer. This function is provided as an
3251" example and as a fix for a Windows 95 problem: in my
3252" experience, win95's ftp always dumped four blank lines
3253" at the end of the transfer.
3254if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3255 fun! NetReadFixup(method, line1, line2)
3256" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003257
3258 " sanity checks -- attempt to convert inputs to integers
3259 let method = a:method + 0
3260 let line1 = a:line1 + 0
3261 let line2 = a:line2 + 0
3262 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3263" call Dret("NetReadFixup")
3264 return
3265 endif
3266
Bram Moolenaar9964e462007-05-05 17:54:07 +00003267 if method == 3 " ftp (no <.netrc>)
3268 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003269 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003270 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003271 call histdel("/",-1)
3272 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003273 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003274
Bram Moolenaar9964e462007-05-05 17:54:07 +00003275" call Dret("NetReadFixup")
3276 endfun
3277endif
3278
3279" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003280" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003281" Usage: :call NetUserPass() -- will prompt for userid and password
3282" :call NetUserPass("uid") -- will prompt for password
3283" :call NetUserPass("uid","password") -- sets global userid and password
3284" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3285" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286fun! NetUserPass(...)
3287
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003288" call Dfunc("NetUserPass() a:0=".a:0)
3289
3290 if !exists('s:netrw_hup')
3291 let s:netrw_hup= {}
3292 endif
3293
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003295 " case: no input arguments
3296
3297 " change host and username if not previously entered; get new password
3298 if !exists("g:netrw_machine")
3299 let g:netrw_machine= input('Enter hostname: ')
3300 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003302 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 let g:netrw_uid= input('Enter username: ')
3304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003305 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003306 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003307
3308 " set up hup database
3309 let host = substitute(g:netrw_machine,'\..*$','','')
3310 if !exists('s:netrw_hup[host]')
3311 let s:netrw_hup[host]= {}
3312 endif
3313 let s:netrw_hup[host].uid = g:netrw_uid
3314 let s:netrw_hup[host].passwd = s:netrw_passwd
3315
3316 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003317 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003318
3319 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003320 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003321 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003323 let host = substitute(a:1,'^ftp:','','')
3324 let host = substitute(host,'\..*','','')
3325 if exists("s:netrw_hup[host]")
3326 let g:netrw_uid = s:netrw_hup[host].uid
3327 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003328" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3329" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003330 else
3331 let g:netrw_uid = input("Enter UserId: ")
3332 let s:netrw_passwd = inputsecret("Enter Password: ")
3333 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003334
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003335 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003336 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003337" call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003338 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003339 if g:netrw_machine =~ '[0-9.]\+'
3340 let host= g:netrw_machine
3341 else
3342 let host= substitute(g:netrw_machine,'\..*$','','')
3343 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003344 else
3345 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003346 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003347 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003348" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003349 if exists("g:netrw_passwd")
3350 " ask for password if one not previously entered
3351 let s:netrw_passwd= g:netrw_passwd
3352 else
3353 let s:netrw_passwd = inputsecret("Enter Password: ")
3354 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355 endif
3356
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003357" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003358 if exists("host")
3359 if !exists('s:netrw_hup[host]')
3360 let s:netrw_hup[host]= {}
3361 endif
3362 let s:netrw_hup[host].uid = g:netrw_uid
3363 let s:netrw_hup[host].passwd = s:netrw_passwd
3364 endif
3365
3366 elseif a:0 == 2
3367 let g:netrw_uid = a:1
3368 let s:netrw_passwd = a:2
3369
3370 elseif a:0 == 3
3371 " enter hostname, user-id, and password into the hup dictionary
3372 let host = substitute(a:1,'^\a\+:','','')
3373 let host = substitute(host,'\..*$','','')
3374 if !exists('s:netrw_hup[host]')
3375 let s:netrw_hup[host]= {}
3376 endif
3377 let s:netrw_hup[host].uid = a:2
3378 let s:netrw_hup[host].passwd = a:3
3379 let g:netrw_uid = s:netrw_hup[host].uid
3380 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3382" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003384
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003385" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387
Bram Moolenaar85850f32019-07-19 22:05:51 +02003388" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003389" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003390" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003392" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003393" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3394fun! s:ExplorePatHls(pattern)
3395" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3396 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003397" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003398 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003399" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003400 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3401" call Dret("s:ExplorePatHls repat<".repat.">")
3402 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003403endfun
3404
3405" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003406" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003407" 0: (user: <mb>) bookmark current directory
3408" 1: (user: <gb>) change to the bookmarked directory
3409" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003410" 3: (browsing) records current directory history
3411" 4: (user: <u>) go up (previous) directory, using history
3412" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003413" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003414fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003415" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhistcnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003416 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3417" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3418 return
3419 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003420
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003421 let ykeep = @@
3422 let curbufnr = bufnr("%")
3423
Bram Moolenaar9964e462007-05-05 17:54:07 +00003424 if a:chg == 0
3425 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003426" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003427 if exists("s:netrwmarkfilelist_{curbufnr}")
3428 call s:NetrwBookmark(0)
3429 echo "bookmarked marked files"
3430 else
3431 call s:MakeBookmark(a:curdir)
3432 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003433 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003434
3435 elseif a:chg == 1
3436 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003438 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003439" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003440 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003441 else
3442 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3443 endif
3444
3445 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003447 let didwork= 0
3448 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003449" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003450 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003452 let cnt= 1
3453 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003454" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003455 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003456 let didwork = 1
3457 let cnt = cnt + 1
3458 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003459 endif
3460
3461 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003462 " Note: history is saved only when PerformListing is done;
3463 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3464 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003465 let first = 1
3466 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003467 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003468 while ( first || cnt != g:netrw_dirhistcnt )
3469" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003470 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003471" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003472 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003473 let didwork= 1
3474 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003475 let histcnt = histcnt + 1
3476 let first = 0
3477 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003478 if cnt < 0
3479 let cnt= cnt + g:netrw_dirhistmax
3480 endif
3481 endwhile
3482 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003483 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003484 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003485 if didwork
3486 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3487 endif
3488
3489 elseif a:chg == 3
3490 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003491" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003492 if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003493 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003494 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3495 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003496 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003497" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003498 endif
3499
3500 elseif a:chg == 4
3501 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003503 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003504 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3505 if g:netrw_dirhistcnt < 0
3506 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003507 endif
3508 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003509 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003510 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003511 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3512" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003514 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003515" call Decho("setl ma noro",'~'.expand("<slnum>"))
3516 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003517 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003518" call Decho("setl nomod",'~'.expand("<slnum>"))
3519" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003520 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003521" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3522 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003524 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003525 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003526 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003527 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003529 echo "Sorry, no predecessor directory exists yet"
3530 endif
3531
3532 elseif a:chg == 5
3533 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003534" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003535 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3537 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3538" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003540" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003541 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542 sil! NetrwKeepj %d _
3543" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3544" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003545 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003546" call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003548" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3549 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3552 if g:netrw_dirhistcnt < 0
3553 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 endif
3555 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003560 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003561
3562 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003563" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003564 if exists("s:netrwmarkfilelist_{curbufnr}")
3565 call s:NetrwBookmark(1)
3566 echo "removed marked files from bookmarks"
3567 else
3568 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003569 let iremove = v:count
3570 let dremove = g:netrw_bookmarklist[iremove - 1]
3571" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003572 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3574 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3575 echo "removed ".dremove." from g:netrw_bookmarklist"
3576" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003578" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003579 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003580 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003581 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003582 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003583" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003584endfun
3585
3586" ---------------------------------------------------------------------
3587" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003588" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003589" Sister function: s:NetrwBookHistSave()
3590fun! s:NetrwBookHistRead()
3591" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003592 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003594 return
3595 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003596 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597
3598 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599 if !exists("s:netrw_initbookhist")
3600 let home = s:NetrwHome()
3601 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003602 if filereadable(s:NetrwFile(savefile))
3603" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003604 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003605 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606
3607 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 if g:netrw_dirhistmax > 0
3609 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003610 if filereadable(s:NetrwFile(savefile))
3611" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003612 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003613 endif
3614 let s:netrw_initbookhist= 1
3615 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003616 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003617 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618
Bram Moolenaar97d62492012-11-15 21:28:22 +01003619 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003620" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3621" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003622" call Dret("s:NetrwBookHistRead")
3623endfun
3624
3625" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003626" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003627" Sister function: s:NetrwBookHistRead()
3628" I used to do this via viminfo but that appears to
3629" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3631" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003632" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003633fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003634" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003635 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003636" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003637 return
3638 endif
3639
Bram Moolenaar5c736222010-01-06 20:54:52 +01003640 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642 1split
3643 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003645 if g:netrw_use_noswf
3646 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3647 else
3648 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3649 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003650 setl nocin noai noci magic nospell nohid wig= noaw
3651 setl ma noro write
3652 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003653 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003654
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655 " rename enew'd file: .netrwhist -- no attempt to merge
3656 " record dirhistmax and current dirhistcnt
3657 " save history
3658" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003659 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003660 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003661 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3662 if g:netrw_dirhistmax > 0
3663 let lastline = line("$")
3664 let cnt = g:netrw_dirhistcnt
3665 let first = 1
3666 while ( first || cnt != g:netrw_dirhistcnt )
3667 let lastline= lastline + 1
3668 if exists("g:netrw_dirhist_{cnt}")
3669 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3670" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3671 endif
3672 let first = 0
3673 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3674 if cnt < 0
3675 let cnt= cnt + g:netrw_dirhistmax
3676 endif
3677 endwhile
3678 exe "sil! w! ".savefile
3679" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3680 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003681
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003683 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003685" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003686 " merge and write .netrwbook
3687 let savefile= s:NetrwHome()."/.netrwbook"
3688
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003689 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003691 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692 for bdm in booklist
3693 if index(g:netrw_bookmarklist,bdm) == -1
3694 call add(g:netrw_bookmarklist,bdm)
3695 endif
3696 endfor
3697 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 endif
3699
3700 " construct and save .netrwbook
3701 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003702 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705
3706 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 let bgone= bufnr("%")
3708 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003709 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003710
3711" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003712endfun
3713
3714" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003715" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3716" list of the contents of a local or remote directory. It is assumed that the
3717" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3718" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003719" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003720fun! s:NetrwBrowse(islocal,dirname)
3721 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003722" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003723" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3724" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3725" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003726
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003727 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3728 " This is useful when one edits a local file, then :e ., then :Rex
3729 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3730 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003731" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003732 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003733
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003734 " s:NetrwBrowse : initialize history {{{3
3735 if !exists("s:netrw_initbookhist")
3736 NetrwKeepj call s:NetrwBookHistRead()
3737 endif
3738
3739 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003740 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 else
3744 let dirname= a:dirname
3745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003746
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747 " repoint t:netrw_lexbufnr if appropriate
3748 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3749" call Decho("set repointlexbufnr to true!")
3750 let repointlexbufnr= 1
3751 endif
3752
3753 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003754 if exists("s:netrw_skipbrowse")
3755 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003756" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003757" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003758 return
3759 endif
3760 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003761 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003762" call Dret("s:NetrwBrowse : missing shellescape()")
3763 return
3764 endif
3765 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003766 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767" call Dret("s:NetrwBrowse : missing fnameescape()")
3768 return
3769 endif
3770
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003771 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003772 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003773
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003774 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003775 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3776 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3777" call Decho("clearing marked files",'~'.expand("<slnum>"))
3778 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3779 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780 endif
3781
3782 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003783 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003784" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3785" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 if s:NetrwLcd(dirname)
3787" call Dret("s:NetrwBrowse : lcd failure")
3788 return
3789 endif
3790 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003791" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003792
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003794 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003795" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003796 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003797" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003798 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003799 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003800 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003801" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003802
3803 " remove any filetype indicator from end of dirname, except for the
3804 " "this is a directory" indicator (/).
3805 " There shouldn't be one of those here, anyway.
3806 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003807" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003808 call s:RemotePathAnalysis(dirname)
3809
3810 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3811 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003812 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003813 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003814" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003815 let b:netrw_curdir = dirname
3816 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003817 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003818 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3819 sil call netrw#NetRead(2,url)
3820 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003821" call Decho("url<".url.">",'~'.expand("<slnum>"))
3822" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3823" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 if s:path =~ '.bz2'
3825 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3826 elseif s:path =~ '.gz'
3827 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3828 elseif s:path =~ '.gz'
3829 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3830 else
3831 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3832 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003833 endif
3834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003837 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003838" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003840" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842" call Dret("s:NetrwBrowse : file<".s:fname.">")
3843 return
3844 endif
3845
Bram Moolenaaradc21822011-04-01 18:03:16 +02003846 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847 call s:UseBufWinVars()
3848
3849 " set up some variables {{{3
3850 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003851 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852 let s:last_sort_by = g:netrw_sort_by
3853
3854 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856
Bram Moolenaar97d62492012-11-15 21:28:22 +01003857 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003858" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003859 let svpos = winsaveview()
3860" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003862
Bram Moolenaar446cb832008-06-24 21:56:24 +00003863 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003864 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3865 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3866" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3867" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3868 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3869 else
3870" " call Decho("2match none",'~'.expand("<slnum>"))
3871 2match none
3872 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003873 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003874 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003875 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003877 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003878" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003880 return
3881 endif
3882
3883 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003884" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003885 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003886 if b:netrw_curdir =~ '[/\\]$'
3887 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3888 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003889 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3890 let b:netrw_curdir= b:netrw_curdir."/"
3891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003892 if b:netrw_curdir == ''
3893 if has("amiga")
3894 " On the Amiga, the empty string connotes the current directory
3895 let b:netrw_curdir= getcwd()
3896 else
3897 " under unix, when the root directory is encountered, the result
3898 " from the preceding substitute is an empty string.
3899 let b:netrw_curdir= '/'
3900 endif
3901 endif
3902 if !a:islocal && b:netrw_curdir !~ '/$'
3903 let b:netrw_curdir= b:netrw_curdir.'/'
3904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906
3907 " ------------
3908 " (local only) {{{3
3909 " ------------
3910 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003912
3913 " Set up ShellCmdPost handling. Append current buffer to browselist
3914 call s:LocalFastBrowser()
3915
3916 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3917 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3919" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003921 if s:NetrwLcd(b:netrw_curdir)
3922" call Dret("s:NetrwBrowse : lcd failure")
3923 return
3924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 endif
3926 endif
3927
3928 " --------------------------------
3929 " remote handling: {{{3
3930 " --------------------------------
3931 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003932" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933
Bram Moolenaar97d62492012-11-15 21:28:22 +01003934 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003936 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3940 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3941 if dirname !~ '/$'
3942 let dirname= dirname.'/'
3943 endif
3944 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003947 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 endif
3950
3951 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3952 if dirname !~ dirpat
3953 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003954 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003956 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003958 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003959" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3961 return
3962 endif
3963 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 endif " (additional remote handling)
3966
Bram Moolenaar85850f32019-07-19 22:05:51 +02003967 " -------------------------------
3968 " Perform Directory Listing: {{{3
3969 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003970 NetrwKeepj call s:NetrwMaps(a:islocal)
3971 NetrwKeepj call s:NetrwCommands(a:islocal)
3972 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003974 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003975 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003976" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3977
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978 " If there is a rexposn: restore position with rexposn
3979 " Otherwise : set rexposn
3980 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003981" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3982 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3983 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3984 NetrwKeepj exe w:netrw_bannercnt
3985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986 else
3987 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3988 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003989 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003990 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003992 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003993 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003994
Bram Moolenaar85850f32019-07-19 22:05:51 +02003995 " repoint t:netrw_lexbufnr if appropriate
3996 if exists("repointlexbufnr")
3997 let t:netrw_lexbufnr= bufnr("%")
3998" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
3999 endif
4000
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001 " restore position
4002 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004003" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4004 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004005 endif
4006
Bram Moolenaara6878372014-03-22 21:02:50 +01004007 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004008 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4009 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4011" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004012" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013 return
4014endfun
4015
4016" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004017" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4018" may not apply correctly; ie. netrw's idea of the current directory may
4019" differ from vim's. This function insures that netrw's idea of the current
4020" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004021" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004023" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4024" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4025" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4026" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4027" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004028
4029 " clean up any leading treedepthstring
4030 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4031 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004033 else
4034 let fname= a:fname
4035 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036
4037 if g:netrw_keepdir
4038 " vim's idea of the current directory possibly may differ from netrw's
4039 if !exists("b:netrw_curdir")
4040 let b:netrw_curdir= getcwd()
4041 endif
4042
4043 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004046 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004047" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004048 else
4049 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004050 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004051" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052 endif
4053
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004054 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004056 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004057" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004058 else
4059 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062 endif
4063 else
4064 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004066" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4067" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4068" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 endif
4070
Bram Moolenaar85850f32019-07-19 22:05:51 +02004071" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072 return ret
4073endfun
4074
4075" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076" s:NetrwFileInfo: supports qf (query for file information) {{{2
4077fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004078" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004079 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004080 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004081 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004082 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004083 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004084 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004085 let lsopt= "-lsadh --si"
4086 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004087 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004088
4089 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004090 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004091" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004092
Bram Moolenaara6878372014-03-22 21:02:50 +01004093 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004096
4097 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004099" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004100
Bram Moolenaar446cb832008-06-24 21:56:24 +00004101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004105 endif
4106 else
4107 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4109 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004110 let fname= substitute(a:fname,".$","","")
4111 else
4112 let fname= a:fname
4113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 let t = getftime(s:NetrwFile(fname))
4115 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004116 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 let sz= s:NetrwHumanReadable(sz)
4118 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4120" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004121 endif
4122 else
4123 echo "sorry, \"qf\" not supported yet for remote files"
4124 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004125 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004126" call Dret("s:NetrwFileInfo")
4127endfun
4128
4129" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004130" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4131fun! s:NetrwFullPath(filename)
4132" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4133 let filename= a:filename
4134 if filename !~ '^/'
4135 let filename= resolve(getcwd().'/'.filename)
4136 endif
4137 if filename != "/" && filename =~ '/$'
4138 let filename= substitute(filename,'/$','','')
4139 endif
4140" " call Dret("s:NetrwFullPath <".filename.">")
4141 return filename
4142endfun
4143
4144" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004145" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004146" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004147" 1=re-used buffer (buffer not cleared)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148fun! s:NetrwGetBuffer(islocal,dirname)
4149" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004150" 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,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004151" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4152" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 let dirname= a:dirname
4154
4155 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004157 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004158" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004159 let s:netrwbuf= {}
4160 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004161" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4162" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4163
4164 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4165 let bufnum = -1
4166
4167 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4168 if has_key(s:netrwbuf,"NetrwTreeListing")
4169 let bufnum= s:netrwbuf["NetrwTreeListing"]
4170 else
4171 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4172 endif
4173" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4174 if !bufexists(bufnum)
4175 call remove(s:netrwbuf,"NetrwTreeListing"])
4176 let bufnum= -1
4177 endif
4178 elseif bufnr("NetrwTreeListing") != -1
4179 let bufnum= bufnr("NetrwTreeListing")
4180" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4181 else
4182" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4183 let bufnum= -1
4184 endif
4185
4186 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004187 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004188" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004189 if !bufexists(bufnum)
4190 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4191 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004193
Bram Moolenaar446cb832008-06-24 21:56:24 +00004194 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004195" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004196 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004197 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004198" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4199
4200 " highjack the current buffer if
4201 " it has the desired name
4202 " it is empty
4203" call Decho("deciding if I can highjack the current buffer#".bufnr("%"),'~'.expand("<slnum>"))
4204" call Decho("..dirname<".dirname.">",'~'.expand("<slnum>"))
4205" call Decho("..bufname<".bufname("%").">",'~'.expand("<slnum>"))
4206" call Decho("..getline($)<".getline("$").">",'~'.expand("<slnum>"))
4207 if dirname == bufname("%") && line("$") == 1 && getline("%") == ""
4208" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4209 return 0
4210 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211
4212 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004213 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004214" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004217 " name the buffer
4218 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4219 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004220" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004221 let w:netrw_treebufnr = bufnr("%")
4222 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004223 if g:netrw_use_noswf
4224 setl nobl bt=nofile noswf
4225 else
4226 setl nobl bt=nofile
4227 endif
4228 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4229 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4230 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4231 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004232" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004233 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004234 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004235 " enter the new buffer into the s:netrwbuf dictionary
4236 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4237" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4238" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004239 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004240" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004241
4242 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004243" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004244 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004245 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004246 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004247" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4248 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004249 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004250" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4251 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004253" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004256 endif
4257 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004258
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004259 if line("$") <= 1 && getline(1) == ""
4260 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004261 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004262" 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,'~'.expand("<slnum>"))
4263" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004264" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4265 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004266
Bram Moolenaar97d62492012-11-15 21:28:22 +01004267 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004268" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004269 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004270 sil NetrwKeepj %d _
4271" 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,'~'.expand("<slnum>"))
4272" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004273" 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 +00004274 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004275
Bram Moolenaar446cb832008-06-24 21:56:24 +00004276 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004277" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4278" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004279 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004280 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004281 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004282" 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,'~'.expand("<slnum>"))
4283" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004284" 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 +00004285 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004286
Bram Moolenaar446cb832008-06-24 21:56:24 +00004287 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" 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,'~'.expand("<slnum>"))
4289" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4290" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 return 1
4292 endif
4293 endif
4294
4295 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4296 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4297 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4298 " med 1 D H
4299 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004300" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004302 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004303 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304
4305 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004306" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4307" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4308 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" 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,'~'.expand("<slnum>"))
4311" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4312" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 return 0
4314endfun
4315
4316" ---------------------------------------------------------------------
4317" s:NetrwGetcwd: get the current directory. {{{2
4318" Change backslashes to forward slashes, if any.
4319" If doesc is true, escape certain troublesome characters
4320fun! s:NetrwGetcwd(doesc)
4321" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4322 let curdir= substitute(getcwd(),'\\','/','ge')
4323 if curdir !~ '[\/]$'
4324 let curdir= curdir.'/'
4325 endif
4326 if a:doesc
4327 let curdir= fnameescape(curdir)
4328 endif
4329" call Dret("NetrwGetcwd <".curdir.">")
4330 return curdir
4331endfun
4332
4333" ---------------------------------------------------------------------
4334" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4335fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4337" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4338 let keepsol= &l:sol
4339 setl nosol
4340
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 call s:UseBufWinVars()
4342
4343 " insure that w:netrw_liststyle is set up
4344 if !exists("w:netrw_liststyle")
4345 if exists("g:netrw_liststyle")
4346 let w:netrw_liststyle= g:netrw_liststyle
4347 else
4348 let w:netrw_liststyle= s:THINLIST
4349 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351 endif
4352
4353 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4354 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004356 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 let dirname= "./"
4358 let curline= getline('.')
4359
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004360 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004361 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004362 let s:netrw_skipbrowse= 1
4363 echo 'Pressing "s" also works'
4364
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004365 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 let s:netrw_skipbrowse= 1
4367 echo 'Press "S" to edit sorting sequence'
4368
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004369 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004370 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004373 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004374 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 let s:netrw_skipbrowse= 1
4376 echo 'Pressing "a" also works'
4377
4378 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380 endif
4381
4382 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj norm! 0
4385 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
4387 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004388" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004389 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4391
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004392 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004393" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004394 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004395 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004396
4397 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004398" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399 let dirname= getline('.')
4400
4401 if !exists("b:netrw_cpf")
4402 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004403 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 +01004404 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004405" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406 endif
4407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004408" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004409 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004410" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4411" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004413 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004414 else
4415 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004416 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004417 endif
4418 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004419 let eofname= filestart + b:netrw_cpf + 1
4420 if eofname <= col("$")
4421 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004422 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004423 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004424 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004425 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 let dirname = @a
4427 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004428" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004429 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004430" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 endif
4432
4433 " symlinks are indicated by a trailing "@". Remove it before further processing.
4434 let dirname= substitute(dirname,"@$","","")
4435
4436 " executables are indicated by a trailing "*". Remove it before further processing.
4437 let dirname= substitute(dirname,"\*$","","")
4438
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004439 let &l:sol= keepsol
4440
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441" call Dret("s:NetrwGetWord <".dirname.">")
4442 return dirname
4443endfun
4444
4445" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004446" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4447" g:netrw_bufsettings will be used after the listing is produced.
4448" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449fun! s:NetrwListSettings(islocal)
4450" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004451" 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,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004453" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4454 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4455 setl bt=nofile nobl ma nonu nowrap noro nornu
4456 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004458 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004460" call Dredir("ls!","s:NetrwListSettings")
4461" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004462 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004463 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004465 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004467 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004469" 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,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004470" call Dret("s:NetrwListSettings")
4471endfun
4472
4473" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004474" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475" islocal=0: remote browsing
4476" =1: local browsing
4477fun! s:NetrwListStyle(islocal)
4478" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004479
Bram Moolenaar97d62492012-11-15 21:28:22 +01004480 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 let fname = s:NetrwGetWord()
4482 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004483 let svpos = winsaveview()
4484" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4487" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4488" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489
Bram Moolenaar85850f32019-07-19 22:05:51 +02004490 " repoint t:netrw_lexbufnr if appropriate
4491 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4492" call Decho("set repointlexbufnr to true!")
4493 let repointlexbufnr= 1
4494 endif
4495
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 if w:netrw_liststyle == s:THINLIST
4497 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004498" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4500
4501 elseif w:netrw_liststyle == s:LONGLIST
4502 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004503" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4505
4506 elseif w:netrw_liststyle == s:WIDELIST
4507 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004508" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4510
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004511 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4514
4515 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004516 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 let g:netrw_liststyle = s:THINLIST
4518 let w:netrw_liststyle = g:netrw_liststyle
4519 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4520 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004521 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523
4524 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4526 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004527 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004528" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004529 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004530" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531
4532 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004533" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004534 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4535 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536
Bram Moolenaar85850f32019-07-19 22:05:51 +02004537 " repoint t:netrw_lexbufnr if appropriate
4538 if exists("repointlexbufnr")
4539 let t:netrw_lexbufnr= bufnr("%")
4540" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4541 endif
4542
Bram Moolenaar13600302014-05-22 18:26:40 +02004543 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004544" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4545 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004546 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547
4548" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4549endfun
4550
4551" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004552" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4553fun! s:NetrwBannerCtrl(islocal)
4554" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4555
Bram Moolenaar97d62492012-11-15 21:28:22 +01004556 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004557 " toggle the banner (enable/suppress)
4558 let g:netrw_banner= !g:netrw_banner
4559
4560 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004561 let svpos= winsaveview()
4562" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004563 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4564
4565 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004566 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4567 let fname= s:NetrwGetWord()
4568 sil NetrwKeepj $
4569 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4570" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4571 if result <= 0 && exists("w:netrw_bannercnt")
4572 exe "NetrwKeepj ".w:netrw_bannercnt
4573 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004574 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004575 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004576" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4577endfun
4578
4579" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004580" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4581"
4582" No bang: enters files/directories into Netrw's bookmark system
4583" No argument and in netrw buffer:
4584" if there are marked files: bookmark marked files
4585" otherwise : bookmark file/directory under cursor
4586" No argument and not in netrw buffer: bookmarks current open file
4587" Has arguments: globs them individually and bookmarks them
4588"
4589" With bang: deletes files/directories from Netrw's bookmark system
4590fun! s:NetrwBookmark(del,...)
4591" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4592 if a:0 == 0
4593 if &ft == "netrw"
4594 let curbufnr = bufnr("%")
4595
4596 if exists("s:netrwmarkfilelist_{curbufnr}")
4597 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004598" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004599 let svpos = winsaveview()
4600" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004602 for fname in s:netrwmarkfilelist_{curbufnr}
4603 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4604 endfor
4605 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4606 call s:NetrwUnmarkList(curbufnr,curdir)
4607 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004608" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4609 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004610 else
4611 let fname= s:NetrwGetWord()
4612 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4613 endif
4614
4615 else
4616 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004618 let fname= expand("%")
4619 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4620 endif
4621
4622 else
4623 " bookmark specified files
4624 " attempts to infer if working remote or local
4625 " by deciding if the current file begins with an url
4626 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004627 let islocal= expand("%") !~ '^\a\{3,}://'
4628" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004629 let i = 1
4630 while i <= a:0
4631 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004632 if v:version > 704 || (v:version == 704 && has("patch656"))
4633 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004634 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004635 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004636 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004637 else
4638 let mbfiles= [a:{i}]
4639 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004640" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004641 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004642" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004643 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4644 endfor
4645 let i= i + 1
4646 endwhile
4647 endif
4648
4649 " update the menu
4650 call s:NetrwBookmarkMenu()
4651
4652" call Dret("s:NetrwBookmark")
4653endfun
4654
4655" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004656" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4657" .2.[cnt] for bookmarks, and
4658" .3.[cnt] for history
4659" (see s:NetrwMenu())
4660fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004661 if !exists("s:netrw_menucnt")
4662 return
4663 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004664" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004665
4666 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004667 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004668 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004669" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004670 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4671 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004672 endif
4673 if !exists("s:netrw_initbookhist")
4674 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004675 endif
4676
4677 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004678 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004679 let cnt= 1
4680 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004681" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004682 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004683
4684 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004685 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004686
4687 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004688 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 +01004689 let cnt= cnt + 1
4690 endfor
4691
4692 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004693
4694 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004695 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004696 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004697 let first = 1
4698 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004699 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004700 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004701 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004702 if exists("g:netrw_dirhist_{cnt}")
4703 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004704" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004705 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4706 endif
4707 let first = 0
4708 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4709 if cnt < 0
4710 let cnt= cnt + g:netrw_dirhistmax
4711 endif
4712 endwhile
4713 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004714
Bram Moolenaar9964e462007-05-05 17:54:07 +00004715 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004716" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004717endfun
4718
4719" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004720" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4721" directory and a new directory name. Also, if the
4722" "new directory name" is actually a file,
4723" NetrwBrowseChgDir() edits the file.
4724fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4725" 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 Moolenaara0f849e2015-10-30 14:37:44 +01004726" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004727
Bram Moolenaar97d62492012-11-15 21:28:22 +01004728 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004729 if !exists("b:netrw_curdir")
4730 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4731 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004732 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004733" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4734" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004735" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004736" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004737 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004738 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004739" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740
Bram Moolenaar97d62492012-11-15 21:28:22 +01004741 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004742" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004743 call s:SavePosn(s:netrw_posn)
4744 NetrwKeepj call s:NetrwOptionsSave("s:")
4745 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004746 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004747 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004748 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004749 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004750 endif
4751 let newdir = a:newdir
4752 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004753 let dorestore = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004755" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004756
4757 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004758" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004759 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004761 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004762 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" 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.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004764 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004765" 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.">)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004766 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004767 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004768 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004769 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004770" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004771 endif
4772 endif
4773" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004774" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004775 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776
Bram Moolenaar446cb832008-06-24 21:56:24 +00004777 " set up o/s-dependent directory recognition pattern
4778 if has("amiga")
4779 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004780 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004781 let dirpat= '[\/]$'
4782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004783" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004784
4785 if dirname !~ dirpat
4786 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004788 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004789" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004790 endif
4791
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004792" call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004793 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004794 " ------------------------------
4795 " NetrwBrowseChgDir: edit a file {{{3
4796 " ------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004797" call Decho('(s:NetrwBrowseChgDir) edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004798
Bram Moolenaar97d62492012-11-15 21:28:22 +01004799 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004800 let s:rexposn_{bufnr("%")}= winsaveview()
4801" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4803" 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.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004804
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004806" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4807" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004808 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004809 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4810" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4811 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812 if dirname =~ '/$'
4813 let dirname= dirname.newdir
4814 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004815 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004817" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4818" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004820" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004824 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004825" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004826 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004827 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004828" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004829 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004830 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004831 if !exists("s:didsplit")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004832" call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004833 if type(g:netrw_browse_split) == 3
4834 " open file in server
4835 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004836" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004837 call s:NetrwServerEdit(a:islocal,dirname)
4838" call Dret("s:NetrwBrowseChgDir")
4839 return
4840 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004841 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004842" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004843 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004844 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004845 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004846 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004847 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004849 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004851 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004852 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004853 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004854 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004855 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004857 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004859 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004860 if !exists("b:netrw_curdir")
4861 let b:netrw_curdir= getcwd()
4862 endif
4863 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004865 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004868 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004870 return
4871 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004872 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004873 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004875" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 call s:NetrwMenu(0)
4877 " optional change to window
4878 if g:netrw_chgwin >= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879" call Decho("edit-a-file: changing window to #".g:netrw_chgwin,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004880 if winnr("$")+1 == g:netrw_chgwin
4881 " if g:netrw_chgwin is set to one more than the last window, then
4882 " vertically split the last window to make that window available.
4883 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004885 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004886 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004887 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004888 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004889 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004890 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004891 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004892 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004893
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 " the point where netrw actually edits the (local) file
4895 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004896 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004898" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004899 " some like c-^ to return to the last edited file
4900 " others like c-^ to return to the netrw buffer
4901 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004902 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004903 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004904 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004906" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004907 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004908 if &hidden || &bufhidden == "hide"
4909 " file came from vim's hidden storage. Don't "restore" options with it.
4910 let dorestore= 0
4911 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004912 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004914 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004916
4917 " handle g:Netrw_funcref -- call external-to-netrw functions
4918 " This code will handle g:Netrw_funcref as an individual function reference
4919 " or as a list of function references. It will ignore anything that's not
4920 " a function reference. See :help Funcref for information about function references.
4921 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004923 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004924" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004925 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004926 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928 for Fncref in g:Netrw_funcref
4929 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004930 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004931 endif
4932 endfor
4933 endif
4934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935 endif
4936
4937 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004938 " ----------------------------------------------------
4939 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4940 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004942 let dirname = newdir
4943 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004944 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946
4947 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004948 " ---------------------------------------------
4949 " NetrwBrowseChgDir: refresh the directory list {{{3
4950 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004951" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004952 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004953 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004954
4955 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 " --------------------------------------
4957 " NetrwBrowseChgDir: go up one directory {{{3
4958 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004959" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960
4961 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4962 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004963" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4964" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004965 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004966 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004967 endif
4968
4969 if has("amiga")
4970 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004971" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 if a:islocal
4973 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4974 let dirname= substitute(dirname,'/$','','')
4975 else
4976 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4977 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004979
Bram Moolenaar8d043172014-01-23 14:24:41 +01004980 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4981 " windows
4982 if a:islocal
4983 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4984 if dirname == ""
4985 let dirname= '/'
4986 endif
4987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004988 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004989 endif
4990 if dirname =~ '^\a:$'
4991 let dirname= dirname.'/'
4992 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004993" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004994
Bram Moolenaar446cb832008-06-24 21:56:24 +00004995 else
4996 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02004997" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 if a:islocal
4999 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5000 if dirname == ""
5001 let dirname= '/'
5002 endif
5003 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005004 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005007 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005008 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005009 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005010
5011 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005012 " --------------------------------------
5013 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5014 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005015" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5017" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005018 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005019 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5021 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005022 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005023 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005024" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005025 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005026 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005027" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005028
5029 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005030" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005031 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005032" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 let haskey= 1
5034 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005035" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
5037
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005039" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005040 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005041 if has_key(w:netrw_treedict,treedir."/")
5042 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005043" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044 let haskey = 1
5045 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005046" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047 endif
5048 endif
5049
5050 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005051" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052 if !haskey && treedir =~ '/$'
5053 let treedir= substitute(treedir,'/$','','')
5054 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005055" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056 let haskey = 1
5057 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005058" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005059 endif
5060 endif
5061
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005062" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005063 if haskey
5064 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005065" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5068" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005069 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070 else
5071 " go down one directory
5072 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005073" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5074" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005075 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005076 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005078 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079
5080 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005081 " ----------------------------------------
5082 " NetrwBrowseChgDir: Go down one directory {{{3
5083 " ----------------------------------------
5084 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005086 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005087 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005088 endif
5089
Bram Moolenaar97d62492012-11-15 21:28:22 +01005090 " --------------------------------------
5091 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5092 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005093 if dorestore
5094 " dorestore is zero'd when a local file was hidden or bufhidden;
5095 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005097 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005098" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005100 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005101 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005103 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005104" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5105" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005106 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005107" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5110" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005111 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005113 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005114 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005115 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005116 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005117
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5119 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005120endfun
5121
5122" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005123" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5124" for thin, long, and wide: cursor placed just after banner
5125" for tree, keeps cursor on current filename
5126fun! s:NetrwBrowseUpDir(islocal)
5127" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005128 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5129 " this test needed because occasionally this function seems to be incorrectly called
5130 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005131 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005132 " directories.
5133" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5134 return
5135 endif
5136
Bram Moolenaara6878372014-03-22 21:02:50 +01005137 norm! 0
5138 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005140 let curline= getline(".")
5141 let swwline= winline() - 1
5142 if exists("w:netrw_treetop")
5143 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144 elseif exists("b:netrw_curdir")
5145 let w:netrw_treetop= b:netrw_curdir
5146 else
5147 let w:netrw_treetop= getcwd()
5148 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005149 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005150 let curfile = getline(".")
5151 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005152 if a:islocal
5153 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5154 else
5155 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5156 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005157" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5158" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5159 if w:netrw_treetop == '/'
5160 keepj call search('^\M'.curfile,"w")
5161 elseif curfile == '../'
5162 keepj call search('^\M'.curfile,"wb")
5163 else
5164" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5165 while 1
5166 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5167 let treepath= s:NetrwTreePath(w:netrw_treetop)
5168" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5169 if treepath == curpath
5170 break
5171 endif
5172 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005173 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005174
Bram Moolenaara6878372014-03-22 21:02:50 +01005175 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005176" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005177 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178 if exists("b:netrw_curdir")
5179 let curdir= b:netrw_curdir
5180 else
5181 let curdir= expand(getcwd())
5182 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005183 if a:islocal
5184 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5185 else
5186 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5187 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 call s:RestorePosn(s:netrw_posn)
5189 let curdir= substitute(curdir,'^.*[\/]','','')
5190 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005191 endif
5192" call Dret("s:NetrwBrowseUpDir")
5193endfun
5194
5195" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005196" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005197" given filename; typically this means given their extension.
5198" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005199fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005200 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005201" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005202
Bram Moolenaar91359012019-11-30 17:57:03 +01005203 if a:remote == 0 && isdirectory(a:fname)
5204 " if its really just a local directory, then do a "gf" instead
5205" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005206" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5207 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005208" call Dret("netrw#BrowseX")
5209 return
5210 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5211 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5212" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5213" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5214" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5215" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5216 norm! gf
5217" call Dret("netrw#BrowseX")
5218 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005219 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005220" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005221
Bram Moolenaar97d62492012-11-15 21:28:22 +01005222 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005223 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005224" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005225
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005226 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5227 let awkeep = &aw
5228 set noaw
5229
Bram Moolenaar5c736222010-01-06 20:54:52 +01005230 " special core dump handler
5231 if a:fname =~ '/core\(\.\d\+\)\=$'
5232 if exists("g:Netrw_corehandler")
5233 if type(g:Netrw_corehandler) == 2
5234 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005235" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005237 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005238 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005239" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005240 for Fncref in g:Netrw_corehandler
5241 if type(FncRef) == 2
5242 call FncRef(a:fname)
5243 endif
5244 endfor
5245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005247 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005248 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005249 let &aw= awkeep
5250" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005251 return
5252 endif
5253 endif
5254
Bram Moolenaar446cb832008-06-24 21:56:24 +00005255 " set up the filename
5256 " (lower case the extension, make a local copy of a remote file)
5257 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5258 if has("win32") || has("win95") || has("win64") || has("win16")
5259 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005261 if exten =~ "[\\/]"
5262 let exten= ""
5263 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005264" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005265
Bram Moolenaar446cb832008-06-24 21:56:24 +00005266 if a:remote == 1
5267 " create a local copy
Bram Moolenaar46973992017-12-14 19:56:46 +01005268" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005269 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005270 call netrw#NetRead(3,a:fname)
5271 " attempt to rename tempfile
5272 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005273 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005274" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5275" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005276 if s:netrw_tmpfile != newname && newname != ""
5277 if rename(s:netrw_tmpfile,newname) == 0
5278 " renaming succeeded
5279" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5280 let fname= newname
5281 else
5282 " renaming failed
5283" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5284 let fname= s:netrw_tmpfile
5285 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005286 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005287 let fname= s:netrw_tmpfile
5288 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005289 else
Bram Moolenaar46973992017-12-14 19:56:46 +01005290" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005291 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005292 " special ~ handler for local
5293 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005294" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5295 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005296 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005297 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005298" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5299" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005300
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005301 " set up redirection (avoids browser messages)
5302 " by default, g:netrw_suppress_gx_mesg is true
5303 if g:netrw_suppress_gx_mesg
5304 if &srr =~ "%s"
5305 if (has("win32") || has("win95") || has("win64") || has("win16"))
5306 let redir= substitute(&srr,"%s","nul","")
5307 else
5308 let redir= substitute(&srr,"%s","/dev/null","")
5309 endif
5310 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5311 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005312 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005313 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005314 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005315 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005316" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005317
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005318 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005319 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005320" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005321 if g:netrw_browsex_viewer =~ '\s'
5322 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5323 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5324 let oviewer = ''
5325 let cnt = 1
5326 while !executable(viewer) && viewer != oviewer
5327 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5328 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5329 let cnt = cnt + 1
5330 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005331" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005332 endwhile
5333 else
5334 let viewer = g:netrw_browsex_viewer
5335 let viewopt = ""
5336 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005338 endif
5339
5340 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005341" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005342 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005343" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005344 let ret= netrwFileHandlers#Invoke(exten,fname)
5345
5346 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005347" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005348 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005349 let ret= v:shell_error
5350
5351 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005352" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005354 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005355 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005356 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005357 else
5358 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5359 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005360 let ret= v:shell_error
5361
Bram Moolenaar97d62492012-11-15 21:28:22 +01005362 elseif has("win32unix")
5363 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005364" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005365 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005366" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005367 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005368 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005369" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005370 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005371 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005372" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005373 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005374 else
5375 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5376 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005377 let ret= v:shell_error
5378
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005379 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005380" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005381 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005382 let ret= v:shell_error
5383
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005384 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005385" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005386 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir)
5387 let ret= v:shell_error
5388
Bram Moolenaar85850f32019-07-19 22:05:51 +02005389 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005390" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5391 if a:fname =~ '^https\=://'
5392 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5393 let use_ctrlo= 0
5394" call Decho("(COMBAK) fname<".fname.">")
5395" call Decho("(COMBAK) a:fname<".a:fname.">")
5396 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5397
5398 else
5399 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5400 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005401 let ret= v:shell_error
5402
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005403 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005404" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005405 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005406 let ret= v:shell_error
5407
5408 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005409" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005410 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005411 let ret= v:shell_error
5412
5413 else
5414 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005415" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 let ret= netrwFileHandlers#Invoke(exten,fname)
5417 endif
5418
5419 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5420 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005421" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 let ret= netrwFileHandlers#Invoke(exten,fname)
5423 endif
5424
Bram Moolenaarc236c162008-07-13 17:41:49 +00005425 " restoring redraw! after external file handlers
5426 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427
5428 " cleanup: remove temporary file,
5429 " delete current buffer if success with handler,
5430 " return to prior buffer (directory listing)
5431 " Feb 12, 2008: had to de-activiate removal of
5432 " temporary file because it wasn't getting seen.
5433" if a:remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005434"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005435" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436" endif
5437
5438 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005439 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005441 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005443 if use_ctrlo
5444 exe "sil! NetrwKeepj norm! \<c-o>"
5445 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005447" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005448 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005449 let @@ = ykeep
5450 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005452" call Dret("netrw#BrowseX")
5453endfun
5454
5455" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005456" netrw#GX: gets word under cursor for gx support {{{2
5457" See also: netrw#BrowseXVis
5458" netrw#BrowseX
5459fun! netrw#GX()
5460" call Dfunc("netrw#GX()")
5461 if &ft == "netrw"
5462 let fname= s:NetrwGetWord()
5463 else
5464 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5465 endif
5466" call Dret("netrw#GX <".fname.">")
5467 return fname
5468endfun
5469
5470" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005471" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5472fun! netrw#BrowseXVis()
5473" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005474 let akeep = @a
5475 norm! gv"ay
5476 let gxfile= @a
5477 let @a = akeep
5478 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005479" call Dret("netrw#BrowseXVis")
5480endfun
5481
5482" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005483" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5484" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5485" to become an unlisted buffer, so in that case don't bwipe it.
5486fun! s:NetrwBufRename(newname)
5487" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5488" call Dredir("ls!","s:NetrwBufRename (before rename)")
5489 let oldbufname= bufname(bufnr("%"))
5490" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5491
5492 if oldbufname != a:newname
5493" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5494 let b:junk= 1
5495" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5496 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
5497" call Dredir("ls!","s:NetrwBufRename (before bwipe)")
5498 let oldbufnr= bufnr(oldbufname)
5499" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5500" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5501 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5502" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5503 exe "bwipe! ".oldbufnr
5504" else " Decho
5505" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
5506 endif
5507" call Dredir("ls!","s:NetrwBufRename (after rename)")
5508" else " Decho
5509" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5510 endif
5511
5512" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5513endfun
5514
5515" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005516" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005517fun! netrw#CheckIfRemote(...)
5518" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5519 if a:0 > 0
5520 let curfile= a:1
5521 else
5522 let curfile= expand("%")
5523 endif
5524" call Decho("curfile<".curfile.">")
5525 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005526" call Dret("netrw#CheckIfRemote 1")
5527 return 1
5528 else
5529" call Dret("netrw#CheckIfRemote 0")
5530 return 0
5531 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005532endfun
5533
5534" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005535" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5536fun! s:NetrwChgPerm(islocal,curdir)
5537" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005538 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005539 call inputsave()
5540 let newperm= input("Enter new permission: ")
5541 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005542 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5543 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5544" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005545 call system(chgperm)
5546 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005547 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005548 endif
5549 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005551 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005552 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005553" call Dret("s:NetrwChgPerm")
5554endfun
5555
5556" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005557" s:CheckIfKde: checks if kdeinit is running {{{2
5558" Returns 0: kdeinit not running
5559" 1: kdeinit is running
5560fun! s:CheckIfKde()
5561" call Dfunc("s:CheckIfKde()")
5562 " seems kde systems often have gnome-open due to dependencies, even though
5563 " gnome-open's subsidiary display tools are largely absent. Kde systems
5564 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5565 if !exists("s:haskdeinit")
5566 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005567 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005568 if v:shell_error
5569 let s:haskdeinit = 0
5570 endif
5571 else
5572 let s:haskdeinit= 0
5573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005574" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005575 endif
5576
5577" call Dret("s:CheckIfKde ".s:haskdeinit)
5578 return s:haskdeinit
5579endfun
5580
5581" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005582" s:NetrwClearExplore: clear explore variables (if any) {{{2
5583fun! s:NetrwClearExplore()
5584" call Dfunc("s:NetrwClearExplore()")
5585 2match none
5586 if exists("s:explore_match") |unlet s:explore_match |endif
5587 if exists("s:explore_indx") |unlet s:explore_indx |endif
5588 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5589 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5590 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5591 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5592 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5593 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5594 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5595" redraw!
5596 echo " "
5597 echo " "
5598" call Dret("s:NetrwClearExplore")
5599endfun
5600
5601" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005602" s:NetrwExploreListUniq: {{{2
5603fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005604" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005605
5606 " this assumes that the list is already sorted
5607 let newexplist= []
5608 for member in a:explist
5609 if !exists("uniqmember") || member != uniqmember
5610 let uniqmember = member
5611 let newexplist = newexplist + [ member ]
5612 endif
5613 endfor
5614
Bram Moolenaar15146672011-10-20 22:22:38 +02005615" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005616 return newexplist
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005620" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5621fun! s:NetrwForceChgDir(islocal,newdir)
5622" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005623 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005624 if a:newdir !~ '/$'
5625 " ok, looks like force is needed to get directory-style treatment
5626 if a:newdir =~ '@$'
5627 let newdir= substitute(a:newdir,'@$','/','')
5628 elseif a:newdir =~ '[*=|\\]$'
5629 let newdir= substitute(a:newdir,'.$','/','')
5630 else
5631 let newdir= a:newdir.'/'
5632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005633" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005634 else
5635 " should already be getting treatment as a directory
5636 let newdir= a:newdir
5637 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005638 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005639 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005640 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005641" call Dret("s:NetrwForceChgDir")
5642endfun
5643
5644" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005645" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005646" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5647" expr : this is the expression to follow the directory. Will use s:ComposePath()
5648" pare =1: remove the current directory from the resulting glob() filelist
5649" =0: leave the current directory in the resulting glob() filelist
5650fun! s:NetrwGlob(direntry,expr,pare)
5651" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005652 if netrw#CheckIfRemote()
5653 keepalt 1sp
5654 keepalt enew
5655 let keep_liststyle = w:netrw_liststyle
5656 let w:netrw_liststyle = s:THINLIST
5657 if s:NetrwRemoteListing() == 0
5658 keepj keepalt %s@/@@
5659 let filelist= getline(1,$)
5660 q!
5661 else
5662 " remote listing error -- leave treedict unchanged
5663 let filelist= w:netrw_treedict[a:direntry]
5664 endif
5665 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005666 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5667 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5668 if a:pare
5669 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5670 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005671 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005672 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5673 if a:pare
5674 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5675 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005676 endif
5677" call Dret("s:NetrwGlob ".string(filelist))
5678 return filelist
5679endfun
5680
5681" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005682" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5683fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005684" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005685 if a:newfile =~ '[/@*=|\\]$'
5686 let newfile= substitute(a:newfile,'.$','','')
5687 else
5688 let newfile= a:newfile
5689 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005690 if a:islocal
5691 call s:NetrwBrowseChgDir(a:islocal,newfile)
5692 else
5693 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5694 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005695" call Dret("s:NetrwForceFile")
5696endfun
5697
5698" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005699" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5700" and switches the hiding mode. The actual hiding is done by
5701" s:NetrwListHide().
5702" g:netrw_hide= 0: show all
5703" 1: show not-hidden files
5704" 2: show hidden files only
5705fun! s:NetrwHide(islocal)
5706" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005707 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005708 let svpos= winsaveview()
5709" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005710
5711 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005712" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5713" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005714
5715 " hide the files in the markfile list
5716 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005717" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005718 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5719 " remove fname from hiding list
5720 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5721 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5722 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005723" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005724 else
5725 " append fname to hiding list
5726 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5727 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5728 else
5729 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5730 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005731" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005732 endif
5733 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005734 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005735 let g:netrw_hide= 1
5736
5737 else
5738
5739 " switch between show-all/show-not-hidden/show-hidden
5740 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005741 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005742 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005743 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005744 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005745" call Dret("NetrwHide")
5746 return
5747 endif
5748 endif
5749
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005750 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005751" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5752 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005753 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005754" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005755endfun
5756
5757" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005758" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5759fun! s:NetrwHideEdit(islocal)
5760" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5761
5762 let ykeep= @@
5763 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005764 let svpos= winsaveview()
5765" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005766
5767 " get new hiding list from user
5768 call inputsave()
5769 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5770 call inputrestore()
5771 let g:netrw_list_hide= newhide
5772" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5773
5774 " refresh the listing
5775 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5776
5777 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005778" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5779 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005780 let @@= ykeep
5781
5782" call Dret("NetrwHideEdit")
5783endfun
5784
5785" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005786" s:NetrwHidden: invoked by "gh" {{{2
5787fun! s:NetrwHidden(islocal)
5788" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005789 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005790 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005791 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005792" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005793
5794 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005795 " remove .file pattern from hiding list
5796" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005797 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005798 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005799" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005800 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5801 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005802" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005803 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5804 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005805 if g:netrw_list_hide =~ '^,'
5806 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5807 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005808
5809 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005810 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005811" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5812 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005813 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005814" call Dret("s:NetrwHidden")
5815endfun
5816
5817" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005818" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5819fun! s:NetrwHome()
5820 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005821 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005822 else
5823 " go to vim plugin home
5824 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005825 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005826 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005827 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005828 let home= basehome."/.vim"
5829 break
5830 endif
5831 endfor
5832 if home == ""
5833 " just pick the first directory
5834 let home= substitute(&rtp,',.*$','','')
5835 endif
5836 if (has("win32") || has("win95") || has("win64") || has("win16"))
5837 let home= substitute(home,'/','\\','g')
5838 endif
5839 endif
5840 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005841 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005842" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005843 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005844" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005845 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005846 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005847" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005848 call mkdir(home)
5849 endif
5850 endif
5851 let g:netrw_home= home
5852 return home
5853endfun
5854
5855" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005856" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5857fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005858 if exists("s:netrwdrag")
5859 return
5860 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005861 if &ft != "netrw"
5862 return
5863 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005865
Bram Moolenaar97d62492012-11-15 21:28:22 +01005866 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005867 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005868 while getchar(0) != 0
5869 "clear the input stream
5870 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005871 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005872 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005873 let mouse_lnum = v:mouse_lnum
5874 let wlastline = line('w$')
5875 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005876" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5877" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005878 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5879 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005880 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005881" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5882 return
5883 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005884 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005885 " 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 +01005886 " without this test when its disabled.
5887 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005888" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005889 if v:mouse_col > virtcol('.')
5890 let @@= ykeep
5891" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5892 return
5893 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005894
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895 if a:islocal
5896 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005897 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 endif
5899 else
5900 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 endif
5903 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005904 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905" call Dret("s:NetrwLeftmouse")
5906endfun
5907
5908" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5910fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005911 if &ft != "netrw"
5912 return
5913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005914" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5915 call s:NetrwMarkFileTgt(a:islocal)
5916" call Dret("s:NetrwCLeftmouse")
5917endfun
5918
5919" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005920" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5921" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005922" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005923" a:islocal=2 : <c-r> used, remote
5924" a:islocal=3 : <c-r> used, local
5925fun! s:NetrwServerEdit(islocal,fname)
5926" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5927 let islocal = a:islocal%2 " =0: remote =1: local
5928 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005929" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005930
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005932 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005933 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005934" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005935 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005936 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005937 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5938 unlet s:netrw_browse_split_{winnr()}
5939 endif
5940 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5941" call Dret("s:NetrwServerEdit")
5942 return
5943 endif
5944
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005945" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005946 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005947" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005948
5949 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005950" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 let srvrname = g:netrw_browse_split[0]
5952 let tabnum = g:netrw_browse_split[1]
5953 let winnum = g:netrw_browse_split[2]
5954
5955 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005956" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005957
5958 if !ctrlr
5959 " user must have closed the server window and the user did not use <c-r>, but
5960 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005961" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005962 if exists("g:netrw_browse_split")
5963 unlet g:netrw_browse_split
5964 endif
5965 let g:netrw_browse_split= 0
5966 if exists("s:netrw_browse_split_".winnr())
5967 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5968 endif
5969 call s:NetrwBrowseChgDir(islocal,a:fname)
5970" call Dret("s:NetrwServerEdit")
5971 return
5972
5973 elseif has("win32") && executable("start")
5974 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005975" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005976 call system("start gvim --servername ".srvrname)
5977
5978 else
5979 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005981 call system("gvim --servername ".srvrname)
5982 endif
5983 endif
5984
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005986 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5987 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005988 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005989
5990 else
5991
5992 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5993
5994 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005995" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005996 if exists("g:netrw_browse_split")
5997 unlet g:netrw_browse_split
5998 endif
5999 let g:netrw_browse_split= 0
6000 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6001" call Dret("s:NetrwServerEdit")
6002 return
6003
6004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006005" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006006 if has("win32") && executable("start")
6007 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006008" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006009 call system("start gvim --servername ".g:netrw_servername)
6010 else
6011 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006012" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006013 call system("gvim --servername ".g:netrw_servername)
6014 endif
6015 endif
6016 endif
6017
6018 while 1
6019 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006020" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6021 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006022 break
6023 catch /^Vim\%((\a\+)\)\=:E241/
6024 sleep 200m
6025 endtry
6026 endwhile
6027
6028 if exists("g:netrw_browse_split")
6029 if type(g:netrw_browse_split) != 3
6030 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6031 endif
6032 unlet g:netrw_browse_split
6033 endif
6034 let g:netrw_browse_split= [g:netrw_servername,1,1]
6035 endif
6036
6037 else
6038 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6039 endif
6040
6041" call Dret("s:NetrwServerEdit")
6042endfun
6043
6044" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006045" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6046fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006047 if &ft != "netrw"
6048 return
6049 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006050" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051
Bram Moolenaar8d043172014-01-23 14:24:41 +01006052 let s:ngw= s:NetrwGetWord()
6053 call s:NetrwMarkFile(a:islocal,s:ngw)
6054
6055" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006056endfun
6057
6058" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006059" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6060" Used to mark multiple files.
6061fun! s:NetrwSLeftdrag(islocal)
6062" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6063 if !exists("s:netrwdrag")
6064 let s:netrwdrag = winnr()
6065 if a:islocal
6066 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006067 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006068 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006069 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006070 endif
6071 let ngw = s:NetrwGetWord()
6072 if !exists("s:ngw") || s:ngw != ngw
6073 call s:NetrwMarkFile(a:islocal,ngw)
6074 endif
6075 let s:ngw= ngw
6076" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6077endfun
6078
6079" ---------------------------------------------------------------------
6080" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6081fun! s:NetrwSLeftrelease(islocal)
6082" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6083 if exists("s:netrwdrag")
6084 nunmap <s-leftrelease>
6085 let ngw = s:NetrwGetWord()
6086 if !exists("s:ngw") || s:ngw != ngw
6087 call s:NetrwMarkFile(a:islocal,ngw)
6088 endif
6089 if exists("s:ngw")
6090 unlet s:ngw
6091 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006092 unlet s:netrwdrag
6093 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006094" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006095endfun
6096
6097" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006098" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6099" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006100fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006102" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006103 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006104
6105 " find a character not in the "hide" string to use as a separator for :g and :v commands
Bram Moolenaar85850f32019-07-19 22:05:51 +02006106 " How-it-works: take the hiding command, convert it into a range.
6107 " Duplicate characters don't matter.
6108 " Remove all such characters from the '/~@#...890' string.
6109 " Use the first character left as a separator character.
6110" call Decho("find a character not in the hide string to use as a separator")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006111 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006112 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
6113" call Decho("sep=".sep," (sep not in hide string)'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006114
6115 while listhide != ""
6116 if listhide =~ ','
6117 let hide = substitute(listhide,',.*$','','e')
6118 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6119 else
6120 let hide = listhide
6121 let listhide = ""
6122 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01006123" call Decho("..extracted from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
6124 if g:netrw_sort_by =~ '^[ts]'
6125 if hide =~ '^\^'
6126" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6127 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6128 elseif hide =~ '^\\(\^'
6129 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6130 endif
6131" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6132 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006133
6134 " Prune the list by hiding any files which match
Bram Moolenaar91359012019-11-30 17:57:03 +01006135" call Decho("..prune the list by hiding any files which ",((g:netrw_hide == 1)? "" : "don't")." match hide<".hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006136 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006137" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006139 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006140" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006142 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006143" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006144 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006145
Bram Moolenaar446cb832008-06-24 21:56:24 +00006146 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006147 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006148" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006150" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006151 endif
6152
Bram Moolenaaradc21822011-04-01 18:03:16 +02006153 " remove any blank lines that have somehow remained.
6154 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006155 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006156
Bram Moolenaar97d62492012-11-15 21:28:22 +01006157 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006158" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006159endfun
6160
6161" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006162" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006164fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006165" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006166
Bram Moolenaar97d62492012-11-15 21:28:22 +01006167 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006168 " get name of new directory from user. A bare <CR> will skip.
6169 " if its currently a directory, also request will be skipped, but with
6170 " a message.
6171 call inputsave()
6172 let newdirname= input("Please give directory name: ")
6173 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006174" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006175
6176 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006177 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006178" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006179 return
6180 endif
6181
6182 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006183" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006184
6185 " Local mkdir:
6186 " sanity checks
6187 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6189 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006190 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006191 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006192 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006193 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006194" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006195 return
6196 endif
6197 if s:FileReadable(fullnewdir)
6198 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006199 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006200 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006201 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006202" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006203 return
6204 endif
6205
6206 " requested new local directory is neither a pre-existing file or
6207 " directory, so make it!
6208 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006209 if has("unix")
6210 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6211 else
6212 call mkdir(fullnewdir,"p")
6213 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214 else
6215 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006216 if s:NetrwLcd(b:netrw_curdir)
6217" call Dret("s:NetrwMakeDir : lcd failure")
6218 return
6219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006220" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006221 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006222 if v:shell_error != 0
6223 let @@= ykeep
6224 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006225" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006226 return
6227 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006228 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006229" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006230 if s:NetrwLcd(netrw_origdir)
6231" call Dret("s:NetrwBrowse : lcd failure")
6232 return
6233 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006234 endif
6235 endif
6236
6237 if v:shell_error == 0
6238 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006239" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006240 let svpos= winsaveview()
6241" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006243" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6244 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006245 elseif !exists("g:netrw_quiet")
6246 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6247 endif
6248" redraw!
6249
6250 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006251 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006252" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006253 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6254 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006255 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 if v:shell_error == 0
6257 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006258 let svpos= winsaveview()
6259" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006260 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006261" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6262 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006264 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265 endif
6266" redraw!
6267
6268 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006269 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006270 let svpos= winsaveview()
6271" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006272" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006273 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006274" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006275 let remotepath= b:netrw_fname
6276 else
6277 let remotepath= ""
6278 endif
6279 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006280 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006281" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6282 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006283
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006285 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006286 let svpos= winsaveview()
6287" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006288" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006289 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006290" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006291 let remotepath= b:netrw_fname
6292 else
6293 let remotepath= ""
6294 endif
6295 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006297" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6298 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 endif
6300
Bram Moolenaar97d62492012-11-15 21:28:22 +01006301 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006302" call Dret("s:NetrwMakeDir")
6303endfun
6304
6305" ---------------------------------------------------------------------
6306" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6307fun! s:TreeSqueezeDir(islocal)
6308" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6309 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6310 " its a tree-listing style
6311 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006312 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006313 let depth = strchars(substitute(curdepth,' ','','g'))
6314 let srch = -1
6315" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6316" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006317" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006318" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6319 if depth >= 2
6320 NetrwKeepj norm! 0
6321 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6322 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6323" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6324" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6325 elseif depth == 1
6326 NetrwKeepj norm! 0
6327 let treedepthchr= substitute(s:treedepthstring,' ','','')
6328 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6329" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6330 endif
6331 if srch > 0
6332" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6333 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6334 exe srch
6335 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006336 endif
6337" call Dret("s:TreeSqueezeDir")
6338endfun
6339
6340" ---------------------------------------------------------------------
6341" s:NetrwMaps: {{{2
6342fun! s:NetrwMaps(islocal)
6343" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6344
Bram Moolenaar85850f32019-07-19 22:05:51 +02006345 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006346 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006347" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006348 if !hasmapto("<Plug>NetrwReturn")
6349 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006350" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006351 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6352 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006354 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6355 endif
6356 endif
6357 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006359 endif
6360
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 " generate default <Plug> maps {{{3
6362 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006363 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006364 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6365 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6366 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6367 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6368 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6369 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6370 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6371 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6372 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6373 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6374" ---------------------------------------------------------------------
6375" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6376" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6377" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6378" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6379" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6380" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6381" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6382" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6383" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6384" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6385" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6386" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6387" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6388" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6389" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6390" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6391" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6392" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6393" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6394" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6395" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6396" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6397" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6398" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6399" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6400" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6401" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6402" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6403" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6404" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6405" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6406" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6407" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6408" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6409" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6410" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6411" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6412" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6413" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6414" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6415" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6416" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6417" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6418" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6419" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6420" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6421" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6422
Bram Moolenaara6878372014-03-22 21:02:50 +01006423 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006424" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006425 " local normal-mode maps {{{3
6426 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6427 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6428 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6429 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6430 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6431 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6432 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6433 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6434 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6435 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6436 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6437" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006438 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6439 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6440 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006441 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006442 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006443 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6444 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6445 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6446 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006447 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6448 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6449 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6450 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6451 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6452 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6453 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6454 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6455 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6456 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6457 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6458 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6459 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006461 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006462 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6463 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6464 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6465 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6466 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006467 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006468 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006469 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6470 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006471 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6472 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6473 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006474 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006475 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006476 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6477 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006478 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006479 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006480 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6481 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6482 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006483 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6484 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006485
6486 nnoremap <buffer> <silent> <nowait> r :<c-u>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>
Bram Moolenaara6878372014-03-22 21:02:50 +01006487 if !hasmapto('<Plug>NetrwHideEdit')
6488 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006490 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 if !hasmapto('<Plug>NetrwRefresh')
6492 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006493 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006494 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006495 if s:didstarstar || !mapcheck("<s-down>","n")
6496 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006497 endif
6498 if s:didstarstar || !mapcheck("<s-up>","n")
6499 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006500 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006501 if !hasmapto('<Plug>NetrwTreeSqueeze')
6502 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006503 endif
6504 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006505 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6506 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006507 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6508 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6509 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6510 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6511 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6512 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6513 imap <buffer> <leftmouse> <Plug>ILeftmouse
6514 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006515 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006516 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006517 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006518 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006519 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006521 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6522 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006523 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006524 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6525 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6526 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6527 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6528 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6529 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6530 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006531 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6532
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006533 " support user-specified maps
6534 call netrw#UserMaps(1)
6535
Bram Moolenaar85850f32019-07-19 22:05:51 +02006536 else
6537 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006538" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006539 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006540 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6541 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6542 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6543 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6544 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6545 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6546 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6547 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6548 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6549 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6550 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6551" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006552 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6553 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6554 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6555 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6556 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6557 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6558 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6559 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006560 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006561 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006562 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6563 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6564 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6565 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6566 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6567 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6568 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6569 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6570 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6571 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6572 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006573 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006575 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6576 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6577 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6578 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6579 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006580 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6581 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6582 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6583 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6586 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006587 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006588 nnoremap <buffer> <silent> <nowait> r :<c-u>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>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006589 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6590 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6591 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6592 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6594 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6595 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6596 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6597 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006598 if !hasmapto('<Plug>NetrwHideEdit')
6599 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006600 endif
6601 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6602 if !hasmapto('<Plug>NetrwRefresh')
6603 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006604 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006605 if !hasmapto('<Plug>NetrwTreeSqueeze')
6606 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 endif
6608 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006609
6610 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006611 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006612
6613 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6614 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6616 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6617 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6618 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6619 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6620 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6621 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6622 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6623 nmap <middlemouse> <Plug>NetrwMiddlemouse
6624 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6625 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6626 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6627 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006630 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6631 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6634 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6635 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6636 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6637 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6638 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6639 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006641
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006642 " support user-specified maps
6643 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006644 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006645
6646" call Dret("s:NetrwMaps")
6647endfun
6648
6649" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006650" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006651" If -buffer, the command is only available from within netrw buffers
6652" Otherwise, the command is available from any window, so long as netrw
6653" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006654fun! s:NetrwCommands(islocal)
6655" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6656
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006657 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6658 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006659 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,"win#".winnr()." not a former netrw window",79)|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006661 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006662 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006663 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006664 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006665 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006666
6667" call Dret("s:NetrwCommands")
6668endfun
6669
6670" ---------------------------------------------------------------------
6671" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6672" glob()ing only works with local files
6673fun! s:NetrwMarkFiles(islocal,...)
6674" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675 let curdir = s:NetrwGetCurdir(a:islocal)
6676 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 while i <= a:0
6678 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006679 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006680 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006682 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006684 else
6685 let mffiles= [a:{i}]
6686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006687" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006688 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006690 call s:NetrwMarkFile(a:islocal,mffile)
6691 endfor
6692 let i= i + 1
6693 endwhile
6694" call Dret("s:NetrwMarkFiles")
6695endfun
6696
6697" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006699fun! s:NetrwMarkTarget(...)
6700" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6701 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 let curdir = s:NetrwGetCurdir(1)
6703 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006705 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6706 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006708" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006709 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6711 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006712 let svpos = winsaveview()
6713" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006714 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6716 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006717" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006718endfun
6719
6720" ---------------------------------------------------------------------
6721" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6722" mark and unmark files. If a markfile list exists,
6723" then the rename and delete functions will use it instead
6724" of whatever may happen to be under the cursor at that
6725" moment. When the mouse and gui are available,
6726" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006727"
6728" Creates two lists
6729" s:netrwmarkfilelist -- holds complete paths to all marked files
6730" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6731"
6732" Creates a marked file match string
6733" s:netrwmarfilemtch_# -- used with 2match to display marked files
6734"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006735" Creates a buffer version of islocal
6736" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006737fun! s:NetrwMarkFile(islocal,fname)
6738" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006739" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006740
6741 " sanity check
6742 if empty(a:fname)
6743" call Dret("s:NetrwMarkFile : emtpy fname")
6744 return
6745 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006746 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006747
Bram Moolenaar97d62492012-11-15 21:28:22 +01006748 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006749 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006750 if a:fname =~ '^\a'
6751 let leader= '\<'
6752 else
6753 let leader= ''
6754 endif
6755 if a:fname =~ '\a$'
6756 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6757 else
6758 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6759 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006760
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006762 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6764" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6765" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006766 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006767
6768 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006769 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006771 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006772 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006773
6774 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006775 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006777 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6778 if s:netrwmarkfilelist_{curbufnr} == []
6779 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006781 call s:NetrwUnmarkList(curbufnr,curdir)
6782 else
6783 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006785 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006786 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787 for fname in s:netrwmarkfilelist_{curbufnr}
6788 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006789 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006790 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006791 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006792 endif
6793 let first= 0
6794 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006795" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006796 endif
6797 endif
6798
6799 else
6800 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006801" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006802
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006804 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006805 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6806" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006807
6808 " build initial markfile matching pattern
6809 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006810 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006811 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006814" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006815 endif
6816
6817 " handle global markfilelist
6818 if exists("s:netrwmarkfilelist")
6819 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6820 if index(s:netrwmarkfilelist,dname) == -1
6821 " append new filename to global markfilelist
6822 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006823" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006824 else
6825 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006826" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6827" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006828 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006829" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006830 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006831" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006832 unlet s:netrwmarkfilelist
6833 endif
6834 endif
6835 else
6836 " initialize new global-directory markfilelist
6837 let s:netrwmarkfilelist= []
6838 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006840 endif
6841
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006843 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6844 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6845" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6846 if exists("g:did_drchip_netrwlist_syntax")
6847 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6848 endif
6849 else
6850" " call Decho("2match none",'~'.expand("<slnum>"))
6851 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006853 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006854 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006855" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6856" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006857endfun
6858
6859" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006860" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6861" mA: move the argument list to marked file list (tomflist=1)
6862" Uses the global marked file list
6863fun! s:NetrwMarkFileArgList(islocal,tomflist)
6864" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6865
6866 let svpos = winsaveview()
6867" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6868 let curdir = s:NetrwGetCurdir(a:islocal)
6869 let curbufnr = bufnr("%")
6870
6871 if a:tomflist
6872 " mA: move argument list to marked file list
6873 while argc()
6874 let fname= argv(0)
6875" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6876 exe "argdel ".fnameescape(fname)
6877 call s:NetrwMarkFile(a:islocal,fname)
6878 endwhile
6879
6880 else
6881 " ma: move marked file list to argument list
6882 if exists("s:netrwmarkfilelist")
6883
6884 " for every filename in the marked list
6885 for fname in s:netrwmarkfilelist
6886" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6887 exe "argadd ".fnameescape(fname)
6888 endfor " for every file in the marked list
6889
6890 " unmark list and refresh
6891 call s:NetrwUnmarkList(curbufnr,curdir)
6892 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6893" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6894 NetrwKeepj call winrestview(svpos)
6895 endif
6896 endif
6897
6898" call Dret("s:NetrwMarkFileArgList")
6899endfun
6900
6901" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6903" compress/decompress files using the programs
6904" in g:netrw_compress and g:netrw_uncompress,
6905" using g:netrw_compress_suffix to know which to
6906" do. By default:
6907" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006908" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909fun! s:NetrwMarkFileCompress(islocal)
6910" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006911 let svpos = winsaveview()
6912" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 let curbufnr = bufnr("%")
6915
Bram Moolenaarff034192013-04-24 18:51:19 +02006916 " sanity check
6917 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006918 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006919" call Dret("s:NetrwMarkFileCompress")
6920 return
6921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006922" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006923
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006925
6926 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006928 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006930 if exists("g:netrw_decompress['".sfx."']")
6931 " fname has a suffix indicating that its compressed; apply associated decompression routine
6932 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006934 let exe= netrw#WinPath(exe)
6935 if a:islocal
6936 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006937 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006939 call system(exe." ".fname)
6940 if v:shell_error
6941 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006942 endif
6943 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006944 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6945 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006946 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006947
Bram Moolenaarff034192013-04-24 18:51:19 +02006948 endif
6949 unlet sfx
6950
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 if exists("exe")
6952 unlet exe
6953 elseif a:islocal
6954 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006955 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006956 if v:shell_error
6957 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 else
6960 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006961 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006963 endfor " for every file in the marked list
6964
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006966 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006967" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6968 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 endif
6970" call Dret("s:NetrwMarkFileCompress")
6971endfun
6972
6973" ---------------------------------------------------------------------
6974" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6975" If no marked files, then set up directory as the
6976" target. Currently does not support copying entire
6977" directories. Uses the local-buffer marked file list.
6978" Returns 1=success (used by NetrwMarkFileMove())
6979" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006980fun! s:NetrwMarkFileCopy(islocal,...)
6981" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6982
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006983 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006984 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006985 if b:netrw_curdir !~ '/$'
6986 if !exists("b:netrw_curdir")
6987 let b:netrw_curdir= curdir
6988 endif
6989 let b:netrw_curdir= b:netrw_curdir."/"
6990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991
Bram Moolenaarff034192013-04-24 18:51:19 +02006992 " sanity check
6993 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006994 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006995" call Dret("s:NetrwMarkFileCopy")
6996 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006998" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006999
Bram Moolenaar446cb832008-06-24 21:56:24 +00007000 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007001 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007002" call Dret("s:NetrwMarkFileCopy 0")
7003 return 0
7004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007005" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007006
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007007 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007008 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007009" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007010 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007011 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7012" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7013 return
7014 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007015
7016 " copy marked files while within the same directory (ie. allow renaming)
7017 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7018 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7019 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007020" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007021 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007022 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7023 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007024" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007025 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007026 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007027 let oldname = a:1
7028 else
7029 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007030" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007031 let s:recursive= 1
7032 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7033 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7034 if ret == 0
7035 break
7036 endif
7037 endfor
7038 unlet s:recursive
7039 call s:NetrwUnmarkList(curbufnr,curdir)
7040" call Dret("s:NetrwMarkFileCopy ".ret)
7041 return ret
7042 endif
7043
7044 call inputsave()
7045 let newname= input("Copy ".oldname." to : ",oldname,"file")
7046 call inputrestore()
7047 if newname == ""
7048" call Dret("s:NetrwMarkFileCopy 0")
7049 return 0
7050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007051 let args= s:ShellEscape(oldname)
7052 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007053 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007054 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7055 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007056 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007057 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7058 let args= substitute(args,'/','\\','g')
7059 let tgt = substitute(tgt, '/','\\','g')
7060 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007061 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7062 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7063 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7064 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7065" call Decho("args <".args.">",'~'.expand("<slnum>"))
7066" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067 if isdirectory(s:NetrwFile(args))
7068" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007069 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7072 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7073 " contents to a target. One must append the source directory name to the target to get xcopy to
7074 " do the right thing.
7075 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007076" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007077 endif
7078 else
7079 let copycmd= g:netrw_localcopycmd
7080 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007081 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007082 let copycmd = substitute(copycmd,'\s.*$','','')
7083 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007084 let copycmd = netrw#WinPath(copycmd).copycmdargs
7085 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007086 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007087 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007088" call Decho("args <".args.">",'~'.expand("<slnum>"))
7089" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7090" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7091" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007092 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007093 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007094 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007095 call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096 else
7097 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7098 endif
7099" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007100 return 0
7101 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102
7103 elseif a:islocal && !s:netrwmftgt_islocal
7104 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007105" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107
7108 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007109 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007110" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007111 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112
7113 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007114 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007115" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007116 let curdir = getcwd()
7117 let tmpdir = s:GetTempfile("")
7118 if tmpdir !~ '/'
7119 let tmpdir= curdir."/".tmpdir
7120 endif
7121 if exists("*mkdir")
7122 call mkdir(tmpdir)
7123 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007124 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007125 if v:shell_error != 0
7126 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007127" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007128 return
7129 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007131 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007132 if s:NetrwLcd(tmpdir)
7133" call Dret("s:NetrwMarkFileCopy : lcd failure")
7134 return
7135 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007136 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007137 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139 if getcwd() == tmpdir
7140 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007143 if s:NetrwLcd(curdir)
7144" call Dret("s:NetrwMarkFileCopy : lcd failure")
7145 return
7146 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007147 if delete(tmpdir,"d")
7148 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007149 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007150 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007151 if s:NetrwLcd(curdir)
7152" call Dret("s:NetrwMarkFileCopy : lcd failure")
7153 return
7154 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007155 endif
7156 endif
7157 endif
7158
7159 " -------
7160 " cleanup
7161 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007162" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007163 " remove markings from local buffer
7164 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007165" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7166" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7167" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7168" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7169" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7170" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7171 if exists("s:recursive")
7172" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7173 else
7174" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007175 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007176 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007177 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007178 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007179 else
7180 " refresh local and targets for fast browsing
7181 if !exists("s:recursive")
7182 " remove markings from local buffer
7183" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7184 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7185 endif
7186
7187 " refresh buffers
7188 if s:netrwmftgt_islocal
7189" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7190 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7191 endif
7192 if a:islocal && s:netrwmftgt != curdir
7193" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7194 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7195 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007196 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007197
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198" call Dret("s:NetrwMarkFileCopy 1")
7199 return 1
7200endfun
7201
7202" ---------------------------------------------------------------------
7203" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7204" invoke vim's diff mode on the marked files.
7205" Either two or three files can be so handled.
7206" Uses the global marked file list.
7207fun! s:NetrwMarkFileDiff(islocal)
7208" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7209 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007210
Bram Moolenaarff034192013-04-24 18:51:19 +02007211 " sanity check
7212 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007213 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007214" call Dret("s:NetrwMarkFileDiff")
7215 return
7216 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217 let curdir= s:NetrwGetCurdir(a:islocal)
7218" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007219
Bram Moolenaara6878372014-03-22 21:02:50 +01007220 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007221 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007222 for fname in s:netrwmarkfilelist
7223 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007227 diffthis
7228 elseif cnt == 2 || cnt == 3
7229 vsplit
7230 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007231" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007232 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233 diffthis
7234 else
7235 break
7236 endif
7237 endfor
7238 call s:NetrwUnmarkList(curbufnr,curdir)
7239 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007240
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241" call Dret("s:NetrwMarkFileDiff")
7242endfun
7243
7244" ---------------------------------------------------------------------
7245" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7246" Uses global markfilelist
7247fun! s:NetrwMarkFileEdit(islocal)
7248" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7249
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007251 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007252
7253 " sanity check
7254 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007255 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007256" call Dret("s:NetrwMarkFileEdit")
7257 return
7258 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007259" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007260
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 if exists("s:netrwmarkfilelist_{curbufnr}")
7262 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007263 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007264 " unmark markedfile list
7265" call s:NetrwUnmarkList(curbufnr,curdir)
7266 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007268 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007269 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007270 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272" call Dret("s:NetrwMarkFileEdit")
7273endfun
7274
7275" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007276" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007277fun! s:NetrwMarkFileQFEL(islocal,qfel)
7278" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7279 call s:NetrwUnmarkAll()
7280 let curbufnr= bufnr("%")
7281
7282 if !empty(a:qfel)
7283 for entry in a:qfel
7284 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007285" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007286 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007287" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007288 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7289 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7290 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7291 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007292" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007293 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7294 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007295" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007296 endif
7297 endfor
7298 echo "(use me to edit marked files)"
7299 else
7300 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7301 endif
7302
7303" call Dret("s:NetrwMarkFileQFEL")
7304endfun
7305
7306" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007307" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7308" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7309" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7310fun! s:NetrwMarkFileExe(islocal,enbloc)
7311" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007312 let svpos = winsaveview()
7313" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007314 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007315 let curbufnr = bufnr("%")
7316
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007317 if a:enbloc == 0
7318 " individually apply command to files, one at a time
7319 " sanity check
7320 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7321 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7322" call Dret("s:NetrwMarkFileExe")
7323 return
7324 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007325" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007326
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007327 if exists("s:netrwmarkfilelist_{curbufnr}")
7328 " get the command
7329 call inputsave()
7330 let cmd= input("Enter command: ","","file")
7331 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007332" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007333 if cmd == ""
7334" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7335 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007336 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007337
7338 " apply command to marked files, individually. Substitute: filename -> %
7339 " If no %, then append a space and the filename to the command
7340 for fname in s:netrwmarkfilelist_{curbufnr}
7341 if a:islocal
7342 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007343 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007344 endif
7345 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007346 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007347 endif
7348 if cmd =~ '%'
7349 let xcmd= substitute(cmd,'%',fname,'g')
7350 else
7351 let xcmd= cmd.' '.fname
7352 endif
7353 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007355 let ret= system(xcmd)
7356 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007357" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007358 let ret= s:RemoteSystem(xcmd)
7359 endif
7360 if v:shell_error < 0
7361 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7362 break
7363 else
7364 echo ret
7365 endif
7366 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367
7368 " unmark marked file list
7369 call s:NetrwUnmarkList(curbufnr,curdir)
7370
7371 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007373" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7374 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007378
7379 else " apply command to global list of files, en bloc
7380
7381 call inputsave()
7382 let cmd= input("Enter command: ","","file")
7383 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007384" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385 if cmd == ""
7386" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7387 return
7388 endif
7389 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007393 endif
7394 if a:islocal
7395 call system(cmd)
7396 if v:shell_error < 0
7397 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7398 endif
7399 else
7400 let ret= s:RemoteSystem(cmd)
7401 endif
7402 call s:NetrwUnmarkAll()
7403
7404 " refresh the listing
7405 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007406" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7407 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007408
7409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411" call Dret("s:NetrwMarkFileExe")
7412endfun
7413
7414" ---------------------------------------------------------------------
7415" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7416" as the marked file(s) (toggles suffix presence)
7417" Uses the local marked file list.
7418fun! s:NetrwMarkHideSfx(islocal)
7419" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007420 let svpos = winsaveview()
7421" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007422 let curbufnr = bufnr("%")
7423
7424 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7425 if exists("s:netrwmarkfilelist_{curbufnr}")
7426
7427 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007429 " construct suffix pattern
7430 if fname =~ '\.'
7431 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7432 else
7433 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7434 endif
7435 " determine if its in the hiding list or not
7436 let inhidelist= 0
7437 if g:netrw_list_hide != ""
7438 let itemnum = 0
7439 let hidelist= split(g:netrw_list_hide,',')
7440 for hidepat in hidelist
7441 if sfxpat == hidepat
7442 let inhidelist= 1
7443 break
7444 endif
7445 let itemnum= itemnum + 1
7446 endfor
7447 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 if inhidelist
7450 " remove sfxpat from list
7451 call remove(hidelist,itemnum)
7452 let g:netrw_list_hide= join(hidelist,",")
7453 elseif g:netrw_list_hide != ""
7454 " append sfxpat to non-empty list
7455 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7456 else
7457 " set hiding list to sfxpat
7458 let g:netrw_list_hide= sfxpat
7459 endif
7460 endfor
7461
7462 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007464" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7465 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007466 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007468 endif
7469
7470" call Dret("s:NetrwMarkHideSfx")
7471endfun
7472
7473" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007475" Uses the local marked-file list.
7476fun! s:NetrwMarkFileVimCmd(islocal)
7477" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007478 let svpos = winsaveview()
7479" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007480 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007481 let curbufnr = bufnr("%")
7482
Bram Moolenaarff034192013-04-24 18:51:19 +02007483 " sanity check
7484 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007486" call Dret("s:NetrwMarkFileVimCmd")
7487 return
7488 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007489" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007490
Bram Moolenaar15146672011-10-20 22:22:38 +02007491 if exists("s:netrwmarkfilelist_{curbufnr}")
7492 " get the command
7493 call inputsave()
7494 let cmd= input("Enter vim command: ","","file")
7495 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007497 if cmd == ""
7498" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7499 return
7500 endif
7501
7502 " apply command to marked files. Substitute: filename -> %
7503 " If no %, then append a space and the filename to the command
7504 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007505" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007506 if a:islocal
7507 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007509" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007510 exe cmd
7511 exe "sil! keepalt wq!"
7512 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007513" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007515 endif
7516 endfor
7517
7518 " unmark marked file list
7519 call s:NetrwUnmarkList(curbufnr,curdir)
7520
7521 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007523" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7524 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007525 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007526 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007527 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528
Bram Moolenaar15146672011-10-20 22:22:38 +02007529" call Dret("s:NetrwMarkFileVimCmd")
7530endfun
7531
7532" ---------------------------------------------------------------------
7533" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7534" as the marked file(s) (toggles suffix presence)
7535" Uses the local marked file list.
7536fun! s:NetrwMarkHideSfx(islocal)
7537" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007538 let svpos = winsaveview()
7539" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007540 let curbufnr = bufnr("%")
7541
7542 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7543 if exists("s:netrwmarkfilelist_{curbufnr}")
7544
7545 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007547 " construct suffix pattern
7548 if fname =~ '\.'
7549 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7550 else
7551 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7552 endif
7553 " determine if its in the hiding list or not
7554 let inhidelist= 0
7555 if g:netrw_list_hide != ""
7556 let itemnum = 0
7557 let hidelist= split(g:netrw_list_hide,',')
7558 for hidepat in hidelist
7559 if sfxpat == hidepat
7560 let inhidelist= 1
7561 break
7562 endif
7563 let itemnum= itemnum + 1
7564 endfor
7565 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007566" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007567 if inhidelist
7568 " remove sfxpat from list
7569 call remove(hidelist,itemnum)
7570 let g:netrw_list_hide= join(hidelist,",")
7571 elseif g:netrw_list_hide != ""
7572 " append sfxpat to non-empty list
7573 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7574 else
7575 " set hiding list to sfxpat
7576 let g:netrw_list_hide= sfxpat
7577 endif
7578 endfor
7579
7580 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007581 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007582" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7583 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007584 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007585 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007586 endif
7587
7588" call Dret("s:NetrwMarkHideSfx")
7589endfun
7590
7591" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007592" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7593" Uses the global markfilelist
7594fun! s:NetrwMarkFileGrep(islocal)
7595" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007596 let svpos = winsaveview()
7597" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007599 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007600
7601 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007602" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007603 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007604" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007606 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007607" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007608 let netrwmarkfilelist= "*"
7609 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007610
Bram Moolenaarff034192013-04-24 18:51:19 +02007611 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007612" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007613 call inputsave()
7614 let pat= input("Enter pattern: ","")
7615 call inputrestore()
7616 let patbang = ""
7617 if pat =~ '^!'
7618 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007620 endif
7621 if pat =~ '^\i'
7622 let pat = escape(pat,'/')
7623 let pat = '/'.pat.'/'
7624 else
7625 let nonisi = pat[0]
7626 endif
7627
7628 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007629" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007630 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007631 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007632 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007633 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007634" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7635 return
7636 endtry
7637 echo "(use :cn, :cp to navigate, :Rex to return)"
7638
7639 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007640" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7641 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007642
7643 if exists("nonisi")
7644 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007646 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007647 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007648 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007649 endif
7650
7651" call Dret("s:NetrwMarkFileGrep")
7652endfun
7653
7654" ---------------------------------------------------------------------
7655" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7656" uses the global marked file list
7657" s:netrwmfloc= 0: target directory is remote
7658" = 1: target directory is local
7659fun! s:NetrwMarkFileMove(islocal)
7660" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007662 let curbufnr = bufnr("%")
7663
7664 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007665 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007666 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007667" call Dret("s:NetrwMarkFileMove")
7668 return
7669 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007670" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007671
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007673 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674" call Dret("s:NetrwMarkFileCopy 0")
7675 return 0
7676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007678
7679 if a:islocal && s:netrwmftgt_islocal
7680 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007681" call Decho("move from local to local",'~'.expand("<slnum>"))
7682" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007683 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007684 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7685" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7686 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007687 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007688 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007689" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007690 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007691 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007692" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007693 if g:netrw_localmovecmd =~ '\s'
7694 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7695 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7696 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007697" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007698 else
7699 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007701 endif
7702 else
7703 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007704" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007705 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007706 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007707 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7708 let fname= substitute(fname,'/','\\','g')
7709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007710" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007711 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007712 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007713 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007714 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715 else
7716 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7717 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007718 break
7719 endif
7720 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007721
7722 elseif a:islocal && !s:netrwmftgt_islocal
7723 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007724" call Decho("move from local to remote",'~'.expand("<slnum>"))
7725" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007726 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007727 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007728" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007729 for fname in mflist
7730 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7731 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7732 endfor
7733 unlet mflist
7734
7735 elseif !a:islocal && s:netrwmftgt_islocal
7736 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007737" call Decho("move from remote to local",'~'.expand("<slnum>"))
7738" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007740 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007741" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007742 for fname in mflist
7743 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7744 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7745 endfor
7746 unlet mflist
7747
7748 elseif !a:islocal && !s:netrwmftgt_islocal
7749 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007750" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7751" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007753 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007754" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007755 for fname in mflist
7756 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7757 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7758 endfor
7759 unlet mflist
7760 endif
7761
7762 " -------
7763 " cleanup
7764 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007766
7767 " remove markings from local buffer
7768 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7769
7770 " refresh buffers
7771 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007773 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007774 endif
7775 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007776" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007777 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007779 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007780" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007781 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007783
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784" call Dret("s:NetrwMarkFileMove")
7785endfun
7786
7787" ---------------------------------------------------------------------
7788" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7789" using the hardcopy command. Local marked-file list only.
7790fun! s:NetrwMarkFilePrint(islocal)
7791" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7792 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007793
7794 " sanity check
7795 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007796 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007797" call Dret("s:NetrwMarkFilePrint")
7798 return
7799 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7801 let curdir= s:NetrwGetCurdir(a:islocal)
7802
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803 if exists("s:netrwmarkfilelist_{curbufnr}")
7804 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805 call s:NetrwUnmarkList(curbufnr,curdir)
7806 for fname in netrwmarkfilelist
7807 if a:islocal
7808 if g:netrw_keepdir
7809 let fname= s:ComposePath(curdir,fname)
7810 endif
7811 else
7812 let fname= curdir.fname
7813 endif
7814 1split
7815 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007817 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007818" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007819 hardcopy
7820 q
7821 endfor
7822 2match none
7823 endif
7824" call Dret("s:NetrwMarkFilePrint")
7825endfun
7826
7827" ---------------------------------------------------------------------
7828" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7829" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007830" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831fun! s:NetrwMarkFileRegexp(islocal)
7832" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7833
7834 " get the regular expression
7835 call inputsave()
7836 let regexp= input("Enter regexp: ","","file")
7837 call inputrestore()
7838
7839 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007841" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007845 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007846 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847 else
7848 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007849 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852
7853 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007854 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007855 if fname =~ '^'.fnameescape(curdir)
7856" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7857 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7858 else
7859" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7860 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7861 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007862 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863
7864 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007865" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866
7867 " convert displayed listing into a filelist
7868 let eikeep = &ei
7869 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007871 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007873 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007874 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007875 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007876 sil NetrwKeepj norm! "ap
7877 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007878 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007879 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007880 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007881 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007882 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007883 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007885 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007886 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007888 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7889 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007890 call histdel("/",-1)
7891 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 endif
7893 " convert regexp into the more usual glob-style format
7894 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007897 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 let filelist= getline(1,line("$"))
7899 q!
7900 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007901 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 endfor
7903 unlet filelist
7904 let @a = areg
7905 let &ei = eikeep
7906 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007907 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908
7909" call Dret("s:NetrwMarkFileRegexp")
7910endfun
7911
7912" ---------------------------------------------------------------------
7913" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7914" Uses the local marked file list.
7915fun! s:NetrwMarkFileSource(islocal)
7916" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7917 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007918
7919 " sanity check
7920 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007921 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007922" call Dret("s:NetrwMarkFileSource")
7923 return
7924 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7926 let curdir= s:NetrwGetCurdir(a:islocal)
7927
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 if exists("s:netrwmarkfilelist_{curbufnr}")
7929 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930 call s:NetrwUnmarkList(curbufnr,curdir)
7931 for fname in netrwmarkfilelist
7932 if a:islocal
7933 if g:netrw_keepdir
7934 let fname= s:ComposePath(curdir,fname)
7935 endif
7936 else
7937 let fname= curdir.fname
7938 endif
7939 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007940" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007941 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007942 endfor
7943 2match none
7944 endif
7945" call Dret("s:NetrwMarkFileSource")
7946endfun
7947
7948" ---------------------------------------------------------------------
7949" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7950" Uses the global markfilelist
7951fun! s:NetrwMarkFileTag(islocal)
7952" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007953 let svpos = winsaveview()
7954" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007955 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956 let curbufnr = bufnr("%")
7957
Bram Moolenaarff034192013-04-24 18:51:19 +02007958 " sanity check
7959 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007961" call Dret("s:NetrwMarkFileTag")
7962 return
7963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007964" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007965
Bram Moolenaar446cb832008-06-24 21:56:24 +00007966 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007967" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7968 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969 call s:NetrwUnmarkAll()
7970
7971 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007972
7973" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7974 call system(g:netrw_ctags." ".netrwmarkfilelist)
7975 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7977 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007978
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007980 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007981 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007982 let curdir= b:netrw_curdir
7983 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007984 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007987 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007988 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 wq!
7990 endif
7991 2match none
7992 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007993" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7994 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995 endif
7996
7997" call Dret("s:NetrwMarkFileTag")
7998endfun
7999
8000" ---------------------------------------------------------------------
8001" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008002" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008003" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008005" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008007" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8008 let svpos = winsaveview()
8009" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008010 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008011 let hadtgt = exists("s:netrwmftgt")
8012 if !exists("w:netrw_bannercnt")
8013 let w:netrw_bannercnt= b:netrw_bannercnt
8014 endif
8015
8016 " set up target
8017 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008018" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008019 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8020 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008021" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008022 unlet s:netrwmftgt s:netrwmftgt_islocal
8023 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008024 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008025 endif
8026 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008027" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8028 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008029" call Dret("s:NetrwMarkFileTgt : removed target")
8030 return
8031 else
8032 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008033" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008034 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035
8036 else
8037 " get word under cursor.
8038 " * If directory, use it for the target.
8039 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008040" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 let curword= s:NetrwGetWord()
8042 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008043 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008044 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046 elseif !a:islocal && tgtdir =~ '/$'
8047 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008048" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049 else
8050 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008051" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 endif
8053 endif
8054 if a:islocal
8055 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8056 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008057" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058 endif
8059 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008060 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008061 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8062 endif
8063 let s:netrwmftgt_islocal= a:islocal
8064
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065 " need to do refresh so that the banner will be updated
8066 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008067 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008068" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008069 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008071" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008072 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008073 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8074 else
8075 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8076 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008077" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8078 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008080 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 endif
8082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8084" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8086endfun
8087
8088" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8090fun! s:NetrwGetCurdir(islocal)
8091" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8092
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008093 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008094 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8095" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8096 elseif !exists("b:netrw_curdir")
8097 let b:netrw_curdir= getcwd()
8098" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8099 endif
8100
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008101" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008102 if b:netrw_curdir !~ '\<\a\{3,}://'
8103 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008104" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008105 if g:netrw_keepdir == 0
8106 call s:NetrwLcd(curdir)
8107 endif
8108 endif
8109
8110" call Dret("s:NetrwGetCurdir <".curdir.">")
8111 return b:netrw_curdir
8112endfun
8113
8114" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008115" s:NetrwOpenFile: query user for a filename and open it {{{2
8116fun! s:NetrwOpenFile(islocal)
8117" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008118 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008119 call inputsave()
8120 let fname= input("Enter filename: ")
8121 call inputrestore()
8122 if fname !~ '[/\\]'
8123 if exists("b:netrw_curdir")
8124 if exists("g:netrw_quiet")
8125 let netrw_quiet_keep = g:netrw_quiet
8126 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008127 let g:netrw_quiet = 1
8128 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008129 let s:rexposn_{bufnr("%")}= winsaveview()
8130" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008131 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008132 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008133 else
8134 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8135 endif
8136 if exists("netrw_quiet_keep")
8137 let g:netrw_quiet= netrw_quiet_keep
8138 else
8139 unlet g:netrw_quiet
8140 endif
8141 endif
8142 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008143 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008144 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008145 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008146" call Dret("s:NetrwOpenFile")
8147endfun
8148
8149" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8151" For the mapping to this function be made via
8152" netrwPlugin, you'll need to have had
8153" g:netrw_usetab set to non-zero.
8154fun! netrw#Shrink()
8155" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8156 let curwin = winnr()
8157 let wiwkeep = &wiw
8158 set wiw=1
8159
8160 if &ft == "netrw"
8161 if winwidth(0) > g:netrw_wiw
8162 let t:netrw_winwidth= winwidth(0)
8163 exe "vert resize ".g:netrw_wiw
8164 wincmd l
8165 if winnr() == curwin
8166 wincmd h
8167 endif
8168" call Decho("vert resize 0",'~'.expand("<slnum>"))
8169 else
8170 exe "vert resize ".t:netrw_winwidth
8171" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8172 endif
8173
8174 elseif exists("t:netrw_lexbufnr")
8175 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8176 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8177 let t:netrw_winwidth= winwidth(0)
8178 exe "vert resize ".g:netrw_wiw
8179 wincmd l
8180 if winnr() == curwin
8181 wincmd h
8182 endif
8183" call Decho("vert resize 0",'~'.expand("<slnum>"))
8184 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8185 exe "vert resize ".t:netrw_winwidth
8186" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8187 else
8188 call netrw#Lexplore(0,0)
8189 endif
8190
8191 else
8192 call netrw#Lexplore(0,0)
8193 endif
8194 let wiw= wiwkeep
8195
8196" call Dret("netrw#Shrink")
8197endfun
8198
8199" ---------------------------------------------------------------------
8200" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8201fun! s:NetSortSequence(islocal)
8202" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8203
8204 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008205 let svpos= winsaveview()
8206" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 call inputsave()
8208 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8209 call inputrestore()
8210
8211 " refresh the listing
8212 let g:netrw_sort_sequence= newsortseq
8213 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008214" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8215 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 let @@= ykeep
8217
8218" call Dret("NetSortSequence")
8219endfun
8220
8221" ---------------------------------------------------------------------
8222" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8223" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008224" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225fun! s:NetrwUnmarkList(curbufnr,curdir)
8226" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8227
8228 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008230 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8231 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8232 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8233 call remove(s:netrwmarkfilelist,idx) " remove from global list
8234 endfor
8235 if s:netrwmarkfilelist == []
8236 unlet s:netrwmarkfilelist
8237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008238
Bram Moolenaar446cb832008-06-24 21:56:24 +00008239 " getting rid of the local marked-file lists is easy
8240 unlet s:netrwmarkfilelist_{a:curbufnr}
8241 endif
8242 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8243 unlet s:netrwmarkfilemtch_{a:curbufnr}
8244 endif
8245 2match none
8246" call Dret("s:NetrwUnmarkList")
8247endfun
8248
8249" ---------------------------------------------------------------------
8250" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8251fun! s:NetrwUnmarkAll()
8252" call Dfunc("s:NetrwUnmarkAll()")
8253 if exists("s:netrwmarkfilelist")
8254 unlet s:netrwmarkfilelist
8255 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008256 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008257 2match none
8258" call Dret("s:NetrwUnmarkAll")
8259endfun
8260
8261" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008262" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008263fun! s:NetrwUnmarkAll2()
8264" call Dfunc("s:NetrwUnmarkAll2()")
8265 redir => netrwmarkfilelist_let
8266 let
8267 redir END
8268 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008269 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008270 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8271 for flist in netrwmarkfilelist_list
8272 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8273 unlet s:netrwmarkfilelist_{curbufnr}
8274 unlet s:netrwmarkfilemtch_{curbufnr}
8275 endfor
8276" call Dret("s:NetrwUnmarkAll2")
8277endfun
8278
8279" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008280" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8281"
8282" Marked files are in two types of lists:
8283" s:netrwmarkfilelist -- holds complete paths to all marked files
8284" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8285"
8286" Marked files suitable for use with 2match are in:
8287" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008288fun! s:NetrwUnMarkFile(islocal)
8289" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008290 let svpos = winsaveview()
8291" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008292 let curbufnr = bufnr("%")
8293
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008294 " unmark marked file list
8295 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8296 if exists("s:netrwmarkfilelist")
8297" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008299 endif
8300
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008301 let ibuf= 1
8302 while ibuf < bufnr("$")
8303 if exists("s:netrwmarkfilelist_".ibuf)
8304 unlet s:netrwmarkfilelist_{ibuf}
8305 unlet s:netrwmarkfilemtch_{ibuf}
8306 endif
8307 let ibuf = ibuf + 1
8308 endwhile
8309 2match none
8310
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008312"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8313call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008314" call Dret("s:NetrwUnMarkFile")
8315endfun
8316
8317" ---------------------------------------------------------------------
8318" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8319fun! s:NetrwMenu(domenu)
8320
8321 if !exists("g:NetrwMenuPriority")
8322 let g:NetrwMenuPriority= 80
8323 endif
8324
Bram Moolenaaradc21822011-04-01 18:03:16 +02008325 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8327
8328 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008329" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008330 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008331 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8332 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8333 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8334 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8335 if g:netrw_dirhistmax > 0
8336 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8337 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8338 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8339 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8340 else
8341 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8342 endif
8343 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8344 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8345 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8346 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8347 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8348 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8349 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8350 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8351 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8352 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8353 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8354 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8355 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8356 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8357 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 +01008358 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 +02008359 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8360 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8361 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8362 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8363 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8364 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8365 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8366 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8367 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8368 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8369 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8370 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8371 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8372 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8373 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8374 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8375 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8376 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8377 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8378 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8379 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8380 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8381 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8382 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8383 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8384 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8385 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8386 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8387 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8388 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>'
8389 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>'
8390 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>'
8391 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8392 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>'
8393 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>'
8394 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>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008396 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8397 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008398 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008399 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8400 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008401
8402 elseif !a:domenu
8403 let s:netrwcnt = 0
8404 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008405 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406 exe curwin."wincmd w"
8407
8408 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008409" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008410 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008411" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008412 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008413 endif
8414 endif
8415" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008416 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 endif
8418
8419endfun
8420
8421" ---------------------------------------------------------------------
8422" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8423" Used by the O maps (as <SID>NetrwObtain())
8424fun! s:NetrwObtain(islocal)
8425" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8426
Bram Moolenaar97d62492012-11-15 21:28:22 +01008427 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008430 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008431 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8432 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008433 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008435 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436
8437" call Dret("NetrwObtain")
8438endfun
8439
8440" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8442" If there's only one window, then the window will first be split.
8443" Returns:
8444" choice = 0 : didn't have to choose
8445" choice = 1 : saved modified file in window first
8446" choice = 2 : didn't save modified file, opened window
8447" choice = 3 : cancel open
8448fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008449" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450
Bram Moolenaar97d62492012-11-15 21:28:22 +01008451 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008453 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454
8455 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008456 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 let lastwinnr = winnr("$")
8458 let curword = s:NetrwGetWord()
8459 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008460 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008461 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008462" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463
Bram Moolenaar8d043172014-01-23 14:24:41 +01008464 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 if lastwinnr == 1
8466 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008467" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008468 " g:netrw_preview=0: preview window shown in a horizontally split window
8469 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008470 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008471 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008472 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008473" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008474 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008476 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008477 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008478" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008479 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008480 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008481 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008482" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483
8484 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008485 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008486 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008487 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008488 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008490
8491 " prevwinnr: the window number of the "prev" window
8492 " prevbufnr: the buffer number of the buffer in the "prev" window
8493 " bnrcnt : the qty of windows open on the "prev" buffer
8494 let prevwinnr = winnr()
8495 let prevbufnr = bufnr("%")
8496 let prevbufname = bufname("%")
8497 let prevmod = &mod
8498 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008499 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008500" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008501
8502 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008503 " and it doesn't appear in any other extant window, then ask the
8504 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008505 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008506" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008507 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008508" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008509 exe prevwinnr."wincmd w"
8510
8511 if bnrcnt == 1 && &hidden == 0
8512 " only one copy of the modified buffer in a window, and
8513 " hidden not set, so overwriting will lose the modified file. Ask first...
8514 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008515" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008516 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008517
8518 if choice == 1
8519 " Yes -- write file & then browse
8520 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008521 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008522 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008523 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008524 exe origwin."wincmd w"
8525 let &ei = eikeep
8526 let @@ = ykeep
8527" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528 return choice
8529 endif
8530
8531 elseif choice == 2
8532 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008533" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008534 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008535
8536 else
8537 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008538" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008539 exe origwin."wincmd w"
8540 let &ei= eikeep
8541 let @@ = ykeep
8542" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008543 return choice
8544 endif
8545 endif
8546 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008547 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008548 endif
8549
8550 " restore b:netrw_curdir (window split/enew may have lost it)
8551 let b:netrw_curdir= curdir
8552 if a:islocal < 2
8553 if a:islocal
8554 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8555 else
8556 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8557 endif
8558 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008559 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008560" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561 return choice
8562endfun
8563
8564" ---------------------------------------------------------------------
8565" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8566" Always assumed to be local -> remote
8567" call s:NetrwUpload(filename, target)
8568" call s:NetrwUpload(filename, target, fromdirectory)
8569fun! s:NetrwUpload(fname,tgt,...)
8570" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8571
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008572 if a:tgt =~ '^\a\{3,}://'
8573 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 else
8575 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008577" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008578
8579 if a:0 > 0
8580 let fromdir= a:1
8581 else
8582 let fromdir= getcwd()
8583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008584" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585
8586 if type(a:fname) == 1
8587 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008588" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008590" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8591 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8592" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 if a:tgt =~ '/$'
8594 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008595" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008596 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008597 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008598" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008599 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008600" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 endif
8602 q!
8603
8604 elseif type(a:fname) == 3
8605 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008606" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 let curdir= getcwd()
8608 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008609 if s:NetrwLcd(fromdir)
8610" call Dret("s:NetrwUpload : lcd failure")
8611 return
8612 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008613 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008614 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 if exists("g:netrw_port") && g:netrw_port != ""
8616 let useport= " ".g:netrw_scpport." ".g:netrw_port
8617 else
8618 let useport= ""
8619 endif
8620 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8621 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008622 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008623 if s:NetrwLcd(curdir)
8624" call Dret("s:NetrwUpload : lcd failure")
8625 return
8626 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008627
8628 elseif a:tgt =~ '^ftp:'
8629 call s:NetrwMethod(a:tgt)
8630
8631 if b:netrw_method == 2
8632 " handle uploading a list of files via ftp+.netrc
8633 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008634 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008637 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639
8640 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008642" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 endif
8644
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008645 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008647
Bram Moolenaaradc21822011-04-01 18:03:16 +02008648 if tgtdir == ""
8649 let tgtdir= '/'
8650 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008652" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653
8654 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008655 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8656" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 endfor
8658
8659 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008660 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8663 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 endif
8665 " 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 +01008666 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008667 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8669 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8670 else
8671 bw!|q
8672 endif
8673
8674 elseif b:netrw_method == 3
8675 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8676 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008677 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008679 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008680
8681 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008682 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008685 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008686" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687 endif
8688
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008689 if exists("g:netrw_uid") && g:netrw_uid != ""
8690 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008691 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008692" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008693 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008694 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008696" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008697 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008698 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008699" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008700 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701 endif
8702
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008703 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008704" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705
8706 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008707 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 endif
8710
8711 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008712 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008714 endif
8715
8716 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008717 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719 endfor
8720
8721 " perform ftp:
8722 " -i : turns off interactive prompting from ftp
8723 " -n unix : DON'T use <.netrc>, even though it exists
8724 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008725 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008726 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008727 " 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 +01008728 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008729 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8731 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008732 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008733 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8734 let &debug = debugkeep
8735 let mod = 1
8736 else
8737 bw!|q
8738 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008739 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008740" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008741 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 endif
8743 else
8744 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8745 endif
8746 endif
8747
8748" call Dret("s:NetrwUpload")
8749endfun
8750
8751" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008752" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008753fun! s:NetrwPreview(path) range
8754" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008755" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8756" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008757 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008758 NetrwKeepj call s:NetrwOptionsSave("s:")
8759 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8760 NetrwKeepj call s:NetrwOptionsSafe(1)
8761 else
8762 NetrwKeepj call s:NetrwOptionsSafe(0)
8763 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008765" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008767" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8768 if g:netrw_preview
8769 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008770 let pvhkeep = &pvh
8771 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8772 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008773" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8774 else
8775 " horizontal split
8776 let pvhkeep = &pvh
8777 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8778 let &pvh = winheight(0) - winsz
8779" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008780 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008781 " g:netrw_preview g:netrw_alto
8782 " 1 : vert 1: top -- preview window is vertically split off and on the left
8783 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8784 " 0 : 1: top -- preview window is horizontally split off and on the top
8785 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8786 "
8787 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowse() check via
8788 " the BufEnter event set up in netrwPlugin.vim
8789" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8790 let eikeep = &ei
8791 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008792 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008793 let &ei= eikeep
8794" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008795 if exists("pvhkeep")
8796 let &pvh= pvhkeep
8797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008799 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 endif
8801 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008802 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 +00008803 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008804 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008805 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806" call Dret("NetrwPreview")
8807endfun
8808
8809" ---------------------------------------------------------------------
8810" s:NetrwRefresh: {{{2
8811fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008812" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008814 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("setl ma noro",'~'.expand("<slnum>"))
8816" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008817 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008818 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8819 if !exists("w:netrw_treetop")
8820 if exists("b:netrw_curdir")
8821 let w:netrw_treetop= b:netrw_curdir
8822 else
8823 let w:netrw_treetop= getcwd()
8824 endif
8825 endif
8826 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8827 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008828
8829 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008830 let screenposn = winsaveview()
8831" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832
8833" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8834" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8835 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008837 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008841
8842 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008843" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8844 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
8846 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008847 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8848 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8849" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8850 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8851 else
8852" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8853 2match none
8854 endif
8855 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
Bram Moolenaar97d62492012-11-15 21:28:22 +01008857" restore
8858 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008859" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860endfun
8861
8862" ---------------------------------------------------------------------
8863" s:NetrwRefreshDir: refreshes a directory by name {{{2
8864" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008865" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008867" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868 if g:netrw_fastbrowse == 0
8869 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008870" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008872" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873
8874 if tgtwin > 0
8875 " tgtwin is being displayed, so refresh it
8876 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008878 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008879 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008880 exe curwin."wincmd w"
8881
8882 elseif bufnr(a:dirname) > 0
8883 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8885 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 endif
8887
8888 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008890 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008891 endif
8892" call Dret("s:NetrwRefreshDir")
8893endfun
8894
8895" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008896" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8897" window number to do its editing in.
8898" Supports [count]C where the count, if present, is used to specify
8899" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008901" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008904 if a:1 == "" " :NetrwC win#
8905 let g:netrw_chgwin= winnr()
8906 else " :NetrwC
8907 let g:netrw_chgwin= a:1
8908 endif
8909 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008910 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008912 let g:netrw_chgwin= winnr()
8913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008914 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008915" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008916endfun
8917
8918" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008919" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8920" What this function does is to compute a priority for the patterns
8921" in the g:netrw_sort_sequence. It applies a substitute to any
8922" "files" that satisfy each pattern, putting the priority / in
8923" front. An "*" pattern handles the default priority.
8924fun! s:NetrwSetSort()
8925" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008926 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 if w:netrw_liststyle == s:LONGLIST
8928 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8929 else
8930 let seqlist = g:netrw_sort_sequence
8931 endif
8932 " sanity check -- insure that * appears somewhere
8933 if seqlist == ""
8934 let seqlist= '*'
8935 elseif seqlist !~ '\*'
8936 let seqlist= seqlist.',*'
8937 endif
8938 let priority = 1
8939 while seqlist != ""
8940 if seqlist =~ ','
8941 let seq = substitute(seqlist,',.*$','','e')
8942 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8943 else
8944 let seq = seqlist
8945 let seqlist = ""
8946 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008948 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008950 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008952 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008955
8956 " sanity check
8957 if w:netrw_bannercnt > line("$")
8958 " apparently no files were left after a Hiding pattern was used
8959" call Dret("SetSort : no files left after hiding")
8960 return
8961 endif
8962 if seq == '*'
8963 let starpriority= spriority
8964 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008965 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008966 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967 " sometimes multiple sorting patterns will match the same file or directory.
8968 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008969 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8970 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008971 endif
8972 let priority = priority + 1
8973 endwhile
8974 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8976 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008977 endif
8978
8979 " Following line associated with priority -- items that satisfy a priority
8980 " pattern get prefixed by ###/ which permits easy sorting by priority.
8981 " Sometimes files can satisfy multiple priority patterns -- only the latest
8982 " priority pattern needs to be retained. So, at this point, these excess
8983 " priority prefixes need to be removed, but not directories that happen to
8984 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008985 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8986 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008987 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988
8989" call Dret("SetSort")
8990endfun
8991
Bram Moolenaarff034192013-04-24 18:51:19 +02008992" ---------------------------------------------------------------------
8993" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8994" Implements [count]Tb (bookhist<b>)
8995" [count]Th (bookhist<h>)
8996" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008997fun! s:NetrwSetTgt(islocal,bookhist,choice)
8998" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008999
9000 if a:bookhist == 'b'
9001 " supports choosing a bookmark as a target using a qb-generated list
9002 let choice= a:choice - 1
9003 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009004 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009005 else
9006 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9007 endif
9008
9009 elseif a:bookhist == 'h'
9010 " supports choosing a history stack entry as a target using a qb-generated list
9011 let choice= (a:choice % g:netrw_dirhistmax) + 1
9012 if exists("g:netrw_dirhist_".choice)
9013 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009014 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009015 else
9016 echomsg "Sorry, history#".a:choice." not available!"
9017 endif
9018 endif
9019
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009020 " refresh the display
9021 if !exists("b:netrw_curdir")
9022 let b:netrw_curdir= getcwd()
9023 endif
9024 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9025
Bram Moolenaarff034192013-04-24 18:51:19 +02009026" call Dret("s:NetrwSetTgt")
9027endfun
9028
Bram Moolenaar446cb832008-06-24 21:56:24 +00009029" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009030" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009031fun! s:NetrwSortStyle(islocal)
9032" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009033 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009034 let svpos= winsaveview()
9035" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009036
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009037 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038 NetrwKeepj norm! 0
9039 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009040" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9041 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042
9043" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9044endfun
9045
9046" ---------------------------------------------------------------------
9047" s:NetrwSplit: mode {{{2
9048" =0 : net and o
9049" =1 : net and t
9050" =2 : net and v
9051" =3 : local and o
9052" =4 : local and t
9053" =5 : local and v
9054fun! s:NetrwSplit(mode)
9055" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9056
Bram Moolenaar97d62492012-11-15 21:28:22 +01009057 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058 call s:SaveWinVars()
9059
9060 if a:mode == 0
9061 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009062 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009063 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009065 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009067 NetrwKeepj call s:RestoreWinVars()
9068 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 unlet s:didsplit
9070
9071 elseif a:mode == 1
9072 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009073 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009074" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 tabnew
9076 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009077 NetrwKeepj call s:RestoreWinVars()
9078 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 unlet s:didsplit
9080
9081 elseif a:mode == 2
9082 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009083 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009084 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009085" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009086 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 NetrwKeepj call s:RestoreWinVars()
9089 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 unlet s:didsplit
9091
9092 elseif a:mode == 3
9093 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009094 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009095 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009097 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 NetrwKeepj call s:RestoreWinVars()
9100 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 unlet s:didsplit
9102
9103 elseif a:mode == 4
9104 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009105 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009106 let eikeep = &ei
9107 let netrw_winnr = winnr()
9108 let netrw_line = line(".")
9109 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009110 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009111 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009112 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009113 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9114 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009115 let &ei = eikeep
9116 let netrw_curdir = s:NetrwTreeDir(0)
9117" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009118 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009119 let b:netrw_curdir = netrw_curdir
9120 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009121 NetrwKeepj call s:RestoreWinVars()
9122 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009123 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009124 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009125 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9126 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009127 let &ei= eikeep
9128 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009129 unlet s:didsplit
9130
9131 elseif a:mode == 5
9132 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009133 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009134 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009135" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009136 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009138 NetrwKeepj call s:RestoreWinVars()
9139 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140 unlet s:didsplit
9141
9142 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009143 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 endif
9145
Bram Moolenaar97d62492012-11-15 21:28:22 +01009146 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009147" call Dret("s:NetrwSplit")
9148endfun
9149
9150" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009151" s:NetrwTgtMenu: {{{2
9152fun! s:NetrwTgtMenu()
9153 if !exists("s:netrw_menucnt")
9154 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009156" call Dfunc("s:NetrwTgtMenu()")
9157
9158 " the following test assures that gvim is running, has menus available, and has menus enabled.
9159 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9160 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009161" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009162 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9163 endif
9164 if !exists("s:netrw_initbookhist")
9165 call s:NetrwBookHistRead()
9166 endif
9167
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009168 " try to cull duplicate entries
9169 let tgtdict={}
9170
Bram Moolenaarff034192013-04-24 18:51:19 +02009171 " target bookmarked places
9172 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009173" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009174 let cnt= 1
9175 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009176 if has_key(tgtdict,bmd)
9177 let cnt= cnt + 1
9178 continue
9179 endif
9180 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009181 let ebmd= escape(bmd,g:netrw_menu_escape)
9182 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009183" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009184 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 +02009185 let cnt= cnt + 1
9186 endfor
9187 endif
9188
9189 " target directory browsing history
9190 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009191" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009192 let histcnt = 1
9193 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009194 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009195 if exists("g:netrw_dirhist_{histcnt}")
9196 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009197 if has_key(tgtdict,histentry)
9198 let histcnt = histcnt + 1
9199 continue
9200 endif
9201 let tgtdict[histentry] = histcnt
9202 let ehistentry = escape(histentry,g:netrw_menu_escape)
9203" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009204 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 +02009205 endif
9206 let histcnt = histcnt + 1
9207 endwhile
9208 endif
9209 endif
9210" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211endfun
9212
9213" ---------------------------------------------------------------------
9214" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9215" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009216fun! s:NetrwTreeDir(islocal)
9217" 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 Moolenaaraa3b15d2016-04-21 08:53:19 +02009218" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9219" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9220" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221
Bram Moolenaar8d043172014-01-23 14:24:41 +01009222 if exists("s:treedir")
9223 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
9224 let treedir= s:treedir
9225 unlet s:treedir
9226" call Dret("s:NetrwTreeDir ".treedir)
9227 return treedir
9228 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009229
Bram Moolenaar8d043172014-01-23 14:24:41 +01009230 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9231 let b:netrw_curdir= getcwd()
9232 endif
9233 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009234" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009236 let s:treecurpos= winsaveview()
9237" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9238
9239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009240" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9241" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009242
9243 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 let curline= substitute(getline('.'),"\t -->.*$",'','')
9245 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009246" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009247 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009248" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9249 elseif curline =~ '@$'
9250" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9251 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9252" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009254" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009255 let treedir= ""
9256 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257
9258 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9260" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009261" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009263" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009265" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9266 sil! NetrwKeepj %d _
9267" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009269" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009270" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271 endif
9272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009274 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9275" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9278" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9279" let newdir = w:netrw_treetop.'/'.potentialdir
9280" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9281" let treedir = s:NetrwTreePath(newdir)
9282" let w:netrw_treetop = newdir
9283" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9284" else
9285" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009286 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009287" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009289
9290 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295 return treedir
9296endfun
9297
9298" ---------------------------------------------------------------------
9299" s:NetrwTreeDisplay: recursive tree display {{{2
9300fun! s:NetrwTreeDisplay(dir,depth)
9301" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9302
9303 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009304 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305
9306 " install ../ and shortdir
9307 if a:depth == ""
9308 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009309" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009310 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009312 if a:dir == w:netrw_treetop
9313 let shortdir= a:dir
9314 else
9315 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9316 endif
9317 call setline(line("$")+1,a:depth.shortdir)
9318 else
9319 let shortdir= substitute(a:dir,'^.*/','','e')
9320 call setline(line("$")+1,a:depth.shortdir.'/')
9321 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009322" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323
9324 " append a / to dir if its missing one
9325 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326
9327 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009328 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009329" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330
Bram Moolenaar85850f32019-07-19 22:05:51 +02009331 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9332 if g:netrw_hide == 1
9333 " hide given patterns
9334 let listhide= split(g:netrw_list_hide,',')
9335" call Decho("listhide=".string(listhide))
9336 for pat in listhide
9337 call filter(w:netrw_treedict[dir],'v:val !~ "'.pat.'"')
9338 endfor
9339
9340 elseif g:netrw_hide == 2
9341 " show given patterns (only)
9342 let listhide= split(g:netrw_list_hide,',')
9343" call Decho("listhide=".string(listhide))
9344 let entries=[]
9345 for entry in w:netrw_treedict[dir]
9346 for pat in listhide
9347 if entry =~ pat
9348 call add(entries,entry)
9349 break
9350 endif
9351 endfor
9352 endfor
9353 let w:netrw_treedict[dir]= entries
9354 endif
9355 if depth != ""
9356 " always remove "." and ".." entries when there's depth
9357 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9358 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9359 endif
9360
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009361" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009363 if dir =~ '/$'
9364 let direntry= substitute(dir.entry,'[@/]$','','e')
9365 else
9366 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9367 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009369 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009370" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009371 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009372 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009373" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9374 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9375 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9376" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009377 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009378 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009380 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009381 endif
9382 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009383" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009384
Bram Moolenaar446cb832008-06-24 21:56:24 +00009385" call Dret("NetrwTreeDisplay")
9386endfun
9387
9388" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009389" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9390fun! s:NetrwRefreshTreeDict(dir)
9391" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009392 if !exists("w:netrw_treedict")
9393" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9394 return
9395 endif
9396
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009397 for entry in w:netrw_treedict[a:dir]
9398 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9399" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9400
9401 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9402" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9403 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009404 let liststar = s:NetrwGlob(direntry,'*',1)
9405 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009406 let w:netrw_treedict[direntry] = liststar + listdotstar
9407" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9408
9409 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9410" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9411 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009412 let liststar = s:NetrwGlob(direntry.'/','*',1)
9413 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009414 let w:netrw_treedict[direntry]= liststar + listdotstar
9415" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9416
9417 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9418" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9419 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009420 let liststar = s:NetrwGlob(direntry.'/','*',1)
9421 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009422" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9423
9424 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009425" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009426 endif
9427 endfor
9428" call Dret("s:NetrwRefreshTreeDict")
9429endfun
9430
9431" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009433" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009434fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009435 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009437" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9438" 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"),'~'.expand("<slnum>"))
9439" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440
9441 " update the treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("update the treetop",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 if !exists("w:netrw_treetop")
9444 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009446 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
9447 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 endif
9450
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452 " insure that we have a treedict, albeit empty
9453" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 let w:netrw_treedict= {}
9455 endif
9456
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009457 " update the dictionary for the current directory
9458" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009460 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009463 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464
9465 " if past banner, record word
9466 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9467 let fname= expand("<cword>")
9468 else
9469 let fname= ""
9470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9472" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
9474 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009475 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009476" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009477
9478 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9479 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009481 1d
9482 endwhile
9483
Bram Moolenaar13600302014-05-22 18:26:40 +02009484 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485
9486" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009487 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009488 endif
9489endfun
9490
9491" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009492" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009493" Normally, treetop is w:netrw_treetop, but a
9494" user of the function ( netrw#SetTreetop() )
9495" wipes that out prior to calling this function
9496fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009497" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9498 if line(".") < w:netrw_bannercnt + 2
9499 let treedir= a:treetop
9500 if treedir !~ '/$'
9501 let treedir= treedir.'/'
9502 endif
9503" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9504 return treedir
9505 endif
9506
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009507 let svpos = winsaveview()
9508" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009509 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009511 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9513 let curline= getline('.')
9514" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9515 if curline =~ '/$'
9516" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9517 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9518" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9519 elseif curline =~ '@\s\+-->'
9520" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9521 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9522 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9523" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009524 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009526 let treedir= ""
9527 endif
9528 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9530" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009531 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9532 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9533 let treedir= dirname.treedir
9534 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009536 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009537" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009538 if a:treetop =~ '/$'
9539 let treedir= a:treetop.treedir
9540 else
9541 let treedir= a:treetop.'/'.treedir
9542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009543" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009544 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009545" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009546" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9547 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009548" call Dret("s:NetrwTreePath <".treedir.">")
9549 return treedir
9550endfun
9551
9552" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009553" s:NetrwWideListing: {{{2
9554fun! s:NetrwWideListing()
9555
9556 if w:netrw_liststyle == s:WIDELIST
9557" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9558 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009559 " cpf: characters per filename
9560 " fpl: filenames per line
9561 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009562 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009563 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009564" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009565 let b:netrw_cpf= 0
9566 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009567 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009568 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9569 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009570 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009571 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572" call Dret("NetrwWideListing")
9573 return
9574 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009575 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009576 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578
9579 " determine qty files per line (fpl)
9580 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9581 if w:netrw_fpl <= 0
9582 let w:netrw_fpl= 1
9583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009584" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009585
9586 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587 " fpc: files per column of wide listing
9588 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9591 let newcolstart = w:netrw_bannercnt + fpc
9592 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009593" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009594 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009595" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009596 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009597 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009598 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 while line("$") >= newcolstart
9600 if newcolend > line("$") | let newcolend= line("$") | endif
9601 let newcolqty= newcolend - newcolstart
9602 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009603 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009604 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009605 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009606 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009607 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009608 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009609 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009612 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009613" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009614 if @* != keepregstar | sil! let @* = keepregstar | endif
9615 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009616 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009617 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9618 NetrwKeepj call histdel("/",-1)
9619 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9620 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009621" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009622 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009623 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009624" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009625" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009626 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009627 else
9628 if hasmapto("w","n")
9629 sil! nunmap <buffer> w
9630 endif
9631 if hasmapto("b","n")
9632 sil! nunmap <buffer> b
9633 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009634 endif
9635
9636endfun
9637
9638" ---------------------------------------------------------------------
9639" s:PerformListing: {{{2
9640fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009641" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9642" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009643" call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
9644 sil! NetrwKeepj %d _
9645" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646
Bram Moolenaar15146672011-10-20 22:22:38 +02009647 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009648" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009649 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009650
Bram Moolenaar85850f32019-07-19 22:05:51 +02009651 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009652 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009653" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654
9655" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009656" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657" endif " Decho
9658
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9661 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009662" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9663 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 endif
9665
9666 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009667 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668
9669 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009670 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009672 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009673 if exists("g:netrw_pchk")
9674 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9675 " failure detections.
9676 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009678 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9679 endif
9680 if exists("g:netrw_pchk")
9681 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9682 else
9683 let curdir= b:netrw_curdir
9684 endif
9685 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9686 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9687 else
9688 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009689 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009690 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009691 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009692 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009695 let w:netrw_bannercnt= 1
9696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009697" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9698" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009699
Bram Moolenaar85850f32019-07-19 22:05:51 +02009700 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009702 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703 let sortby= sortby." reversed"
9704 endif
9705
9706 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009707 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009708" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009709 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009712 NetrwKeepj put ='\" Sorted by '.sortby
9713 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009714 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9715 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009717 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009718 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009719 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9720 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009721 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009722" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009723" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725
Bram Moolenaar85850f32019-07-19 22:05:51 +02009726 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009727 if g:netrw_banner
9728 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009730 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009731 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009732 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009733 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009735 endif
9736 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009737 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009738" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009740 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009742
9743 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009744 if g:netrw_banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02009745" call Decho("--handle hiding/showing (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009746 if g:netrw_list_hide != "" && g:netrw_hide
9747 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009748 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009749 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009750 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009751 endif
9752 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009753 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009754 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009755
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009756" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009759 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009760" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009761 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009762 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009763" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009764" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766
9767 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009768 if g:netrw_banner
9769 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009770 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009771" call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009772" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009773" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009774 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009775
Bram Moolenaar446cb832008-06-24 21:56:24 +00009776 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009777" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009779 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009781 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009782 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009783" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009784" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9785 return
9786 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009788
9789 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009790 if !exists("w:netrw_bannercnt")
9791 let w:netrw_bannercnt= 0
9792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9794" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9795" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009796
Bram Moolenaar5c736222010-01-06 20:54:52 +01009797 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009798" call Decho("manipulate directory listing (hide)",'~'.expand("<slnum>"))
9799" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009801 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009803 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009804" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009806 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009808" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009809 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810
Bram Moolenaar5c736222010-01-06 20:54:52 +01009811 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009813 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009814 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009815 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 else
9817 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009818 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819 endif
9820 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009821
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009824 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9825 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009826
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009827 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009828 " exten: sort by extension
9829 " The histdel(...,-1) calls remove the last search from the search history
9830" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009831 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9832 NetrwKeepj call histdel("/",-1)
9833 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9834 NetrwKeepj call histdel("/",-1)
9835 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9836 NetrwKeepj call histdel("/",-1)
9837 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9838" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009839 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009840 " normal direction sorting
9841 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9842 else
9843 " reverse direction sorting
9844 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9845 endif
9846 endif
9847 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9848 NetrwKeepj call histdel("/",-1)
9849
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009851 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009853 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009855 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009858 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009859 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009860" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009861 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9862 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009863 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864 endif
9865
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009866 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009868 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009869 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009870 call histdel("/",-1)
9871 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009872 endif
9873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009874" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009875
9876 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9878" 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)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880" 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)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" 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)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009884 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009885 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009887 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009888 endif
9889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009891 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9893 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9896 else
9897" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9898" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9899" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9900" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009901 endif
9902
9903 " record previous current directory
9904 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906
9907 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9909" 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)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" 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)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009912 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913" 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)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009914
9915 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009917 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" 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)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009919 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009921 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9922 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009923" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009924" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925
Bram Moolenaar8d043172014-01-23 14:24:41 +01009926 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9928" 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)",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009929" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9930 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 unlet s:treecurpos
9932 endif
9933
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009934" 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)",'~'.expand("<slnum>"))
9935" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9937endfun
9938
9939" ---------------------------------------------------------------------
9940" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009941fun! s:SetupNetrwStatusLine(statline)
9942" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9943
9944 if !exists("s:netrw_setup_statline")
9945 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009947
9948 if !exists("s:netrw_users_stl")
9949 let s:netrw_users_stl= &stl
9950 endif
9951 if !exists("s:netrw_users_ls")
9952 let s:netrw_users_ls= &laststatus
9953 endif
9954
9955 " set up User9 highlighting as needed
9956 let keepa= @a
9957 redir @a
9958 try
9959 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009961 if &bg == "dark"
9962 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9963 else
9964 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9965 endif
9966 endtry
9967 redir END
9968 let @a= keepa
9969 endif
9970
9971 " set up status line (may use User9 highlighting)
9972 " insure that windows have a statusline
9973 " make sure statusline is displayed
9974 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009975 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009976" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009978
9979" call Dret("SetupNetrwStatusLine : stl=".&stl)
9980endfun
9981
Bram Moolenaar85850f32019-07-19 22:05:51 +02009982" =========================================
9983" Remote Directory Browsing Support: {{{1
9984" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009985
9986" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009987" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9988" This function assumes that a long listing will be received. Size, time,
9989" and reverse sorts will be requested of the server but not otherwise
9990" enforced here.
9991fun! s:NetrwRemoteFtpCmd(path,listcmd)
9992" 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 : "???")))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009993" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009994 " sanity check: {{{3
9995 if !exists("w:netrw_method")
9996 if exists("b:netrw_method")
9997 let w:netrw_method= b:netrw_method
9998 else
9999 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10000" call Dret("NetrwRemoteFtpCmd")
10001 return
10002 endif
10003 endif
10004
10005 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10006 let ffkeep= &ff
10007 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010009
10010 " clear off any older non-banner lines " {{{3
10011 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010012" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10013 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010014
10015 ".........................................
10016 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10017 " ftp + <.netrc>: Method #2
10018 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010020 endif
10021 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010022 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010024 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010025 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010027 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10029 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010030 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10032 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010033 endif
10034
10035 ".........................................
10036 elseif w:netrw_method == 3 " {{{3
10037 " ftp + machine,id,passwd,filename: Method #3
10038 setl ff=unix
10039 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010041 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010042 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010043 endif
10044
10045 " handle userid and password
10046 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010048 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10049 call NetUserPass("ftp:".host)
10050 endif
10051 if exists("g:netrw_uid") && g:netrw_uid != ""
10052 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010054 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010055 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010056 endif
10057 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010058 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010059 endif
10060 endif
10061
10062 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010063 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010064 endif
10065 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010066 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010068 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010069 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010070
10071 " perform ftp:
10072 " -i : turns off interactive prompting from ftp
10073 " -n unix : DON'T use <.netrc>, even though it exists
10074 " -n win32: quit being obnoxious about password
10075 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010078" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10080" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010081 endif
10082
10083 ".........................................
10084 elseif w:netrw_method == 9 " {{{3
10085 " sftp username@machine: Method #9
10086 " s:netrw_sftp_cmd
10087 setl ff=unix
10088
10089 " restore settings
10090 let &ff= ffkeep
10091" call Dret("NetrwRemoteFtpCmd")
10092 return
10093
10094 ".........................................
10095 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010096 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010097 endif
10098
10099 " cleanup for Windows " {{{3
10100 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 sil! NetrwKeepj %s/\r$//e
10102 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010103 endif
10104 if a:listcmd == "dir"
10105 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010106 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10107 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10108 NetrwKeepj call histdel("/",-1)
10109 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010110 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010111 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10112 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010113 endif
10114 endif
10115
10116 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10117 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010118 exe 'NetrwKeepj '.w:netrw_bannercnt
10119 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010120 endif
10121 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010122 exe 'NetrwKeepj '.w:netrw_bannercnt
10123 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010124 endif
10125
10126 " restore settings " {{{3
10127 let &ff= ffkeep
10128" call Dret("NetrwRemoteFtpCmd")
10129endfun
10130
10131" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132" s:NetrwRemoteListing: {{{2
10133fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010134" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010135
Bram Moolenaara6878372014-03-22 21:02:50 +010010136 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10137 let w:netrw_bannercnt= s:bannercnt
10138 endif
10139 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10140 let w:netrw_bannercnt= s:bannercnt
10141 endif
10142
Bram Moolenaar446cb832008-06-24 21:56:24 +000010143 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010144
Bram Moolenaar446cb832008-06-24 21:56:24 +000010145 " sanity check:
10146 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010148 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150 if !exists("g:netrw_quiet")
10151 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10152 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010153 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010154" call Dret("s:NetrwRemoteListing -1")
10155 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010156 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010157
Bram Moolenaar8d043172014-01-23 14:24:41 +010010158 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010161 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010162 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 +000010163 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010164 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 +000010165 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010166 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010167
Bram Moolenaar85850f32019-07-19 22:05:51 +020010168 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010169" call Dret("s:NetrwRemoteListing -1")
10170 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010171 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010172" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010173
Bram Moolenaar446cb832008-06-24 21:56:24 +000010174 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010175" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010176 let w:netrw_method= b:netrw_method
10177 endif
10178
Bram Moolenaar13600302014-05-22 18:26:40 +020010179 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010180 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010181" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010182 let s:method = "ftp"
10183 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010184 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010185 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010186 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010187 let listcmd= g:netrw_ftp_sizelist_cmd
10188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010189" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010190 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010191" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010192
Bram Moolenaara6878372014-03-22 21:02:50 +010010193 " report on missing file or directory messages
10194 if search('[Nn]o such file or directory\|Failed to change directory')
10195 let mesg= getline(".")
10196 if exists("w:netrw_bannercnt")
10197 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010198 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010199 setl noma
10200 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010201 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010202 call netrw#ErrorMsg(s:WARNING,mesg,96)
10203" call Dret("s:NetrwRemoteListing : -1")
10204 return -1
10205 endif
10206
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010207 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010208 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010209" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010210 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010211
10212 " cleanup
10213 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010214 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10215 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010216 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010217 sil! NetrwKeepj %s/\r$//e
10218 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010219
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010220 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010221 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010222 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010223 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010224" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010225 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010226" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010227 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010228 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010229 exe "sil! NetrwKeepj ".line1
10230 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010231
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010232" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010233 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010234" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010235 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10236 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010237 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010238" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010239 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10240 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10241 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10242 NetrwKeepj call histdel("/",-1)
10243 NetrwKeepj call histdel("/",-1)
10244 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010245 endif
10246 endif
10247
Bram Moolenaar13600302014-05-22 18:26:40 +020010248 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010249 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010250" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010251 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010252" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010253 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10255 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010256 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10258 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10259 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10260 NetrwKeepj call histdel("/",-1)
10261 NetrwKeepj call histdel("/",-1)
10262 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010263 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010264 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10265 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010266 endif
10267 else
10268 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010269" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010270 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010271 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010272" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10273 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10274" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010275 endif
10276 endif
10277
10278 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010280" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10282 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010283 endif
10284 endif
10285
10286 if w:netrw_liststyle == s:LONGLIST
10287 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010288" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289
10290 if s:method == "ftp"
10291 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010293 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010295 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010296 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010297 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010298 sil! NetrwKeepj 1
10299 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010300 let line2= line(".")
10301 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010302 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010304 endif
10305 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 exe "sil! NetrwKeepj ".line1
10307 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 endif
10309
10310 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010311" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010312 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 +000010313 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010314" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010315 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010317 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10318 NetrwKeepj call histdel("/",-1)
10319 NetrwKeepj call histdel("/",-1)
10320 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010321 endif
10322 endif
10323
10324" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010325" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010326" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010327
10328" call Dret("s:NetrwRemoteListing 0")
10329 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010330endfun
10331
Bram Moolenaar446cb832008-06-24 21:56:24 +000010332" ---------------------------------------------------------------------
10333" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10334fun! s:NetrwRemoteRm(usrhost,path) range
10335" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010336" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010337 let svpos= winsaveview()
10338" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010339
10340 let all= 0
10341 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10342 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010343" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010344 for fname in s:netrwmarkfilelist_{bufnr("%")}
10345 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010346 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010347 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010348 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010349 let all= 1
10350 endif
10351 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010352 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353
10354 else
10355 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010356" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357
10358 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010359 let keepsol = &l:sol
10360 setl nosol
10361 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362
10363 " remove multiple files and directories
10364 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010365 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010367 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010369 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370 let all= 1
10371 endif
10372 let ctr= ctr + 1
10373 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010374 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010375 endif
10376
10377 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010379 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10381 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382
10383" call Dret("s:NetrwRemoteRm")
10384endfun
10385
10386" ---------------------------------------------------------------------
10387" s:NetrwRemoteRmFile: {{{2
10388fun! s:NetrwRemoteRmFile(path,rmfile,all)
10389" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10390
10391 let all= a:all
10392 let ok = ""
10393
10394 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10395 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if !all
10398 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 call inputsave()
10401 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10402 call inputrestore()
10403 echohl NONE
10404 if ok == ""
10405 let ok="no"
10406 endif
10407 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010408 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 let all= 1
10410 endif
10411 endif
10412
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010413 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010416" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010418 if path =~ '^\a\{3,}://'
10419 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010421 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10423 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010424" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010426" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010428 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 let ok="q"
10430 else
10431 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10433" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10434" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010436 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010438 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442 if v:shell_error != 0
10443 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010444 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445 else
10446 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10447 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010448 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010451" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 endif
10453 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010454 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 endif
10457
10458 else
10459 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 if !all
10462 call inputsave()
10463 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10464 call inputrestore()
10465 if ok == ""
10466 let ok="no"
10467 endif
10468 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010469 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 let all= 1
10471 endif
10472 endif
10473
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010474 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010476 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 else
10478 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010479 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10480" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010481 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483
10484 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10486 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10487" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010488 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010489" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490
10491 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010492 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 endif
10494 endif
10495 endif
10496
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010497 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 endif
10500 endif
10501
10502" call Dret("s:NetrwRemoteRmFile ".ok)
10503 return ok
10504endfun
10505
10506" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507" s:NetrwRemoteRename: rename a remote file or directory {{{2
10508fun! s:NetrwRemoteRename(usrhost,path) range
10509" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10510
10511 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010512 let svpos = winsaveview()
10513" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 let ctr = a:firstline
10515 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10516
10517 " rename files given by the markfilelist
10518 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10519 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 if exists("subfrom")
10522 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010523" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010524 else
10525 call inputsave()
10526 let newname= input("Moving ".oldname." to : ",oldname)
10527 call inputrestore()
10528 if newname =~ '^s/'
10529 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10530 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10531 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010532" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533 endif
10534 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010537 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539 let oldname= s:ShellEscape(a:path.oldname)
10540 let newname= s:ShellEscape(a:path.newname)
10541" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010542 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543 endif
10544
10545 endfor
10546 call s:NetrwUnMarkFile(1)
10547
10548 else
10549
10550 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551 let keepsol= &l:sol
10552 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010554 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555
10556 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010557" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558
10559 call inputsave()
10560 let newname= input("Moving ".oldname." to : ",oldname)
10561 call inputrestore()
10562
10563 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10564 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10565 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566 let oldname= s:ShellEscape(a:path.oldname)
10567 let newname= s:ShellEscape(a:path.newname)
10568" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010569 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570 endif
10571
10572 let ctr= ctr + 1
10573 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 endif
10576
10577 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010578 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010579" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10580 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581
10582" call Dret("NetrwRemoteRename")
10583endfun
10584
Bram Moolenaar85850f32019-07-19 22:05:51 +020010585" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586" Local Directory Browsing Support: {{{1
10587" ==========================================
10588
10589" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010590" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010591" Should accept: file://localhost/etc/fstab
10592" file:///etc/fstab
10593" file:///c:/WINDOWS/clock.avi
10594" file:///c|/WINDOWS/clock.avi
10595" file://localhost/c:/WINDOWS/clock.avi
10596" file://localhost/c|/WINDOWS/clock.avi
10597" file://c:/foo.txt
10598" file:///c:/foo.txt
10599" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010600fun! netrw#FileUrlEdit(fname)
10601" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010602 let fname = a:fname
10603 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010605 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010607 endif
10608 if (has("win32") || has("win95") || has("win64") || has("win16"))
10609 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010610" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010611 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010612" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010613 endif
10614 endif
10615 let fname2396 = netrw#RFC2396(fname)
10616 let fname2396e= fnameescape(fname2396)
10617 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10618 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010620 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010622 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10623 endif
10624 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010625
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10627" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010628 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010629 exe 'NetrwKeepj keepalt edit '.plainfname
10630 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10631
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010633" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010634 exe "sil doau BufReadPost ".fname2396e
10635endfun
10636
10637" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638" netrw#LocalBrowseCheck: {{{2
10639fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010640 " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(),
10641 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10642 "
10643 " unfortunate interaction -- split window debugging can't be used here, must use
10644 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10645 " another call to LocalBrowseCheck() when attempts to write
10646 " to the DBG buffer are made.
10647 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 " The &ft == "netrw" test was installed because the BufEnter event
10649 " would hit when re-entering netrw windows, creating unexpected
10650 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010651" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010652" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010653" 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,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010654" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10656" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010657
Bram Moolenaar97d62492012-11-15 21:28:22 +010010658 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659 if isdirectory(s:NetrwFile(a:dirname))
10660" 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,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010661
Bram Moolenaar97d62492012-11-15 21:28:22 +010010662 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10664" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010665 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010666
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010669 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010670
Bram Moolenaar5c736222010-01-06 20:54:52 +010010671 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010673 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010674 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010677" call Dret("netrw#LocalBrowseCheck")
10678 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010680
Bram Moolenaar85850f32019-07-19 22:05:51 +020010681 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010682 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10683 " AND IF the listing style is not a tree listing
10684 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010686 let ibuf = 1
10687 let buflast = bufnr("$")
10688 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10690 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010691 endif
10692 let ibuf= ibuf + 1
10693 endwhile
10694 endif
10695 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" 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,'~'.expand("<slnum>"))
10697" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010699" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700endfun
10701
10702" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010703" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704" performed any shell command. The idea is to cause all local-browsing
10705" buffers to be refreshed after a user has executed some shell command,
10706" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010707fun! s:LocalBrowseRefresh()
10708" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010709" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10710" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010711
Bram Moolenaar446cb832008-06-24 21:56:24 +000010712 " determine which buffers currently reside in a tab
10713 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010714" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 return
10716 endif
10717 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010718" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 return
10720 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010721 if exists("s:netrw_events") && s:netrw_events == 1
10722 " s:LocalFastBrowser gets called (indirectly) from a
10723 let s:netrw_events= 2
10724" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10725 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010726 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010727 let itab = 1
10728 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010729 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730 while itab <= tabpagenr("$")
10731 let buftablist = buftablist + tabpagebuflist()
10732 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010733 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010734 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010735" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10736" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10738 " | refresh any netrw window
10739 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010740 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741 let ibl = 0
10742 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010744 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10745 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010746 " (ibuf not shown in a current window AND
10747 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010748" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10749 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010752 continue
10753 elseif index(tabpagebuflist(),ibuf) != -1
10754 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010757 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010758 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10759 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10760 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010763 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10764 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10765 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010766 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010767 endif
10768 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010771" call Decho("restore window: win_gotoid(".curwinid.")")
10772 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010773 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774
Bram Moolenaara6878372014-03-22 21:02:50 +010010775" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776endfun
10777
10778" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010779" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10780"
10781" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010783" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10784" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010785" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010786"
10787" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10788" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010789" (re-using a buffer may not be as accurate)
10790"
10791" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
10792" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10793" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10794" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10795" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010796fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010797" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10798" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10799" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10800" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010801
10802 " initialize browselist, a list of buffer numbers that the local browser has used
10803 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010804" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010805 let s:netrw_browselist= []
10806 endif
10807
10808 " append current buffer to fastbrowse list
10809 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010810" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010811 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010812" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010813 endif
10814
10815 " enable autocmd events to handle refreshing/removing local browser buffers
10816 " If local browse buffer is currently showing: refresh it
10817 " If local browse buffer is currently hidden : wipe it
10818 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10819 " =1 : medium speed, re-use directory listing for remote only
10820 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010821 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10822 let s:netrw_events= 1
10823 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010824 au!
10825 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010827 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010830 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 endif
10832 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833
10834 " user must have changed fastbrowse to its fast setting, so remove
10835 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010836 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010837" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010838 unlet s:netrw_events
10839 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010840 au!
10841 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010842 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010843 endif
10844
Bram Moolenaar85850f32019-07-19 22:05:51 +020010845" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846endfun
10847
10848" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010849" s:LocalListing: does the job of "ls" for local directories {{{2
10850fun! s:LocalListing()
10851" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10853" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10854" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010855
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
10857" 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",'~'.expand("<slnum>"))|endif
10858" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010859
10860 " get the list of files contained in the current directory
10861 let dirname = b:netrw_curdir
10862 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010863 let filelist = s:NetrwGlob(dirname,"*",0)
10864 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010865" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010866
10867 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010869 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10870 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010872 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010873" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010874 endif
10875
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010876" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010877" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010878" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010879
10880 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10881 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10882 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10884" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010887
10888 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010889" call Decho(" ",'~'.expand("<slnum>"))
10890" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010891
10892 if getftype(filename) == "link"
10893 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010895 let pfile= filename."@"
10896
10897 elseif getftype(filename) == "socket"
10898 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010900 let pfile= filename."="
10901
10902 elseif getftype(filename) == "fifo"
10903 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010905 let pfile= filename."|"
10906
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010907 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010908 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010910 let pfile= filename."/"
10911
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010913 if (has("win32") || has("win95") || has("win64") || has("win16"))
10914 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10915 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010917 let pfile= filename."*"
10918 else
10919 " normal file
10920 let pfile= filename
10921 endif
10922 elseif executable(filename)
10923 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010925 let pfile= filename."*"
10926 else
10927 " normal file
10928 let pfile= filename
10929 endif
10930
10931 else
10932 " normal file
10933 let pfile= filename
10934 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010935" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010936
10937 if pfile =~ '//$'
10938 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010939" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010940 endif
10941 let pfile= strpart(pfile,dirnamelen)
10942 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010943" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
10944" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010945
10946 if w:netrw_liststyle == s:LONGLIST
10947 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010948 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010949 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010950 let sz= s:NetrwHumanReadable(sz)
10951 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010952 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
10953 let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010954" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010955 endif
10956
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010957 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010958 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010959 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010960" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010961 let t = getftime(filename)
10962 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010010963" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010964 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010965 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010966
10967 elseif g:netrw_sort_by =~ "^s"
10968 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010969" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010970 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010971 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010972 let sz= s:NetrwHumanReadable(sz)
10973 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010974 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010976 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010977 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010978
10979 else
10980 " sort by name
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010981" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010982 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010983 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010984" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010010985 endfor
10986
10987 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010988 sil! NetrwKeepj g/^$/d
10989 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010990 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010992 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10993
10994" call Dret("s:LocalListing")
10995endfun
10996
10997" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10999fun! s:NetrwLocalExecute(cmd)
11000" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11001 let ykeep= @@
11002 " sanity check
11003 if !executable(a:cmd)
11004 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11005 let @@= ykeep
11006" call Dret("s:NetrwLocalExecute")
11007 return
11008 endif
11009
11010 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011012 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014
11015 " strip any ansi escape sequences off
11016 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11017
11018 " show user the result(s)
11019 echomsg result
11020 let @@= ykeep
11021
11022" call Dret("s:NetrwLocalExecute")
11023endfun
11024
11025" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011026" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027fun! s:NetrwLocalRename(path) range
11028" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11029
11030 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011031 let ykeep = @@
11032 let ctr = a:firstline
11033 let svpos = winsaveview()
11034 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011035" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036
11037 " rename files given by the markfilelist
11038 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11039 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011040" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041 if exists("subfrom")
11042 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 else
11045 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011046 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011047 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048 if newname =~ ''
11049 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11050 let newname = substitute(newname,'^.*','','')
11051 elseif newname =~ ''
11052 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11053 let newname = substitute(newname,'[^/]*','','')
11054 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 if newname =~ '^s/'
11056 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11057 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011058" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 let newname = substitute(oldname,subfrom,subto,'')
11060 endif
11061 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011062 if !all && filereadable(newname)
11063 call inputsave()
11064 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11065 call inputrestore()
11066 if response == "all"
11067 let all= 1
11068 elseif response != "y" && response != "yes"
11069 " refresh the directory
11070" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11071 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11072" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11073 NetrwKeepj call winrestview(svpos)
11074 let @@= ykeep
11075" call Dret("NetrwLocalRename")
11076 return
11077 endif
11078 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011079 call rename(oldname,newname)
11080 endfor
11081 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011082
Bram Moolenaar97d62492012-11-15 21:28:22 +010011083 else
11084
11085 " attempt to rename files/directories
11086 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011087 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011088
11089 " sanity checks
11090 if line(".") < w:netrw_bannercnt
11091 let ctr= ctr + 1
11092 continue
11093 endif
11094 let curword= s:NetrwGetWord()
11095 if curword == "./" || curword == "../"
11096 let ctr= ctr + 1
11097 continue
11098 endif
11099
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011100 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011101 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011102" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011103
11104 call inputsave()
11105 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11106 call inputrestore()
11107
11108 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011109" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011110
11111 let ctr= ctr + 1
11112 endwhile
11113 endif
11114
11115 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011117 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011118" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11119 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011120 let @@= ykeep
11121
11122" call Dret("NetrwLocalRename")
11123endfun
11124
11125" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011126" s:NetrwLocalRm: {{{2
11127fun! s:NetrwLocalRm(path) range
11128" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011130
11131 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011132 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011133 let ret = 0
11134 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011135 let svpos = winsaveview()
11136" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011137
11138 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11139 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011141 for fname in s:netrwmarkfilelist_{bufnr("%")}
11142 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011143 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011144 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011145 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011146 let all= 1
11147 endif
11148 endfor
11149 call s:NetrwUnMarkFile(1)
11150
11151 else
11152 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011154
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155 let keepsol= &l:sol
11156 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011157 let ctr = a:firstline
11158 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011159 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011160
11161 " sanity checks
11162 if line(".") < w:netrw_bannercnt
11163 let ctr= ctr + 1
11164 continue
11165 endif
11166 let curword= s:NetrwGetWord()
11167 if curword == "./" || curword == "../"
11168 let ctr= ctr + 1
11169 continue
11170 endif
11171 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011172 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011173 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011174 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011175 let all= 1
11176 endif
11177 let ctr= ctr + 1
11178 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011179 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011180 endif
11181
11182 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011183" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011184 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011185 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011186" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11187 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011188 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011189 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011190
11191" call Dret("s:NetrwLocalRm")
11192endfun
11193
11194" ---------------------------------------------------------------------
11195" s:NetrwLocalRmFile: remove file fname given the path {{{2
11196" Give confirmation prompt unless all==1
11197fun! s:NetrwLocalRmFile(path,fname,all)
11198" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011199
Bram Moolenaar446cb832008-06-24 21:56:24 +000011200 let all= a:all
11201 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011202 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011203 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11204" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011205
11206 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11207 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011209 if !all
11210 echohl Statement
11211 call inputsave()
11212 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11213 call inputrestore()
11214 echohl NONE
11215 if ok == ""
11216 let ok="no"
11217 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011219 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011221 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011222 let all= 1
11223 endif
11224 endif
11225
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011226 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011227 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011229 endif
11230
11231 else
11232 " attempt to remove directory
11233 if !all
11234 echohl Statement
11235 call inputsave()
11236 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11237 call inputrestore()
11238 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11239 if ok == ""
11240 let ok="no"
11241 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011242 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011243 let all= 1
11244 endif
11245 endif
11246 let rmfile= substitute(rmfile,'[\/]$','','e')
11247
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011248 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011249 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011250" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11251 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11252" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011253
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011254 if v:shell_error != 0
11255" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11256 let errcode= s:NetrwDelete(rmfile)
11257" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011258
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011259 if errcode != 0
11260 if has("unix")
11261" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11262 call system("rm ".s:ShellEscape(rmfile))
11263 if v:shell_error != 0 && !exists("g:netrw_quiet")
11264 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11265 let ok="no"
11266 endif
11267 elseif !exists("g:netrw_quiet")
11268 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011269 let ok="no"
11270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011271 endif
11272 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011273 else
11274 if delete(rmfile,"d")
11275 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11276 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011277 endif
11278 endif
11279 endif
11280
11281" call Dret("s:NetrwLocalRmFile ".ok)
11282 return ok
11283endfun
11284
Bram Moolenaar85850f32019-07-19 22:05:51 +020011285" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011286" Support Functions: {{{1
11287
Bram Moolenaar488c6512005-08-11 20:09:58 +000011288" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011289" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11290" 0: marked file list of current buffer
11291" 1: marked file target
11292fun! netrw#Access(ilist)
11293 if a:ilist == 0
11294 if exists("s:netrwmarkfilelist_".bufnr('%'))
11295 return s:netrwmarkfilelist_{bufnr('%')}
11296 else
11297 return "no-list-buf#".bufnr('%')
11298 endif
11299 elseif a:ilist == 1
11300 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011301 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011302endfun
11303
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011304" ---------------------------------------------------------------------
11305" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11306fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011307 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011308endfun
11309
Bram Moolenaara6878372014-03-22 21:02:50 +010011310" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011311" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11312" I expect this function to be used in
11313" :PChkAssert netrw#Expose("netrwmarkfilelist")
11314" for example.
11315fun! netrw#Expose(varname)
11316" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011317 if exists("s:".a:varname)
11318 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011319" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011320 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011321" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011322 if type(retval) == 3
11323 let retval = copy(retval)
11324 let i = 0
11325 while i < len(retval)
11326 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11327 let i = i + 1
11328 endwhile
11329 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011330" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011331 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011332 else
11333" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011334 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011335 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011336" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011337 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011338 endif
11339
11340" call Dret("netrw#Expose ".string(retval))
11341 return retval
11342endfun
11343
11344" ---------------------------------------------------------------------
11345" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11346fun! netrw#Modify(varname,newvalue)
11347" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11348 exe "let s:".a:varname."= ".string(a:newvalue)
11349" call Dret("netrw#Modify")
11350endfun
11351
11352" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011353" netrw#RFC2396: converts %xx into characters {{{2
11354fun! netrw#RFC2396(fname)
11355" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11356 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11357" call Dret("netrw#RFC2396 ".fname)
11358 return fname
11359endfun
11360
11361" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011362" netrw#UserMaps: supports user-specified maps {{{2
11363" see :help function()
11364"
11365" g:Netrw_UserMaps is a List with members such as:
11366" [[keymap sequence, function reference],...]
11367"
11368" The referenced function may return a string,
11369" refresh : refresh the display
11370" -other- : this string will be executed
11371" or it may return a List of strings.
11372"
11373" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011374" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011375" Related functions:
11376" netrw#Expose(varname) -- see s:varname variables
11377" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11378" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11379fun! netrw#UserMaps(islocal)
11380" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11381" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11382
11383 " set up usermaplist
11384 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11385" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11386 for umap in g:Netrw_UserMaps
11387" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11388" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11389 " if umap[0] is a string and umap[1] is a string holding a function name
11390 if type(umap[0]) == 1 && type(umap[1]) == 1
11391" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11392 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11393 else
11394 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11395 endif
11396 endfor
11397 endif
11398" call Dret("netrw#UserMaps")
11399endfun
11400
11401" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011402" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11403fun! netrw#WinPath(path)
11404" call Dfunc("netrw#WinPath(path<".a:path.">)")
11405 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11406 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011407 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011408 " remove trailing slash (Win95)
11409 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11410 " remove escaped spaces
11411 let path = substitute(path, '\ ', ' ', 'g')
11412 " convert slashes to backslashes
11413 let path = substitute(path, '/', '\', 'g')
11414 else
11415 let path= a:path
11416 endif
11417" call Dret("netrw#WinPath <".path.">")
11418 return path
11419endfun
11420
11421" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011422" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11423" cb : bl2mf=0 add marked files to buffer list
11424" cB : bl2mf=1 use bufferlist to mark files
11425" (mnemonic: cb = copy (marked files) to buffer list)
11426fun! s:NetrwBadd(islocal,bl2mf)
11427" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11428 if a:bl2mf
11429 " cB: add buffer list to marked files
11430 redir => bufl
11431 ls
11432 redir END
11433 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11434 for fname in bufl
11435 call s:NetrwMarkFile(a:islocal,fname)
11436 endfor
11437 else
11438 " cb: add marked files to buffer list
11439 for fname in s:netrwmarkfilelist_{bufnr("%")}
11440" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11441 exe "badd ".fnameescape(fname)
11442 endfor
11443 let curbufnr = bufnr("%")
11444 let curdir = s:NetrwGetCurdir(a:islocal)
11445 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11446 endif
11447" call Dret("s:NetrwBadd")
11448endfun
11449
11450" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011451" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11452fun! s:ComposePath(base,subdir)
11453" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11454
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011455 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011456" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011457 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011458 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011459 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011460 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011461 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011462 endif
11463
Bram Moolenaar85850f32019-07-19 22:05:51 +020011464 " COMBAK: test on windows with changing to root directory: :e C:/
11465 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011466" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011467 let ret= a:subdir
11468
Bram Moolenaar85850f32019-07-19 22:05:51 +020011469 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011471 if a:base =~ '[/\\]$'
11472 let ret= a:base.a:subdir
11473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011474 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011475 endif
11476
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011477 elseif a:base =~ '^\a\{3,}://'
11478" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011479 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11480 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11481 if a:subdir == '../'
11482 if curpath =~ '[^/]/[^/]\+/$'
11483 let curpath= substitute(curpath,'[^/]\+/$','','')
11484 else
11485 let curpath=""
11486 endif
11487 let ret= urlbase.curpath
11488 else
11489 let ret= urlbase.curpath.a:subdir
11490 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011491" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11492" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11493" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011494
11495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011496" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011497 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11498 if a:base =~ '^//'
11499 " keeping initial '//' for the benefit of network share listing support
11500 let ret= '/'.ret
11501 endif
11502 let ret= simplify(ret)
11503 endif
11504
11505" call Dret("s:ComposePath ".ret)
11506 return ret
11507endfun
11508
11509" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011510" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11511" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11512fun! s:DeleteBookmark(fname)
11513" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11514 call s:MergeBookmarks()
11515
11516 if exists("g:netrw_bookmarklist")
11517 let indx= index(g:netrw_bookmarklist,a:fname)
11518 if indx == -1
11519 let indx= 0
11520 while indx < len(g:netrw_bookmarklist)
11521 if g:netrw_bookmarklist[indx] =~ a:fname
11522 call remove(g:netrw_bookmarklist,indx)
11523 let indx= indx - 1
11524 endif
11525 let indx= indx + 1
11526 endwhile
11527 else
11528 " remove exact match
11529 call remove(g:netrw_bookmarklist,indx)
11530 endif
11531 endif
11532
11533" call Dret("s:DeleteBookmark")
11534endfun
11535
11536" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011537" s:FileReadable: o/s independent filereadable {{{2
11538fun! s:FileReadable(fname)
11539" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11540
11541 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011542 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011543 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011544 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011545 endif
11546
11547" call Dret("s:FileReadable ".ret)
11548 return ret
11549endfun
11550
11551" ---------------------------------------------------------------------
11552" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11553" Places correct suffix on end of temporary filename,
11554" using the suffix provided with fname
11555fun! s:GetTempfile(fname)
11556" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11557
11558 if !exists("b:netrw_tmpfile")
11559 " get a brand new temporary filename
11560 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011562
Bram Moolenaarc236c162008-07-13 17:41:49 +000011563 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011564" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011565
Bram Moolenaar9964e462007-05-05 17:54:07 +000011566 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011567 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11568" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011569 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011570" call Dret("s:GetTempfile getcwd<".getcwd().">")
11571 return ""
11572 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011573
Bram Moolenaar9964e462007-05-05 17:54:07 +000011574 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011575 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011576" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011577
Bram Moolenaar9964e462007-05-05 17:54:07 +000011578 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011579 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011580 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011581 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011582 if !exists("+shellslash") || !&ssl
11583 let tmpfile = substitute(tmpfile,'/','\','g')
11584 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011585 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011586 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011587 endif
11588 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011589" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011590 else
11591 " re-use temporary filename
11592 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011593" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011594 endif
11595
11596 " use fname's suffix for the temporary file
11597 if a:fname != ""
11598 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011599" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011600 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011601 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011602 elseif a:fname =~ '.txz$'
11603 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011604 else
11605 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011607" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011608 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011610 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011611" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011612 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11613 endif
11614 endif
11615
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011616" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011617" call Dret("s:GetTempfile <".tmpfile.">")
11618 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011619endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011620
11621" ---------------------------------------------------------------------
11622" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011623" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011624fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011625" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011626 if s:user == ""
11627 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11628 else
11629 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11630 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011631 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011632 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011633 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011634 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011635 else
11636 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11637 endif
11638" call Dret("s:MakeSshCmd <".sshcmd.">")
11639 return sshcmd
11640endfun
11641
11642" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011643" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11644fun! s:MakeBookmark(fname)
11645" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11646
11647 if !exists("g:netrw_bookmarklist")
11648 let g:netrw_bookmarklist= []
11649 endif
11650
11651 if index(g:netrw_bookmarklist,a:fname) == -1
11652 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011653 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011654 call add(g:netrw_bookmarklist,a:fname.'/')
11655 elseif a:fname !~ '/'
11656 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11657 else
11658 call add(g:netrw_bookmarklist,a:fname)
11659 endif
11660 call sort(g:netrw_bookmarklist)
11661 endif
11662
11663" call Dret("s:MakeBookmark")
11664endfun
11665
11666" ---------------------------------------------------------------------
11667" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11668fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011669" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011670 " get bookmarks from .netrwbook file
11671 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011672 if filereadable(s:NetrwFile(savefile))
11673" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011674 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011675" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011676 NetrwKeepj call delete(savefile)
11677 endif
11678" call Dret("s:MergeBookmarks")
11679endfun
11680
11681" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011682" s:NetrwBMShow: {{{2
11683fun! s:NetrwBMShow()
11684" call Dfunc("s:NetrwBMShow()")
11685 redir => bmshowraw
11686 menu
11687 redir END
11688 let bmshowlist = split(bmshowraw,'\n')
11689 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011690 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011691 if bmshowfuncs != []
11692 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011693 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011694 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011695 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011696 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011697 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011698" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11699endfun
11700
11701" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011702" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
11703fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011704 if !exists("w:netrw_liststyle")
11705 let w:netrw_liststyle= g:netrw_liststyle
11706 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011707" 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 +020011708
11709 if &ft != "netrw"
11710 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11711 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011712" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011713 let &l:cursorline = s:netrw_usercul
11714 let &l:cursorcolumn = s:netrw_usercuc
11715
11716 elseif g:netrw_cursor == 4
11717 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011719 setl cursorline
11720 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011721
11722 elseif g:netrw_cursor == 3
11723 " thin-long-tree: cursorline, user's cursorcolumn
11724 " wide : cursorline, cursorcolumn
11725 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011726" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011727 setl cursorline
11728 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011729 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011730" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011731 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011732 let &l:cursorcolumn = s:netrw_usercuc
11733 endif
11734
11735 elseif g:netrw_cursor == 2
11736 " thin-long-tree: cursorline, user's cursorcolumn
11737 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011738" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011739 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020011740 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011741
11742 elseif g:netrw_cursor == 1
11743 " thin-long-tree: user's cursorline, user's cursorcolumn
11744 " wide : cursorline, user's cursorcolumn
11745 let &l:cursorcolumn = s:netrw_usercuc
11746 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011747" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011748 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011749 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011751 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011752 endif
11753
11754 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011755 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011756" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011757 let &l:cursorline = s:netrw_usercul
11758 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011759 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011760
11761" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011762endfun
11763
11764" ---------------------------------------------------------------------
11765" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11766fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011767" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011768 if exists("s:netrw_usercul")
11769 let &l:cursorline = s:netrw_usercul
11770 endif
11771 if exists("s:netrw_usercuc")
11772 let &l:cursorcolumn = s:netrw_usercuc
11773 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011774" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11775endfun
11776
11777" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011778" s:NetrwDelete: Deletes a file. {{{2
11779" Uses Steve Hall's idea to insure that Windows paths stay
11780" acceptable. No effect on Unix paths.
11781" Examples of use: let result= s:NetrwDelete(path)
11782fun! s:NetrwDelete(path)
11783" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11784
Bram Moolenaar5c736222010-01-06 20:54:52 +010011785 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011786 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11787 if exists("+shellslash")
11788 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011789 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011790 let result = delete(path)
11791 let &shellslash = sskeep
11792 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011793" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011794 let result= delete(path)
11795 endif
11796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011798 let result= delete(path)
11799 endif
11800 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011801 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011802 endif
11803
11804" call Dret("s:NetrwDelete ".result)
11805 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011806endfun
11807
11808" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011809" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011810fun! s:NetrwEnew(...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011811" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813
Bram Moolenaar446cb832008-06-24 21:56:24 +000011814 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11817 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11818 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11819 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11820 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11821 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11822 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11823 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11824 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11825 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11826 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11827 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11828 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11829 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11830 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11831 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11832
Bram Moolenaar85850f32019-07-19 22:05:51 +020011833 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011835 " when tree listing uses file TreeListing... a new buffer is made.
11836 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011837 " COMBAK: this causes a problem, see P43
11838" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011839 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011840 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011841 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011842" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011843 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011844
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011846" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11848 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11849 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11850 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11851 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11852 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11853 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11854 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11855 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11856 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11857 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11858 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11859 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11860 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11861 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11862 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11863
Bram Moolenaar5c736222010-01-06 20:54:52 +010011864 if a:0 > 0
11865 let b:netrw_curdir= a:1
11866 if b:netrw_curdir =~ '/$'
11867 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011868 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011869 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011870 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011871 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11872 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011873 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011874 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011875 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011876 endif
11877 endif
11878
Bram Moolenaar8d043172014-01-23 14:24:41 +010011879" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011880endfun
11881
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011882" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011883" s:NetrwExe: executes a string using "!" {{{2
11884fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011885" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011886 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020011887" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011888 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11889 set shell& shellcmdflag& shellxquote& shellxescape&
11890 set shellquote& shellpipe& shellredir& shellslash&
11891 exe a:cmd
11892 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11893 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011894" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011895 exe a:cmd
11896 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011897 if v:shell_error
11898 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11899 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011900" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011901endfun
11902
11903" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011904" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11905fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011906 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011907" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011908 let curbuf = bufnr("%")
11909 let curwin = winnr()
11910 let iwin = 1
11911 while iwin <= winnr("$")
11912 exe iwin."wincmd w"
11913 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11914 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11915 let winvars= w:
11916 break
11917 endif
11918 let iwin= iwin + 1
11919 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011920 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011921 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011922" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011923 for k in keys(winvars)
11924 let w:{k}= winvars[k]
11925 endfor
11926 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011927" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011928 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011929endfun
11930
Bram Moolenaara6878372014-03-22 21:02:50 +010011931" ---------------------------------------------------------------------
11932" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011933" Returns: 0=success
11934" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011935fun! s:NetrwLcd(newdir)
11936" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
11937
Bram Moolenaar85850f32019-07-19 22:05:51 +020011938 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011939 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011940 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011941 catch /^Vim\%((\a\+)\)\=:E344/
11942 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11943 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011944 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011945 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11946 " forward slashes by earlier code; so check for both.
11947 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
11948 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11949 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011950 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011951 endif
11952 endif
11953 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011954 let err472= 1
11955 endtry
11956
11957 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011958 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11959 if exists("w:netrw_prvdir")
11960 let a:newdir= w:netrw_prvdir
11961 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011962 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011964 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011966 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011967 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011968" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11969 return -1
11970 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011971
Bram Moolenaar85850f32019-07-19 22:05:51 +020011972" call Dret("s:NetrwLcd 0")
11973 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011974endfun
11975
Bram Moolenaar9964e462007-05-05 17:54:07 +000011976" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011977" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11978" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11979fun! s:NetrwSaveWordPosn()
11980" call Dfunc("NetrwSaveWordPosn()")
11981 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11982" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11983endfun
11984
11985" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011986" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11987" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11988fun! s:NetrwHumanReadable(sz)
11989" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11990
11991 if g:netrw_sizestyle == 'h'
11992 if a:sz >= 1000000000
11993 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11994 elseif a:sz >= 10000000
11995 let sz = printf("%d",a:sz/1000000)."m"
11996 elseif a:sz >= 1000000
11997 let sz = printf("%.1f",a:sz/1000000.0)."m"
11998 elseif a:sz >= 10000
11999 let sz = printf("%d",a:sz/1000)."k"
12000 elseif a:sz >= 1000
12001 let sz = printf("%.1f",a:sz/1000.0)."k"
12002 else
12003 let sz= a:sz
12004 endif
12005
12006 elseif g:netrw_sizestyle == 'H'
12007 if a:sz >= 1073741824
12008 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12009 elseif a:sz >= 10485760
12010 let sz = printf("%d",a:sz/1048576)."M"
12011 elseif a:sz >= 1048576
12012 let sz = printf("%.1f",a:sz/1048576.0)."M"
12013 elseif a:sz >= 10240
12014 let sz = printf("%d",a:sz/1024)."K"
12015 elseif a:sz >= 1024
12016 let sz = printf("%.1f",a:sz/1024.0)."K"
12017 else
12018 let sz= a:sz
12019 endif
12020
12021 else
12022 let sz= a:sz
12023 endif
12024
12025" call Dret("s:NetrwHumanReadable ".sz)
12026 return sz
12027endfun
12028
12029" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012030" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12031" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12032fun! s:NetrwRestoreWordPosn()
12033" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012034 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012035" call Dret("NetrwRestoreWordPosn")
12036endfun
12037
12038" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039" s:RestoreBufVars: {{{2
12040fun! s:RestoreBufVars()
12041" call Dfunc("s:RestoreBufVars()")
12042
12043 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12044 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12045 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12046 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12047 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12048 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12049
12050" call Dret("s:RestoreBufVars")
12051endfun
12052
12053" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012054" s:RemotePathAnalysis: {{{2
12055fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012056" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012057
Bram Moolenaara6878372014-03-22 21:02:50 +010012058 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012059 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012060 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012061 let s:user = substitute(a:dirname,dirpat,'\3','')
12062 let s:machine = substitute(a:dirname,dirpat,'\4','')
12063 let s:port = substitute(a:dirname,dirpat,'\5','')
12064 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012065 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012066 if s:machine =~ '@'
12067 let dirpat = '^\(.*\)@\(.\{-}\)$'
12068 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12069 let s:machine = substitute(s:machine,dirpat,'\2','')
12070 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012072" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12073" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12074" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12075" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12076" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12077" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012078
12079" call Dret("s:RemotePathAnalysis")
12080endfun
12081
12082" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012083" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12084" Returns status
12085" Runs system() on
12086" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012087" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012088fun! s:RemoteSystem(cmd)
12089" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12090 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012091 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 +000012092 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012093 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012094 else
12095 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12096 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12097 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012098 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012099 else
12100 let cmd= cmd.' '
12101 endif
12102 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012103" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012104 let ret= system(cmd)
12105 endif
12106" call Dret("s:RemoteSystem ".ret)
12107 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012108endfun
12109
12110" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012111" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012112fun! s:RestoreWinVars()
12113" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012114 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012115 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12116 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12117 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12118 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12119 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12120 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12121 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12122 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12123 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12124 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12125 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12126 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012127 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12128 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012129 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12130 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12131 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12132" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012133endfun
12134
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012135" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012136" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12137"
12138" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12139" is true) and a command, :Rexplore, which call this function.
12140"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012141" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012142"
12143" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012144fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012145 if exists("s:netrwdrag")
12146 return
12147 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012148" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir."> win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012149" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12150" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012151
12152 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012153 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012154" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012155 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012156 unlet w:netrw_rexfile
12157" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012158 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012159" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012160" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12161" call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020012162 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012163
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012164 " ---------------------------
12165 " :Rex issued while in a file
12166 " ---------------------------
12167
Bram Moolenaara6878372014-03-22 21:02:50 +010012168 " record current file so :Rex can return to it from netrw
12169 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012170" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012171
12172 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012173" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012174 return
12175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012176" 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,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012177 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012178 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012179 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012180 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012181 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012182 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012183 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012184 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012185 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012186" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12187 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012188" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12189 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012190 if exists("s:rexposn_".bufnr('%'))
12191 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012192 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012194" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012195 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012196
Bram Moolenaar85850f32019-07-19 22:05:51 +020012197 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12198 if exists("s:explore_match")
12199 exe "2match netrwMarkFile /".s:explore_match."/"
12200 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012201 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012202
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012203" 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,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012204" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012205endfun
12206
12207" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012208" s:SaveBufVars: save selected b: variables to s: variables {{{2
12209" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012210fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012211" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012212
12213 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12214 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12215 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12216 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12217 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12218 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12219
12220" call Dret("s:SaveBufVars")
12221endfun
12222
12223" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012224" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12225fun! s:SavePosn(posndict)
12226" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12227
Bram Moolenaar85850f32019-07-19 22:05:51 +020012228 if !exists("a:posndict[bufnr('%')]")
12229 let a:posndict[bufnr("%")]= []
12230 endif
12231" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12232 call add(a:posndict[bufnr("%")],winsaveview())
12233" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012234
12235" call Dret("s:SavePosn posndict")
12236 return a:posndict
12237endfun
12238
12239" ---------------------------------------------------------------------
12240" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12241fun! s:RestorePosn(posndict)
12242" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012243 if exists("a:posndict")
12244 if has_key(a:posndict,bufnr("%"))
12245" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12246 let posnlen= len(a:posndict[bufnr("%")])
12247 if posnlen > 0
12248 let posnlen= posnlen - 1
12249" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12250 call winrestview(a:posndict[bufnr("%")][posnlen])
12251 call remove(a:posndict[bufnr("%")],posnlen)
12252" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12253 endif
12254 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012255 endif
12256" call Dret("s:RestorePosn")
12257endfun
12258
12259" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012260" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012261fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012262" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012263 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12264 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12265 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12266 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12267 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12268 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12269 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12270 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12271 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12272 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12273 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12274 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12275 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12276 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12277 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12278 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12279 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12280 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12281" call Dret("s:SaveWinVars")
12282endfun
12283
12284" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012285" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012286" To allow separate windows to have their own activities, such as
12287" Explore **/pattern, several variables have been made window-oriented.
12288" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012289" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012290" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012291fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012292" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012293 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12294 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12295 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12296 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12297 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12298 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12299 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12300 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12301 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12302 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12303" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012304endfun
12305
12306" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012307" s:SetRexDir: set directory for :Rexplore {{{2
12308fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012309" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012310 let w:netrw_rexdir = a:dirname
12311 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012312 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012313" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12314" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012315" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012316" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012317" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012318endfun
12319
12320" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012321" s:ShowLink: used to modify thin and tree listings to show links {{{2
12322fun! s:ShowLink()
12323" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012324" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12325" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012326 if exists("b:netrw_curdir")
12327 norm! $?\a
12328 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12329 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012330" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12331" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12332" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12333 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012334 let dirlen = strlen(b:netrw_curdir)
12335 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012336" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012337 endif
12338 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012339" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12340" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012341 setl noro ma
12342 call setline(".",modline)
12343 setl ro noma nomod
12344 endif
12345" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12346endfun
12347
12348" ---------------------------------------------------------------------
12349" s:ShowStyle: {{{2
12350fun! s:ShowStyle()
12351 if !exists("w:netrw_liststyle")
12352 let liststyle= g:netrw_liststyle
12353 else
12354 let liststyle= w:netrw_liststyle
12355 endif
12356 if liststyle == s:THINLIST
12357 return s:THINLIST.":thin"
12358 elseif liststyle == s:LONGLIST
12359 return s:LONGLIST.":long"
12360 elseif liststyle == s:WIDELIST
12361 return s:WIDELIST.":wide"
12362 elseif liststyle == s:TREELIST
12363 return s:TREELIST.":tree"
12364 else
12365 return 'n/a'
12366 endif
12367endfun
12368
12369" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012370" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12371" Solution from Nicolai Weibull, vim docs (:help strlen()),
12372" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012373fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012374" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12375
12376 if v:version >= 703 && exists("*strdisplaywidth")
12377 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012378
Bram Moolenaar8d043172014-01-23 14:24:41 +010012379 elseif type(g:Align_xstrlen) == 1
12380 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12381 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012382
Bram Moolenaar8d043172014-01-23 14:24:41 +010012383 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012384 " number of codepoints (Latin a + combining circumflex is two codepoints)
12385 " (comment from TM, solution from NW)
12386 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012387
Bram Moolenaar8d043172014-01-23 14:24:41 +010012388 elseif g:Align_xstrlen == 2
12389 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012390 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12391 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012392 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012393
Bram Moolenaar8d043172014-01-23 14:24:41 +010012394 elseif g:Align_xstrlen == 3
12395 " virtual length (counting, for instance, tabs as anything between 1 and
12396 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012397 " preceded by lam, one otherwise, etc.)
12398 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012399 let modkeep= &l:mod
12400 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012401 call setline(line("."),a:x)
12402 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012403 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012404 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012405 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012406
Bram Moolenaar446cb832008-06-24 21:56:24 +000012407 else
12408 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012409 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012410 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012411" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012412 return ret
12413endfun
12414
12415" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012416" s:ShellEscape: shellescape(), or special windows handling {{{2
12417fun! s:ShellEscape(s, ...)
12418 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12419 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12420 endif
12421 let f = a:0 > 0 ? a:1 : 0
12422 return shellescape(a:s, f)
12423endfun
12424
12425" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012426" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012427fun! s:TreeListMove(dir)
12428" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012429 let curline = getline('.')
12430 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12431 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12432 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12433 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12434 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12435 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12436" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12437" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12438" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12439" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12440" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12441 " COMBAK : need to handle when on a directory
12442 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012443 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012444 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012445 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012446 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012447" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012448 elseif a:dir == '[]' && nxtline != ''
12449 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012450" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012451 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12452 if nl != 0
12453 NetrwKeepj norm! k
12454 else
12455 NetrwKeepj norm! G
12456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012457" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012458 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012459 endif
12460
12461" call Dret("s:TreeListMove")
12462endfun
12463
12464" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012465" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12466" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12467" can't be called except via emenu. But due to locale, that menu line may not be called
12468" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12469fun! s:UpdateBuffersMenu()
12470" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012471 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012472 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012473 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012474 catch /^Vim\%((\a\+)\)\=:E/
12475 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012476 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012477 endtry
12478 endif
12479" call Dret("s:UpdateBuffersMenu")
12480endfun
12481
12482" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012483" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012484" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012485fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012486" call Dfunc("s:UseBufWinVars()")
12487 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012488 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12489 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12490 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12491 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12492 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12493 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12494 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12495 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12496 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 +000012497" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012498endfun
12499
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012500" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012501" s:UserMaps: supports user-defined UserMaps {{{2
12502" * calls a user-supplied funcref(islocal,curdir)
12503" * interprets result
12504" See netrw#UserMaps()
12505fun! s:UserMaps(islocal,funcname)
12506" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12507
12508 if !exists("b:netrw_curdir")
12509 let b:netrw_curdir= getcwd()
12510 endif
12511 let Funcref = function(a:funcname)
12512 let result = Funcref(a:islocal)
12513
12514 if type(result) == 1
12515 " if result from user's funcref is a string...
12516" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12517 if result == "refresh"
12518" call Decho("refreshing display",'~'.expand("<slnum>"))
12519 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12520 elseif result != ""
12521" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12522 exe result
12523 endif
12524
12525 elseif type(result) == 3
12526 " if result from user's funcref is a List...
12527" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12528 for action in result
12529 if action == "refresh"
12530" call Decho("refreshing display",'~'.expand("<slnum>"))
12531 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12532 elseif action != ""
12533" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12534 exe action
12535 endif
12536 endfor
12537 endif
12538
12539" call Dret("s:UserMaps")
12540endfun
12541
Bram Moolenaar85850f32019-07-19 22:05:51 +020012542" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012543" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012544" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012545let &cpo= s:keepcpo
12546unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012547
Bram Moolenaar85850f32019-07-19 22:05:51 +020012548" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012549" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012550" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551" vim:ts=8 fdm=marker