blob: 26c4c92d06303b8e06f4e139216f385979f195ed [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 Moolenaar91359012019-11-30 17:57:03 +01003" Date: Nov 29, 2019
4" Version: 167
Bram Moolenaarff034192013-04-24 18:51:19 +02005" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram 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 Moolenaar91359012019-11-30 17:57:03 +010046let g:loaded_netrw = "v167"
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 Moolenaar85850f32019-07-19 22:05:51 +020071" Mar 21, 2017 : max errnum currently is 105
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 Moolenaar85850f32019-07-19 22:05:51 +0200450if v:version < 704 || (v:version == 704 && !has("patch1107"))
451 " 1109 provides for delete(tmpdir,"d") which is what will be used
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100452 if exists("g:netrw_local_rmdir")
453 let g:netrw_localrmdir= g:netrw_local_rmdir
454 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
455 endif
456 if has("win32") || has("win95") || has("win64") || has("win16")
457 if g:netrw_cygwin
458 call s:NetrwInit("g:netrw_localrmdir","rmdir")
459 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200460 let g:netrw_localrmdir = expand("$COMSPEC")
461 let g:netrw_localrmdiropt= " /c rmdir"
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100462 endif
463 else
464 call s:NetrwInit("g:netrw_localrmdir","rmdir")
465 endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200466endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100467call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
468" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000469if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000471endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000473 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
474endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000475" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
477call s:NetrwInit("g:netrw_maxfilenamelen", 32)
478call s:NetrwInit("g:netrw_menu" , 1)
479call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200480call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_retmap" , 0)
482if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
483 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
484elseif has("win32") || has("win95") || has("win64") || has("win16")
485 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
486else
487 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000488endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489call s:NetrwInit("g:netrw_preview" , 0)
490call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100491call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_sshport" , "-p")
493call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
494call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
495call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100496call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
497" Default values - q-s ---------- {{{3
498call s:NetrwInit("g:netrw_quickhelp",0)
499let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100500 \ "(create new) %:file d:directory",
501 \ "(windows split&open) o:horz v:vert p:preview",
502 \ "i:style qf:file info O:obtain r:reverse",
503 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
504 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
505 \ "(history) qb:list u:go up U:go down",
506 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
508call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100509if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
510 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
511else
512 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
513endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
515call s:NetrwInit("g:netrw_sort_options" , "")
516call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000517if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200519 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520 else
521 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524call s:NetrwInit("g:netrw_special_syntax" , 0)
525call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200526call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100527call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100528call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000529" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200531if !exists("g:netrw_xstrlen")
532 if exists("g:Align_xstrlen")
533 let g:netrw_xstrlen= g:Align_xstrlen
534 elseif exists("g:drawit_xstrlen")
535 let g:netrw_xstrlen= g:drawit_xstrlen
536 elseif &enc == "latin1" || !has("multi_byte")
537 let g:netrw_xstrlen= 0
538 else
539 let g:netrw_xstrlen= 1
540 endif
541endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200544call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100545call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200546if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000547" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000548" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200550if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200551 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552else
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200555call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
557call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100558if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100559 let s:treedepthstring= "│ "
560else
561 let s:treedepthstring= "| "
562endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200563call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000564
565" BufEnter event ignored by decho when following variable is true
566" Has a side effect that doau BufReadPost doesn't work, so
567" files read by network transfer aren't appropriately highlighted.
568"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569
Bram Moolenaaradc21822011-04-01 18:03:16 +0200570" ======================
571" Netrw Initialization: {{{1
572" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200573if 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 +0100574" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100575 let &l:bexpr = "netrw#BalloonHelp()"
576 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100577 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
578 au VimEnter * let s:initbeval= &beval
579"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100580" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
581" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
582" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
583" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
584" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
585" 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 +0200586endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200587au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200588
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200589if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100590 com! -nargs=* NetrwKeepj keepj <args>
591else
592 let g:netrw_keepj= ""
593 com! -nargs=* NetrwKeepj <args>
594endif
595
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000596" ==============================
597" Netrw Utility Functions: {{{1
598" ==============================
599
Bram Moolenaaradc21822011-04-01 18:03:16 +0200600" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100601" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100602if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100603" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100604 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100605 if &ft != "netrw"
606 return ""
607 endif
608 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
609 let mesg= ""
610 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
611 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
612 elseif getline(v:beval_lnum) =~ '^"\s*/'
613 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
614 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100615 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100616 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
617 let mesg = "S: edit sorting sequence"
618 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
619 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
620 elseif v:beval_text == "Quick" || v:beval_text == "Help"
621 let mesg = "Help: press <F1>"
622 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
623 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
624 else
625 let mesg= ""
626 endif
627 return mesg
628 endfun
629"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100630" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
631" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
632" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
633" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
634" 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 +0200635endif
636
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200638" netrw#Explore: launch the local browser in the directory of the current file {{{2
639" indx: == -1: Nexplore
640" == -2: Pexplore
641" == +: this is overloaded:
642" * If Nexplore/Pexplore is in use, then this refers to the
643" indx'th item in the w:netrw_explore_list[] of items which
644" matched the */pattern **/pattern *//pattern **//pattern
645" * If Hexplore or Vexplore, then this will override
646" g:netrw_winsize to specify the qty of rows or columns the
647" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100648" 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 +0200649" dosplit==1: the window will be split before running the local browser
650" style == 0: Explore style == 1: Explore!
651" == 2: Hexplore style == 3: Hexplore!
652" == 4: Vexplore style == 5: Vexplore!
653" == 6: Texplore
654fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100655" 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 +0100656" 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 +0200657 if !exists("b:netrw_curdir")
658 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100659" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200660 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100661
662 " record current file for Rexplore's benefit
663 if &ft != "netrw"
664 let w:netrw_rexfile= expand("%:p")
665 endif
666
667 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200668 let curdir = simplify(b:netrw_curdir)
669 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200670 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
671 let curdir= substitute(curdir,'\','/','g')
672 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100673" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100674
675 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
676 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
677 " try Explore again.
678 if a:0 > 0
679" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100680 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
681 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
682 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
683 \ '~'.expand("<slnum>"))
684 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
685" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100686 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
687" call Dret("netrw#Explore : returning from retry")
688 return
689" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100690" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100691 endif
692 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200693
694 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100695 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100696" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100697 sil! let keepregstar = @*
698 sil! let keepregplus = @+
699 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200700 sil! let keepregslash= @/
701
Bram Moolenaar8d043172014-01-23 14:24:41 +0100702 " if dosplit
703 " -or- file has been modified AND file not hidden when abandoned
704 " -or- Texplore used
705 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100706" 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 +0200707 call s:SaveWinVars()
708 let winsz= g:netrw_winsize
709 if a:indx > 0
710 let winsz= a:indx
711 endif
712
713 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100714" call Decho("style=0: Explore or Sexplore",'~'.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 "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100718" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200719
720 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200723 if winsz == 0|let winsz= ""|endif
724 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100725" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200726
727 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200730 if winsz == 0|let winsz= ""|endif
731 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733
734 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
738 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
741 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
745 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
752 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 6 " Texplore
756 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 call s:RestoreBufVars()
761 endif
762 call s:RestoreWinVars()
763" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" 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 +0200765 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100766 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200767
768 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100773" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
777 if dirname !~ '/$'
778 let dirname= dirname."/"
779 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200785 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= a:1
792 endif
793 else
794 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 call s:NetrwClearExplore()
797" call Dret("netrw#Explore : cleared list")
798 return
799 endif
800
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 if dirname =~ '\.\./\=$'
803 let dirname= simplify(fnamemodify(dirname,':p:h'))
804 elseif dirname =~ '\.\.' || dirname == '.'
805 let dirname= simplify(fnamemodify(dirname,':p'))
806 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808
809 if dirname =~ '^\*//'
810 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100811" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
813 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
816
817 elseif dirname =~ '^\*\*//'
818 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 let pattern= substitute(dirname,'^\*\*//','','')
821 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 elseif dirname =~ '/\*\*/'
825 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
828 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
829 let b:netrw_curdir = prefixdir
830 else
831 let b:netrw_curdir= getcwd().'/'.prefixdir
832 endif
833 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
834 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
836" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837
838 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200839 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842
843 elseif dirname=~ '^\*\*/'
844 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
845 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200847
848 else
849 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851 endif
852
853 if starpat == 0 && a:indx >= 0
854 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100855" 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 +0200856 if dirname == ""
857 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200860 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200861 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200862 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200863 if dirname == ""
864 let dirname= getcwd()
865 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100866 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100867 " depending on whether backslashes have been converted to forward slashes by earlier code).
868 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200869 let dirname= b:netrw_curdir."/".dirname
870 endif
871 elseif dirname !~ '^/'
872 let dirname= b:netrw_curdir."/".dirname
873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100874" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100876" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
877" 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 +0200878 endif
879 if exists("w:netrw_bannercnt")
880 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
881 " If one wants to return the same place in the netrw window, use :Rex instead.
882 exe w:netrw_bannercnt
883 endif
884
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200886 " ---------------------------------------------------------------------
887 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
888" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100889" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200890" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100891" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200892" endif
893 " ---------------------------------------------------------------------
894
895 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
896 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
897 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
898 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
899 elseif a:indx <= 0
900 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100901" 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 +0200902 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100903" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200904 let s:didstarstar= 1
905 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
906 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
907 endif
908
909 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100910" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 if !exists("w:netrw_explore_indx")
912 let w:netrw_explore_indx= 0
913 endif
914
915 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917
918 if indx == -1
919 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100922 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 +0100923 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100924" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100925 if @* != keepregstar | sil! let @* = keepregstar | endif
926 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100927 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 sil! let @/ = keepregslash
929" call Dret("netrw#Explore")
930 return
931 endif
932 let indx= w:netrw_explore_indx
933 if indx < 0 | let indx= 0 | endif
934 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
935 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100936" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
938 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100939" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 endwhile
941 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100942" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200943
944 elseif indx == -2
945 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100948 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 +0100949 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100950" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100951 if @* != keepregstar | sil! let @* = keepregstar | endif
952 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100953 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 sil! let @/ = keepregslash
955" call Dret("netrw#Explore")
956 return
957 endif
958 let indx= w:netrw_explore_indx
959 if indx < 0 | let indx= 0 | endif
960 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
961 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100962" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 while indx >= 0 && curfile == w:netrw_explore_list[indx]
964 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100965" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 endwhile
967 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100968" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200969
970 else
971 " Explore -- initialize
972 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100974 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 let w:netrw_explore_indx= 0
976 if !exists("b:netrw_curdir")
977 let b:netrw_curdir= getcwd()
978 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200980
981 " switch on starpat to build the w:netrw_explore_list of files
982 if starpat == 1
983 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.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 "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 catch /^Vim\%((\a\+)\)\=:E480/
989 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
990" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
991 return
992 endtry
993 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
994 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
995
996 elseif starpat == 2
997 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100998" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
999" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001001 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 catch /^Vim\%((\a\+)\)\=:E480/
1003 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1004 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001005 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001006" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001007 if @* != keepregstar | sil! let @* = keepregstar | endif
1008 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001009 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 sil! let @/ = keepregslash
1011" call Dret("netrw#Explore : no files matched pattern")
1012 return
1013 endtry
1014 let s:netrw_curdir = b:netrw_curdir
1015 let w:netrw_explore_list = getqflist()
1016 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1017 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1018
1019 elseif starpat == 3
1020 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001021" 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 +02001022 let filepat= substitute(dirname,'^\*/','','')
1023 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001024" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1025" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001026 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1027 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1028
1029 elseif starpat == 4
1030 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001031" 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 +02001032 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1033 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1034 endif " switch on starpat to build w:netrw_explore_list
1035
1036 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1038" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001039
1040 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001041 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +01001042 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001043" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001044 if @* != keepregstar | sil! let @* = keepregstar | endif
1045 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001047 sil! let @/ = keepregslash
1048" call Dret("netrw#Explore : no files matched")
1049 return
1050 endif
1051 endif " if indx ... endif
1052
1053 " NetrwStatusLine support - for exploring support
1054 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001055" 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 +02001056
1057 " wrap the indx around, but issue a note
1058 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001059" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1061 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001062 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 endif
1064
1065 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001067 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001069
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 call netrw#LocalBrowseCheck(newdir)
1072 if !exists("w:netrw_liststyle")
1073 let w:netrw_liststyle= g:netrw_liststyle
1074 endif
1075 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001076 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001078 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 endif
1080 let w:netrw_explore_mtchcnt = indx + 1
1081 let w:netrw_explore_bufnr = bufnr("%")
1082 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001083 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001084" 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 +02001085
1086 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001087" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 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 +02001090 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001091 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001092" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001093 if @* != keepregstar | sil! let @* = keepregstar | endif
1094 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001095 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 sil! let @/ = keepregslash
1097" call Dret("netrw#Explore : missing +path_extra")
1098 return
1099 endif
1100
1101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1104 sil! unlet w:netrw_treedict
1105 sil! unlet w:netrw_treetop
1106 endif
1107 let newdir= dirname
1108 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001109 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001111 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001112 endif
1113 endif
1114
1115 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001116" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1117" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001119" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001121 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001122" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 let s:explore_prvdir = b:netrw_curdir
1124 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001125 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 if b:netrw_curdir !~ '/$'
1127 let dirlen= dirlen + 1
1128 endif
1129 let prvfname= ""
1130 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if fname =~ '^'.b:netrw_curdir
1133 if s:explore_match == ""
1134 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1135 else
1136 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1137 endif
1138 elseif fname !~ '^/' && fname != prvfname
1139 if s:explore_match == ""
1140 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1141 else
1142 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1143 endif
1144 endif
1145 let prvfname= fname
1146 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001147" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001148 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1149 exe "2match netrwMarkFile /".s:explore_match."/"
1150 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001151 endif
1152 echo "<s-up>==Pexplore <s-down>==Nexplore"
1153 else
1154 2match none
1155 if exists("s:explore_match") | unlet s:explore_match | endif
1156 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1157 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001158" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001159 endif
1160
Bram Moolenaara6878372014-03-22 21:02:50 +01001161 " since Explore may be used to initialize netrw's browser,
1162 " there's no danger of a late FocusGained event on initialization.
1163 " Consequently, set s:netrw_events to 2.
1164 let s:netrw_events= 2
1165 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001166" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001167 if @* != keepregstar | sil! let @* = keepregstar | endif
1168 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001169 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 sil! let @/ = keepregslash
1171" call Dret("netrw#Explore : @/<".@/.">")
1172endfun
1173
1174" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001175" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001176fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001177" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001178 let curwin= winnr()
1179
Bram Moolenaara6878372014-03-22 21:02:50 +01001180 if a:0 > 0 && a:1 != ""
1181 " if a netrw window is already on the left-side of the tab
1182 " and a directory has been specified, explore with that
1183 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001184" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001186" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001187 exe "1wincmd w"
1188 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001189" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 exe "Explore ".fnameescape(a1)
1191 exe curwin."wincmd w"
1192 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001193" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 unlet t:netrw_lexposn
1195 endif
1196" call Dret("netrw#Lexplore")
1197 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001198 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 exe curwin."wincmd w"
1200 else
1201 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001202" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 endif
1204
Bram Moolenaar8d043172014-01-23 14:24:41 +01001205 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001207 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001208" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 else
1210 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001211" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001213" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214
1215 if lexwinnr > 0
1216 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001217" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 exe lexwinnr."wincmd w"
1219 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001220 let t:netrw_lexposn = winsaveview()
1221" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001222" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 close
1224 if lexwinnr < curwin
1225 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227 if lexwinnr != curwin
1228 exe curwin."wincmd w"
1229 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001230 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001232
1233 else
1234 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001235" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001236 exe "1wincmd w"
1237 let keep_altv = g:netrw_altv
1238 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 if a:count != 0
1240 let netrw_winsize = g:netrw_winsize
1241 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001244" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001245 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 +02001246" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001247 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001248" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001250 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001251 elseif curfile =~ '^\a\{3,}://'
1252" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001253 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001255" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001256 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 endif
1258 if a:count != 0
1259 let g:netrw_winsize = netrw_winsize
1260 endif
1261 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001262 let g:netrw_altv = keep_altv
1263 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1265" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001268" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1269 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 unlet t:netrw_lexposn
1271 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273
1274 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001275 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001276 if a:rightside
1277 let g:netrw_chgwin= 1
1278 else
1279 let g:netrw_chgwin= 2
1280 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001281" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001282 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001283
Bram Moolenaar8d043172014-01-23 14:24:41 +01001284" call Dret("netrw#Lexplore")
1285endfun
1286
1287" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001288" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001289" supports :NetrwClean -- remove netrw from first directory on runtimepath
1290" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001291fun! netrw#Clean(sys)
1292" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001293
1294 if a:sys
1295 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1296 else
1297 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1298 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001299" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001300 let diddel= 0
1301 let diddir= ""
1302
1303 if choice == 1
1304 for dir in split(&rtp,',')
1305 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001306" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001307 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1308 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1309 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1310 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1311 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1312 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 +00001313 let diddir= dir
1314 let diddel= diddel + 1
1315 if !a:sys|break|endif
1316 endif
1317 endfor
1318 endif
1319
1320 echohl WarningMsg
1321 if diddel == 0
1322 echomsg "netrw is either not installed or not removable"
1323 elseif diddel == 1
1324 echomsg "removed one copy of netrw from <".diddir.">"
1325 else
1326 echomsg "removed ".diddel." copies of netrw"
1327 endif
1328 echohl None
1329
Bram Moolenaara6878372014-03-22 21:02:50 +01001330" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001331endfun
1332
Bram Moolenaar5c736222010-01-06 20:54:52 +01001333" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001334" netrw#MakeTgt: make a target out of the directory name provided {{{2
1335fun! netrw#MakeTgt(dname)
1336" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1337 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001338 let svpos = winsaveview()
1339" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001340 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1341" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001342 if s:netrwmftgt_islocal
1343 let netrwmftgt= simplify(a:dname)
1344 else
1345 let netrwmftgt= a:dname
1346 endif
1347 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1348 " re-selected target, so just clear it
1349 unlet s:netrwmftgt s:netrwmftgt_islocal
1350 else
1351 let s:netrwmftgt= netrwmftgt
1352 endif
1353 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001354 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001355 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001356" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1357 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001358" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001359endfun
1360
Bram Moolenaara6878372014-03-22 21:02:50 +01001361" ---------------------------------------------------------------------
1362" netrw#Obtain: {{{2
1363" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001364" islocal=0 obtain from remote source
1365" =1 obtain from local source
1366" fname : a filename or a list of filenames
1367" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001368fun! netrw#Obtain(islocal,fname,...)
1369" 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 +02001370 " NetrwStatusLine support - for obtaining support
1371
1372 if type(a:fname) == 1
1373 let fnamelist= [ a:fname ]
1374 elseif type(a:fname) == 3
1375 let fnamelist= a:fname
1376 else
1377 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 +01001378" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001379 return
1380 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001381" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001382 if a:0 > 0
1383 let tgtdir= a:1
1384 else
1385 let tgtdir= getcwd()
1386 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001388
1389 if exists("b:netrw_islocal") && b:netrw_islocal
1390 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001391" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1393 let topath= s:ComposePath(tgtdir,"")
1394 if (has("win32") || has("win95") || has("win64") || has("win16"))
1395 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001399 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 if v:shell_error != 0
1401 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 +01001402" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001403 return
1404 endif
1405 endfor
1406 else
1407 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1409 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1410" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001411 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 if v:shell_error != 0
1413 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 +01001414" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 return
1416 endif
1417 endif
1418 elseif !exists("b:netrw_curdir")
1419 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1420 else
1421 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1422 endif
1423
1424 else
1425 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 if type(a:fname) == 1
1428 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1429 endif
1430 call s:NetrwMethod(b:netrw_curdir)
1431
1432 if b:netrw_method == 4
1433 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001434" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 if exists("g:netrw_port") && g:netrw_port != ""
1436 let useport= " ".g:netrw_scpport." ".g:netrw_port
1437 else
1438 let useport= ""
1439 endif
1440 if b:netrw_fname =~ '/'
1441 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1442 else
1443 let path= ""
1444 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001445 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446 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 +02001447
1448 elseif b:netrw_method == 2
1449 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001450" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 let tmpbufnr= bufnr("%")
1453 setl ff=unix
1454 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001455 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 endif
1458
1459 if exists("b:netrw_fname") && b:netrw_fname != ""
1460 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001462 endif
1463
1464 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001465 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001467 endif
1468 for fname in fnamelist
1469 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 endfor
1472 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473 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 +02001474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 endif
1477 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1478 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1479 let debugkeep= &debug
1480 setl debug=msg
1481 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1482 let &debug= debugkeep
1483 endif
1484
1485 elseif b:netrw_method == 3
1486 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001488 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 let tmpbufnr= bufnr("%")
1490 setl ff=unix
1491
1492 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001493 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001496 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 endif
1499
1500 if exists("g:netrw_uid") && g:netrw_uid != ""
1501 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001502 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001508 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 endif
1512 endif
1513
1514 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 endif
1518
1519 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 endif
1523
1524 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 endif
1528
1529 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001531" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 endif
1533 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001537
1538 " perform ftp:
1539 " -i : turns off interactive prompting from ftp
1540 " -n unix : DON'T use <.netrc>, even though it exists
1541 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001542 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1543 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1546 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001547" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001552
1553 elseif b:netrw_method == 9
1554 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001555" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001556 if a:fname =~ '/'
1557 let localfile= substitute(a:fname,'^.*/','','')
1558 else
1559 let localfile= a:fname
1560 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001561 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 +02001562
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001564 " probably a badly formed url; protocol not recognized
1565" call Dret("netrw#Obtain : unsupported method")
1566 return
1567
1568 else
1569 " protocol recognized but not supported for Obtain (yet?)
1570 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001572 endif
1573" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001574 return
1575 endif
1576
1577 " restore status line
1578 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001579 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001580 endif
1581
1582 endif
1583
1584 " cleanup
1585 if exists("tmpbufnr")
1586 if bufnr("%") != tmpbufnr
1587 exe tmpbufnr."bw!"
1588 else
1589 q!
1590 endif
1591 endif
1592
Bram Moolenaara6878372014-03-22 21:02:50 +01001593" call Dret("netrw#Obtain")
1594endfun
1595
1596" ---------------------------------------------------------------------
1597" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1598fun! netrw#Nread(mode,fname)
1599" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001600 let svpos= winsaveview()
1601" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001602 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1604 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001605
1606 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1607 if exists("w:netrw_bannercnt")
1608 " start with cursor just after the banner
1609 exe w:netrw_bannercnt
1610 endif
1611 endif
1612" call Dret("netrw#Nread")
1613endfun
1614
1615" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001616" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1617" Options get restored by s:NetrwOptionsRestore()
1618"
1619" Option handling:
1620" * save user's options (s:NetrwOptionsSave)
1621" * set netrw-safe options (s:NetrwOptionsSafe)
1622" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1623" * restore user's options (s:netrwOPtionsRestore)
1624" - restore a user option when != safe option (s:NetrwRestoreSetting)
1625" vt: (variable type) normally its either "w:" or "s:"
1626fun! s:NetrwOptionsSave(vt)
1627" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1628" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
1629" 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>"))
1630
1631 if !exists("{a:vt}netrw_optionsave")
1632 let {a:vt}netrw_optionsave= 1
1633 else
1634" call Dret("s:NetrwOptionsSave : options already saved")
1635 return
1636 endif
1637" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1638
1639 " Save current settings and current directory
1640" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1641 let s:yykeep = @@
1642 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1643 let {a:vt}netrw_aikeep = &l:ai
1644 let {a:vt}netrw_awkeep = &l:aw
1645 let {a:vt}netrw_bhkeep = &l:bh
1646 let {a:vt}netrw_blkeep = &l:bl
1647 let {a:vt}netrw_btkeep = &l:bt
1648 let {a:vt}netrw_bombkeep = &l:bomb
1649 let {a:vt}netrw_cedit = &cedit
1650 let {a:vt}netrw_cikeep = &l:ci
1651 let {a:vt}netrw_cinkeep = &l:cin
1652 let {a:vt}netrw_cinokeep = &l:cino
1653 let {a:vt}netrw_comkeep = &l:com
1654 let {a:vt}netrw_cpokeep = &l:cpo
1655 let {a:vt}netrw_diffkeep = &l:diff
1656 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001657 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1658 let {a:vt}netrw_ffkeep = &l:ff
1659 endif
1660 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1661 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1662 let {a:vt}netrw_hidkeep = &l:hidden
1663 let {a:vt}netrw_imkeep = &l:im
1664 let {a:vt}netrw_iskkeep = &l:isk
1665 let {a:vt}netrw_lskeep = &l:ls
1666 let {a:vt}netrw_makeep = &l:ma
1667 let {a:vt}netrw_magickeep = &l:magic
1668 let {a:vt}netrw_modkeep = &l:mod
1669 let {a:vt}netrw_nukeep = &l:nu
1670 let {a:vt}netrw_rnukeep = &l:rnu
1671 let {a:vt}netrw_repkeep = &l:report
1672 let {a:vt}netrw_rokeep = &l:ro
1673 let {a:vt}netrw_selkeep = &l:sel
1674 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001675 if !g:netrw_use_noswf
1676 let {a:vt}netrw_swfkeep = &l:swf
1677 endif
1678 let {a:vt}netrw_tskeep = &l:ts
1679 let {a:vt}netrw_twkeep = &l:tw " textwidth
1680 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1681 let {a:vt}netrw_wrapkeep = &l:wrap
1682 let {a:vt}netrw_writekeep = &l:write
1683
1684 " save a few selected netrw-related variables
1685" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1686 if g:netrw_keepdir
1687 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001688" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 endif
1690 if has("clipboard")
1691 sil! let {a:vt}netrw_starkeep = @*
1692 sil! let {a:vt}netrw_pluskeep = @+
1693 endif
1694 sil! let {a:vt}netrw_slashkeep= @/
1695
1696" 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>"))
1697" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1698endfun
1699
1700" ---------------------------------------------------------------------
1701" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1702" Use s:NetrwSaveOptions() to save user settings
1703" Use s:NetrwOptionsRestore() to restore user settings
1704fun! s:NetrwOptionsSafe(islocal)
1705" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1706" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1707" 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>"))
1708 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1709 call s:NetrwSetSafeSetting("&l:ai",0)
1710 call s:NetrwSetSafeSetting("&l:aw",0)
1711 call s:NetrwSetSafeSetting("&l:bl",0)
1712 call s:NetrwSetSafeSetting("&l:bomb",0)
1713 if a:islocal
1714 call s:NetrwSetSafeSetting("&l:bt","nofile")
1715 else
1716 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1717 endif
1718 call s:NetrwSetSafeSetting("&l:ci",0)
1719 call s:NetrwSetSafeSetting("&l:cin",0)
1720 call s:NetrwSetSafeSetting("&l:bh","hide")
1721 call s:NetrwSetSafeSetting("&l:cino","")
1722 call s:NetrwSetSafeSetting("&l:com","")
1723 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1724 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1725 setl fo=nroql2
1726 call s:NetrwSetSafeSetting("&l:hid",0)
1727 call s:NetrwSetSafeSetting("&l:im",0)
1728 setl isk+=@ isk+=* isk+=/
1729 call s:NetrwSetSafeSetting("&l:magic",1)
1730 if g:netrw_use_noswf
1731 call s:NetrwSetSafeSetting("swf",0)
1732 endif
1733 call s:NetrwSetSafeSetting("&l:report",10000)
1734 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1735 call s:NetrwSetSafeSetting("&l:spell",0)
1736 call s:NetrwSetSafeSetting("&l:tw",0)
1737 call s:NetrwSetSafeSetting("&l:wig","")
1738 setl cedit&
1739 call s:NetrwCursor()
1740
1741 " allow the user to override safe options
1742" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1743 if &ft == "netrw"
1744" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1745 keepalt NetrwKeepj doau FileType netrw
1746 endif
1747
1748" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1749" 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>"))
1750" call Dret("s:NetrwOptionsSafe")
1751endfun
1752
1753" ---------------------------------------------------------------------
1754" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1755fun! s:NetrwOptionsRestore(vt)
1756" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001757" 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 +01001758 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001759" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001760" 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>"))
1761" 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 +02001762" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001763 return
1764 endif
1765 unlet {a:vt}netrw_optionsave
1766
1767 if exists("+acd")
1768 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001769" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001770 let curdir = getcwd()
1771 let &l:acd = {a:vt}netrw_acdkeep
1772 unlet {a:vt}netrw_acdkeep
1773 if &l:acd
1774 call s:NetrwLcd(curdir)
1775 endif
1776 endif
1777 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001778 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1779 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1780 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1781 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1782 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1783 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1784 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1785 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1786 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1787 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1788 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1789 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1790 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1791 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1792 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001793 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001794 call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
1795 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
1796 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
1797 call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
1798 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
1799 call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
1800 call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
1801 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
1802 call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
1803 call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
1804 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
1805 call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
1806 call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
1807 call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1808 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
1809 call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
1810 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
1811 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
1812 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1813 call s:NetrwRestoreSetting("s:yykeep","@@")
1814 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1815 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1816 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1817 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1818
Bram Moolenaara6878372014-03-22 21:02:50 +01001819 if exists("{a:vt}netrw_swfkeep")
1820 if &directory == ""
1821 " user hasn't specified a swapfile directory;
1822 " netrw will temporarily set the swapfile directory
1823 " to the current directory as returned by getcwd().
1824 let &l:directory= getcwd()
1825 sil! let &l:swf = {a:vt}netrw_swfkeep
1826 setl directory=
1827 unlet {a:vt}netrw_swfkeep
1828 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001829 if !g:netrw_use_noswf
1830 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1831 sil! let &l:swf= {a:vt}netrw_swfkeep
1832 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001833 unlet {a:vt}netrw_swfkeep
1834 endif
1835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001836 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001837 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1838 if exists("{a:vt}netrw_dirkeep")
1839 call s:NetrwLcd(dirkeep)
1840 unlet {a:vt}netrw_dirkeep
1841 endif
1842 endif
1843 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001844" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001845 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1846 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001847 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001849
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001850" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1851" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1852" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1853" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1854" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001855 " Moved the filetype detect here from NetrwGetFile() because remote files
1856 " were having their filetype detect-generated settings overwritten by
1857 " NetrwOptionRestore.
1858 if &ft != "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001859" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001860 filetype detect
1861 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001862" 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 +02001863" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001864endfun
1865
1866" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1868" but only when the options' value and the safe setting differ
1869" Doing this means that netrw will not come up as having changed a
1870" setting last when it really didn't actually change it.
1871"
1872" Called from s:NetrwOptionsSafe
1873" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1874fun! s:NetrwSetSafeSetting(setting,safesetting)
1875" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001876
Bram Moolenaar85850f32019-07-19 22:05:51 +02001877 if a:setting =~ '^&'
1878" call Decho("fyi: a:setting starts with &")
1879 exe "let settingval= ".a:setting
1880" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001881
Bram Moolenaar85850f32019-07-19 22:05:51 +02001882 if settingval != a:safesetting
1883" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1884 if type(a:safesetting) == 0
1885 exe "let ".a:setting."=".a:safesetting
1886 elseif type(a:safesetting) == 1
1887 exe "let ".a:setting."= '".a:safesetting."'"
1888 else
1889 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1890 endif
1891 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001892 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001893
Bram Moolenaar85850f32019-07-19 22:05:51 +02001894" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001895endfun
1896
1897" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001898" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1899" but only if the setting value differs from the associated keepvar.
1900" Doing this means that netrw will not come up as having changed a
1901" setting last when it really didn't actually change it.
1902"
1903" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1904" keepvars are set up by s:NetrwOptionsSave
1905fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001906""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 " typically called from s:NetrwOptionsRestore
1909 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1910 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1911 " Restores option (if different) from a keepvar
1912 if exists(a:keepvar)
1913 exe "let keepvarval= ".a:keepvar
1914 exe "let setting= ".a:setting
1915
1916"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1917"" call Decho("fyi: keepvarval=".keepvarval)
1918"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1919
1920 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001921"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001922 if type(a:setting) == 0
1923 exe "let ".a:setting."= ".keepvarval
1924 elseif type(a:setting) == 1
1925 exe "let ".a:setting."= '".keepvarval."'"
1926 else
1927 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1928 endif
1929 endif
1930
1931 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001932 endif
1933
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001935endfun
1936
1937" ---------------------------------------------------------------------
1938" NetrwStatusLine: {{{2
1939fun! NetrwStatusLine()
1940
1941" vvv NetrwStatusLine() debugging vvv
1942" let g:stlmsg=""
1943" if !exists("w:netrw_explore_bufnr")
1944" let g:stlmsg="!X<explore_bufnr>"
1945" elseif w:netrw_explore_bufnr != bufnr("%")
1946" let g:stlmsg="explore_bufnr!=".bufnr("%")
1947" endif
1948" if !exists("w:netrw_explore_line")
1949" let g:stlmsg=" !X<explore_line>"
1950" elseif w:netrw_explore_line != line(".")
1951" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1952" endif
1953" if !exists("w:netrw_explore_list")
1954" let g:stlmsg=" !X<explore_list>"
1955" endif
1956" ^^^ NetrwStatusLine() debugging ^^^
1957
1958 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")
1959 " restore user's status line
1960 let &stl = s:netrw_users_stl
1961 let &laststatus = s:netrw_users_ls
1962 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1963 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1964 return ""
1965 else
1966 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1967 endif
1968endfun
1969
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001971" Netrw Transfer Functions: {{{1
1972" ===============================
1973
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001975" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001976" mode: =0 read remote file and insert before current line
1977" =1 read remote file and insert after current line
1978" =2 replace with remote file
1979" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001980fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001981" 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 +00001982
Bram Moolenaar5c736222010-01-06 20:54:52 +01001983 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 call s:NetrwOptionsSave("w:")
1985 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001986 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001987 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1988 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1989 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001990" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001991
Bram Moolenaar5c736222010-01-06 20:54:52 +01001992 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001993 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001994 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001995 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001996 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001997 elseif a:mode == 2 " replace with remote file
1998 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001999 elseif a:mode == 3 " skip read of file (leave as temporary)
2000 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002001 else
2002 exe a:mode
2003 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002004 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002005 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002006" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002007
Bram Moolenaar5c736222010-01-06 20:54:52 +01002008 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002009 let tmpfile= s:GetTempfile("")
2010 if tmpfile == ""
2011" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002012 return
2013 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002014
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002015 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002016
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002017 " attempt to repeat with previous host-file-etc
2018 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002019" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002020 let choice = b:netrw_lastfile
2021 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002022
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 else
2024 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002025" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002026
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002027 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002028 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002029 echomsg 'NetRead Usage:'
2030 echomsg ':Nread machine:path uses rcp'
2031 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2032 echomsg ':Nread "machine id password path" uses ftp'
2033 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2034 echomsg ':Nread fetch://machine/path uses fetch'
2035 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2036 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002037 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002038 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002039 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2040 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2041 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2042 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002043 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002045
Bram Moolenaar9964e462007-05-05 17:54:07 +00002046 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002047 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002048" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002049 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002051 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 else
2053 " case "... ... ..."
2054 let choice = strpart(choice,1,strlen(choice)-1)
2055 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar9964e462007-05-05 17:54:07 +00002057 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 let wholechoice = wholechoice . " " . choice
2059 let ichoice = ichoice + 1
2060 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002061 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002062 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002063 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 return
2066 endif
2067 let choice= a:{ichoice}
2068 endwhile
2069 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2070 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 endif
2072 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002074" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaar5c736222010-01-06 20:54:52 +01002077 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002078 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002079 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002080" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002081 return
2082 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002083 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaar8d043172014-01-23 14:24:41 +01002085 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002086" 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 +02002087 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002089 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002090" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002091 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002093
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002095 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002096 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002097 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2098 echo "(netrw) Processing your read request..."
2099 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002100
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002102 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002105 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002107 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 " ER: the tmpfile is full path: rcp sees C:\... as host C
2109 if s:netrw_has_nt_rcp == 1
2110 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2111 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2112 else
2113 " Any way needed it machine contains a '.'
2114 let uid_machine = g:netrw_machine .'.'. $USERNAME
2115 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2118 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2119 else
2120 let uid_machine = g:netrw_machine
2121 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002123 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 +00002124 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002126
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002128 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002131 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002132 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002133 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002134 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002135 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002137 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002140 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002141 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144 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 +00002145 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 endif
2148 " 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 +00002149 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002150 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002151 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002152 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002153 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002155 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002156 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2158 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002159 q!
2160 endif
2161 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002162 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002164
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002166 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2168 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002170 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002171 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002172 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002173 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002175 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002178 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002181
Bram Moolenaar97d62492012-11-15 21:28:22 +01002182 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002183 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002186 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002190 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002193 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002195
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002199 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002203 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002204 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002206
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 " perform ftp:
2208 " -i : turns off interactive prompting from ftp
2209 " -n unix : DON'T use <.netrc>, even though it exists
2210 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002211 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2214 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002216 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002217 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002218 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002220 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002221 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002223
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002225 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002227" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002229 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 else
2231 let useport= ""
2232 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2234 " This is workaround to avoid mis-handle windows local-path:
2235 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2236 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2237 else
2238 let tmpfile_get = tmpfile
2239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002240 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 +00002241 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002243
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002244 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002245 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002246 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002249 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002250 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002251 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002252" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002253 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002256 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2257 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002259 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260 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 +00002261 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262 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 +00002263 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002264 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002265
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002266 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002267 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002269 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2270 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002271" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2272" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2273 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 +00002274 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002276 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 endif
2278 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002280 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002281
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002283 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002284 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002286
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 if !executable(g:netrw_dav_cmd)
2288 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2289" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2290 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002292 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002293 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 +01002294 else
2295 " Construct execution string (four lines) which will be passed through filter
2296 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2297 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002298 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002299 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002300 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002302 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002303 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002304 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002305 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002306 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002307 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2308 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002311 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002312 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002313 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002314 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002315 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002316 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002318 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002319 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002320 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002322 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 +00002323 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002325
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002327 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002329 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002332 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002333 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002334 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002335" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002336 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002338 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 let netrw_option= "http"
2340 else
2341 let netrw_option= "ftp"
2342 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaar446cb832008-06-24 21:56:24 +00002345 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002346 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 +00002347 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348 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 +00002349 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaar446cb832008-06-24 21:56:24 +00002351 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002352 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002353" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002354 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002355
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002358 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002359" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2360 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 +00002361 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002362 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002363
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002364 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 " NetRead: (file) NetRead Method #10 {{{3
2366 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2368 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2370 let b:netrw_lastfile = choice
2371
2372 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002374 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002375 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 endif
2377 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002381" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 unlet b:netrw_fname
2384 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002385 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 +01002386" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002387 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002388 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002389 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002390
Bram Moolenaar9964e462007-05-05 17:54:07 +00002391" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392endfun
2393
2394" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002395" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002396fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002397" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002398
Bram Moolenaar5c736222010-01-06 20:54:52 +01002399 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002401 call s:NetrwOptionsSave("w:")
2402 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaar5c736222010-01-06 20:54:52 +01002404 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002405 let tmpfile= s:GetTempfile("")
2406 if tmpfile == ""
2407" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002408 return
2409 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 if a:0 == 0
2412 let ichoice = 0
2413 else
2414 let ichoice = 1
2415 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaar9964e462007-05-05 17:54:07 +00002417 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002419 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002420 " For binary writes, always write entire file.
2421 " (line numbers don't really make sense for that).
2422 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002423" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002424 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002425 elseif g:netrw_cygwin
2426 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002427 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002428" 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 +01002429 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002430 else
2431 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002432" 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 +01002433 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002434 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002435
Bram Moolenaar9964e462007-05-05 17:54:07 +00002436 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002437 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002438 " on the temporary file's name. Deletion of the temporary file during
2439 " cleanup then causes an error message.
2440 0file!
2441 endif
2442
Bram Moolenaar5c736222010-01-06 20:54:52 +01002443 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002445
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002447 " attempt to repeat with previous host-file-etc
2448 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002449" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002450 let choice = b:netrw_lastfile
2451 let ichoice= ichoice + 1
2452 else
2453 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002454
Bram Moolenaar8d043172014-01-23 14:24:41 +01002455 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002456 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002457 echomsg 'NetWrite Usage:"'
2458 echomsg ':Nwrite machine:path uses rcp'
2459 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2460 echomsg ':Nwrite "machine id password path" uses ftp'
2461 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2462 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2463 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2464 echomsg ':Nwrite rcp://machine/path uses rcp'
2465 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2466 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2467 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002468 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002469 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002470
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002471 elseif match(choice,"^\"") != -1
2472 if match(choice,"\"$") != -1
2473 " case "..."
2474 let choice=strpart(choice,1,strlen(choice)-2)
2475 else
2476 " case "... ... ..."
2477 let choice = strpart(choice,1,strlen(choice)-1)
2478 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002479
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002480 while match(choice,"\"$") == -1
2481 let wholechoice= wholechoice . " " . choice
2482 let ichoice = ichoice + 1
2483 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002484 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002488 return
2489 endif
2490 let choice= a:{ichoice}
2491 endwhile
2492 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2493 endif
2494 endif
2495 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002496 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002498
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002500 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002501 if !exists("b:netrw_method") || b:netrw_method < 0
2502" call Dfunc("netrw#NetWrite : unsupported method")
2503 return
2504 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002505
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002507 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002508 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002509 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2510 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002511" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002512 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002513
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002514 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002515 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002516 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002517" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 if s:netrw_has_nt_rcp == 1
2519 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2520 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2521 else
2522 let uid_machine = g:netrw_machine .'.'. $USERNAME
2523 endif
2524 else
2525 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2526 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2527 else
2528 let uid_machine = g:netrw_machine
2529 endif
2530 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002531 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 +00002532 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002535 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002536 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002537" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002538 let netrw_fname = b:netrw_fname
2539
2540 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2541 let bhkeep = &l:bh
2542 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002543 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002544 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002545
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002547 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002548 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002550 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002551 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002553 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002554 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557 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 +00002558 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2560 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 endif
2562 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2563 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002564 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002565 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002566 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569
2570 " remove enew buffer (quietly)
2571 let filtbuf= bufnr("%")
2572 exe curbuf."b!"
2573 let &l:bh = bhkeep
2574 exe filtbuf."bw!"
2575
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002577
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002579 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002580 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002581 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002583 let netrw_fname = b:netrw_fname
2584 let bhkeep = &l:bh
2585
2586 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2587 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002588 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002590 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002593 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002596 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002599 if exists("g:netrw_uid") && g:netrw_uid != ""
2600 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002603 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002605 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002607 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002610 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002611 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002614 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002615 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002617 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002618 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002620 " save choice/id/password for future use
2621 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002622
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002623 " perform ftp:
2624 " -i : turns off interactive prompting from ftp
2625 " -n unix : DON'T use <.netrc>, even though it exists
2626 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002627 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002628 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2630 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002631 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002632 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002633 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002634 let mod=1
2635 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002636
2637 " remove enew buffer (quietly)
2638 let filtbuf= bufnr("%")
2639 exe curbuf."b!"
2640 let &l:bh= bhkeep
2641 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002642
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002643 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002645 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002648 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 else
2650 let useport= ""
2651 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652 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 +00002653 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002654
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002656 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002659 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2660 if executable(curl)
2661 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662 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 +01002663 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002664 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002665 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002666
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002668 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002669 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002671
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2674 let bhkeep = &l:bh
2675
2676 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2677 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002678 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680
Bram Moolenaarff034192013-04-24 18:51:19 +02002681 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002685 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002687 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002688 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002689 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002690 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002691
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002693 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002694 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002695
2696 " remove enew buffer (quietly)
2697 let filtbuf= bufnr("%")
2698 exe curbuf."b!"
2699 let &l:bh = bhkeep
2700 exe filtbuf."bw!"
2701
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002706 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002708 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 +00002709 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002710
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002712 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002713 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2717 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2718 else
2719 let uid_machine = g:netrw_machine
2720 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002721
2722 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2723 let bhkeep = &l:bh
2724 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002725 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002726 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727
Bram Moolenaarff034192013-04-24 18:51:19 +02002728 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002730" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002731 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 let filtbuf= bufnr("%")
2734 exe curbuf."b!"
2735 let &l:bh = bhkeep
2736 exe filtbuf."bw!"
2737 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002738
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002740 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002741 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002742 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002743 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002746
Bram Moolenaar5c736222010-01-06 20:54:52 +01002747 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002748" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002749 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002750" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002751 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002752 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002753 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002754
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002756 " restore modifiability; usually equivalent to set nomod
2757 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002758" 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 +02002759 elseif !exists("leavemod")
2760 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002761" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002762 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002763" 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 +00002764 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765
Bram Moolenaar9964e462007-05-05 17:54:07 +00002766" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767endfun
2768
2769" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002770" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002771" uses NetRead to get a copy of the file into a temporarily file,
2772" then sources that file,
2773" then removes that file.
2774fun! netrw#NetSource(...)
2775" call Dfunc("netrw#NetSource() a:0=".a:0)
2776 if a:0 > 0 && a:1 == '?'
2777 " give help
2778 echomsg 'NetSource Usage:'
2779 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2780 echomsg ':Nsource fetch://machine/path uses fetch'
2781 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002782 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002783 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2784 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2785 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2786 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2787 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002788 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002789 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002790 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002791 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002793 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002795 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002796" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002797 if delete(s:netrw_tmpfile)
2798 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2799 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800 unlet s:netrw_tmpfile
2801 else
2802 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2803 endif
2804 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002805 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 endif
2807" call Dret("netrw#NetSource")
2808endfun
2809
Bram Moolenaar8d043172014-01-23 14:24:41 +01002810" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002811" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2812" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002813fun! netrw#SetTreetop(iscmd,...)
2814" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2815" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002816
Bram Moolenaar85850f32019-07-19 22:05:51 +02002817 " iscmd==0: netrw#SetTreetop called using gn mapping
2818 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2819" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002820 " clear out the current tree
2821 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002823 let inittreetop= w:netrw_treetop
2824 unlet w:netrw_treetop
2825 endif
2826 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002827" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002828 unlet w:netrw_treedict
2829 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002830" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002831
Bram Moolenaar85850f32019-07-19 22:05:51 +02002832 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002833 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002834" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002835 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002836 if isdirectory(s:NetrwFile(a:1))
2837" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002838 let treedir= a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002839 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar8d043172014-01-23 14:24:41 +01002840 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002841" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002842 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002843 " normally the cursor is left in the message window.
2844 " However, here this results in the directory being listed in the message window, which is not wanted.
2845 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002846 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002847 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01002848 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002849 endif
2850 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002852
2853 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854 let islocal= expand("%") !~ '^\a\{3,}://'
2855" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002856
2857 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002858 if islocal
2859 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2860 else
2861 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2862 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002863
Bram Moolenaara6878372014-03-22 21:02:50 +01002864" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002865endfun
2866
Bram Moolenaar9964e462007-05-05 17:54:07 +00002867" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002868" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869" readcmd == %r : replace buffer with newly read file
2870" == 0r : read file at top of buffer
2871" == r : read file after current line
2872" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002873fun! s:NetrwGetFile(readcmd, tfile, method)
2874" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002875
2876 " readcmd=='t': simply do nothing
2877 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002878" 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 +01002879" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002880 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002881 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002882
Bram Moolenaar9964e462007-05-05 17:54:07 +00002883 " get name of remote filename (ie. url and all)
2884 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002886
Bram Moolenaar9964e462007-05-05 17:54:07 +00002887 if exists("*NetReadFixup")
2888 " for the use of NetReadFixup (not otherwise used internally)
2889 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002890 endif
2891
Bram Moolenaar9964e462007-05-05 17:54:07 +00002892 if a:readcmd[0] == '%'
2893 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002895
2896 " rename the current buffer to the temp file (ie. tfile)
2897 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002899 else
2900 let tfile= a:tfile
2901 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002902 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002903
2904 " edit temporary file (ie. read the temporary file in)
2905 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002907 call zip#Browse(tfile)
2908 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002910 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002911 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002913 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002914 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002917 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002919 call tar#Browse(tfile)
2920 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002921" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002922 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002923 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002924" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002925 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926 endif
2927
2928 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002929 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002930
Bram Moolenaar97d62492012-11-15 21:28:22 +01002931 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002932 " Note that isk must not include a "/" for scripts.vim
2933 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002934" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002935 let iskkeep= &l:isk
2936 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002937 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002938" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939 let line1 = 1
2940 let line2 = line("$")
2941
Bram Moolenaar8d043172014-01-23 14:24:41 +01002942 elseif !&ma
2943 " 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 +01002944 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002946 return
2947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 elseif s:FileReadable(a:tfile)
2949 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 let curline = line(".")
2952 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002954 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 let line1= curline + 1
2956 let line2= line("$") - lastline + 1
2957
2958 else
2959 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002960" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2961" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002962 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002963" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 return
2965 endif
2966
2967 " User-provided (ie. optional) fix-it-up command
2968 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002970 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 endif
2974
Bram Moolenaaradc21822011-04-01 18:03:16 +02002975 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002976 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002977 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 endif
2979
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" 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 +00002981
2982 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002983" redraw!
2984
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" 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 +00002986" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002987endfun
2988
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002990" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002991" Input:
2992" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2993" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002994" b:netrw_method= 1: rcp
2995" 2: ftp + <.netrc>
2996" 3: ftp + machine, id, password, and [path]filename
2997" 4: scp
2998" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002999" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003000" 7: rsync
3001" 8: fetch
3002" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003003" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003004" g:netrw_machine= hostname
3005" b:netrw_fname = filename
3006" g:netrw_port = optional port number (for ftp)
3007" g:netrw_choice = copy of input url (choice)
3008fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003009" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003010
Bram Moolenaar251e1912011-06-19 05:09:16 +02003011 " sanity check: choice should have at least three slashes in it
3012 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3013 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3014 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003015" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003016 return
3017 endif
3018
Bram Moolenaar5c736222010-01-06 20:54:52 +01003019 " record current g:netrw_machine, if any
3020 " curmachine used if protocol == ftp and no .netrc
3021 if exists("g:netrw_machine")
3022 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003024 else
3025 let curmachine= "N O T A HOST"
3026 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003027 if exists("g:netrw_port")
3028 let netrw_port= g:netrw_port
3029 endif
3030
3031 " insure that netrw_ftp_cmd starts off every method determination
3032 " with the current g:netrw_ftp_cmd
3033 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003034
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003035 " initialization
3036 let b:netrw_method = 0
3037 let g:netrw_machine = ""
3038 let b:netrw_fname = ""
3039 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003040 let g:netrw_choice = a:choice
3041
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003042 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003043 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003044 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3045 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003046 " rcpurm : rcp://[user@]host/filename Use rcp
3047 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003048 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003049 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003050 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003051 " rsyncurm : rsync://host[:port]/path Use rsync
3052 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3053 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003054 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003055 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3056 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003057 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3058 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003059 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003060 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003061 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003062 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003063 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003064 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003066 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003067
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003069 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003070 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003071 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003072" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003073 let b:netrw_method = 1
3074 let userid = substitute(a:choice,rcpurm,'\1',"")
3075 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3076 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003077 if userid != ""
3078 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003080
Bram Moolenaaradc21822011-04-01 18:03:16 +02003081 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003082 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003083" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003084 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003085 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3086 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3087 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003088
Bram Moolenaar15146672011-10-20 22:22:38 +02003089 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003090 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003091" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003092 let b:netrw_method = 5
3093 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3094 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003095 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003096
Bram Moolenaaradc21822011-04-01 18:03:16 +02003097 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003099" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003101 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003102 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3103 else
3104 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3105 endif
3106 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003107
Bram Moolenaaradc21822011-04-01 18:03:16 +02003108 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003110" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 let b:netrw_method = 7
3112 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3113 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003114
Bram Moolenaaradc21822011-04-01 18:03:16 +02003115 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003117" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003118 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3120 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3121 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003122" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 if userid != ""
3124 let g:netrw_uid= userid
3125 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003126
Bram Moolenaaradc21822011-04-01 18:03:16 +02003127 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003128 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003129 call NetUserPass("ftp:".g:netrw_machine)
3130 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003131 " if there's a change in hostname, require password re-entry
3132 unlet s:netrw_passwd
3133 endif
3134 if exists("netrw_port")
3135 unlet netrw_port
3136 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003137 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003138
Bram Moolenaar446cb832008-06-24 21:56:24 +00003139 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 let b:netrw_method = 3
3141 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003142 let host= substitute(g:netrw_machine,'\..*$','','')
3143 if exists("s:netrw_hup[host]")
3144 call NetUserPass("ftp:".host)
3145
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003146 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003147" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3148" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003149 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003150 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003151" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003152 endif
3153 let b:netrw_method= 2
3154 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 let b:netrw_method= 2
3157 else
3158 if !exists("g:netrw_uid") || g:netrw_uid == ""
3159 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003160 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003162 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 endif
3164 let b:netrw_method= 3
3165 endif
3166 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_method = 8
3172 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3173 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3174 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3175 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003176
Bram Moolenaaradc21822011-04-01 18:03:16 +02003177 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003179" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3182 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003183 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003184 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003185 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003186
Bram Moolenaaradc21822011-04-01 18:03:16 +02003187 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003190 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 let b:netrw_method = 3
3192 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3193 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003194
Bram Moolenaar9964e462007-05-05 17:54:07 +00003195 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003196 let b:netrw_method = 2
3197 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3198 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3199 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003200
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003202 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003203" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003204 let b:netrw_method = 9
3205 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3206 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003207
Bram Moolenaaradc21822011-04-01 18:03:16 +02003208 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003209 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003210" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003211 let b:netrw_method = 1
3212 let userid = substitute(a:choice,rcphf,'\2',"")
3213 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3214 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003215" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3216" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3217" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3218" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 if userid != ""
3220 let g:netrw_uid= userid
3221 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003222
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003223 " Method#10: file://user@hostname/...path-to-file {{{3
3224 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003226 let b:netrw_method = 10
3227 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003228" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003229
Bram Moolenaaradc21822011-04-01 18:03:16 +02003230 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003232 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003233 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003234 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003237 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003238
Bram Moolenaar81695252004-12-29 20:58:21 +00003239 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " remove any leading [:#] from port number
3241 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3242 elseif exists("netrw_port")
3243 " retain port number as implicit for subsequent ftp operations
3244 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003245 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003246
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3248" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3249" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3250" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003251" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003252" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003253" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003255" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003256" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003257" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003258" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260
3261" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003262" NetReadFixup: this sort of function is typically written by the user {{{2
3263" to handle extra junk that their system's ftp dumps
3264" into the transfer. This function is provided as an
3265" example and as a fix for a Windows 95 problem: in my
3266" experience, win95's ftp always dumped four blank lines
3267" at the end of the transfer.
3268if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3269 fun! NetReadFixup(method, line1, line2)
3270" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003271
3272 " sanity checks -- attempt to convert inputs to integers
3273 let method = a:method + 0
3274 let line1 = a:line1 + 0
3275 let line2 = a:line2 + 0
3276 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3277" call Dret("NetReadFixup")
3278 return
3279 endif
3280
Bram Moolenaar9964e462007-05-05 17:54:07 +00003281 if method == 3 " ftp (no <.netrc>)
3282 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003283 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003284 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003285 call histdel("/",-1)
3286 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003287 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003288
Bram Moolenaar9964e462007-05-05 17:54:07 +00003289" call Dret("NetReadFixup")
3290 endfun
3291endif
3292
3293" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003294" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003295" Usage: :call NetUserPass() -- will prompt for userid and password
3296" :call NetUserPass("uid") -- will prompt for password
3297" :call NetUserPass("uid","password") -- sets global userid and password
3298" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3299" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300fun! NetUserPass(...)
3301
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003302" call Dfunc("NetUserPass() a:0=".a:0)
3303
3304 if !exists('s:netrw_hup')
3305 let s:netrw_hup= {}
3306 endif
3307
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003309 " case: no input arguments
3310
3311 " change host and username if not previously entered; get new password
3312 if !exists("g:netrw_machine")
3313 let g:netrw_machine= input('Enter hostname: ')
3314 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003316 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 let g:netrw_uid= input('Enter username: ')
3318 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003319 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003320 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003321
3322 " set up hup database
3323 let host = substitute(g:netrw_machine,'\..*$','','')
3324 if !exists('s:netrw_hup[host]')
3325 let s:netrw_hup[host]= {}
3326 endif
3327 let s:netrw_hup[host].uid = g:netrw_uid
3328 let s:netrw_hup[host].passwd = s:netrw_passwd
3329
3330 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003331 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003332
3333 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003334 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003335 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003336" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337 let host = substitute(a:1,'^ftp:','','')
3338 let host = substitute(host,'\..*','','')
3339 if exists("s:netrw_hup[host]")
3340 let g:netrw_uid = s:netrw_hup[host].uid
3341 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003342" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3343" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344 else
3345 let g:netrw_uid = input("Enter UserId: ")
3346 let s:netrw_passwd = inputsecret("Enter Password: ")
3347 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003349 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003350 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003351" 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 +02003352 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003353 if g:netrw_machine =~ '[0-9.]\+'
3354 let host= g:netrw_machine
3355 else
3356 let host= substitute(g:netrw_machine,'\..*$','','')
3357 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 else
3359 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003360 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003361 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003362" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003363 if exists("g:netrw_passwd")
3364 " ask for password if one not previously entered
3365 let s:netrw_passwd= g:netrw_passwd
3366 else
3367 let s:netrw_passwd = inputsecret("Enter Password: ")
3368 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369 endif
3370
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003371" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372 if exists("host")
3373 if !exists('s:netrw_hup[host]')
3374 let s:netrw_hup[host]= {}
3375 endif
3376 let s:netrw_hup[host].uid = g:netrw_uid
3377 let s:netrw_hup[host].passwd = s:netrw_passwd
3378 endif
3379
3380 elseif a:0 == 2
3381 let g:netrw_uid = a:1
3382 let s:netrw_passwd = a:2
3383
3384 elseif a:0 == 3
3385 " enter hostname, user-id, and password into the hup dictionary
3386 let host = substitute(a:1,'^\a\+:','','')
3387 let host = substitute(host,'\..*$','','')
3388 if !exists('s:netrw_hup[host]')
3389 let s:netrw_hup[host]= {}
3390 endif
3391 let s:netrw_hup[host].uid = a:2
3392 let s:netrw_hup[host].passwd = a:3
3393 let g:netrw_uid = s:netrw_hup[host].uid
3394 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003395" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3396" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003398
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003399" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401
Bram Moolenaar85850f32019-07-19 22:05:51 +02003402" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003403" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003404" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003406" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003407" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3408fun! s:ExplorePatHls(pattern)
3409" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3410 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003412 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003413" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003414 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3415" call Dret("s:ExplorePatHls repat<".repat.">")
3416 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003417endfun
3418
3419" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003420" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003421" 0: (user: <mb>) bookmark current directory
3422" 1: (user: <gb>) change to the bookmarked directory
3423" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003424" 3: (browsing) records current directory history
3425" 4: (user: <u>) go up (previous) directory, using history
3426" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003427" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003428fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003429" 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 +02003430 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3431" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3432 return
3433 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003434
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003435 let ykeep = @@
3436 let curbufnr = bufnr("%")
3437
Bram Moolenaar9964e462007-05-05 17:54:07 +00003438 if a:chg == 0
3439 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003441 if exists("s:netrwmarkfilelist_{curbufnr}")
3442 call s:NetrwBookmark(0)
3443 echo "bookmarked marked files"
3444 else
3445 call s:MakeBookmark(a:curdir)
3446 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003447 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003448
3449 elseif a:chg == 1
3450 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003452 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003454 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455 else
3456 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3457 endif
3458
3459 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003461 let didwork= 0
3462 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003464 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003466 let cnt= 1
3467 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003468" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003469 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003470 let didwork = 1
3471 let cnt = cnt + 1
3472 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473 endif
3474
3475 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003476 " Note: history is saved only when PerformListing is done;
3477 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3478 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003479 let first = 1
3480 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003481 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003482 while ( first || cnt != g:netrw_dirhistcnt )
3483" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003484 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003485" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003486 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 let didwork= 1
3488 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003489 let histcnt = histcnt + 1
3490 let first = 0
3491 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003492 if cnt < 0
3493 let cnt= cnt + g:netrw_dirhistmax
3494 endif
3495 endwhile
3496 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003497 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003498 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 if didwork
3500 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3501 endif
3502
3503 elseif a:chg == 3
3504 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003506 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 +02003507 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003508 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3509 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003510 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003511" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 endif
3513
3514 elseif a:chg == 4
3515 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003516" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003517 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3519 if g:netrw_dirhistcnt < 0
3520 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 endif
3522 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003524 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003525 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3526" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003527 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003528 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003529" call Decho("setl ma noro",'~'.expand("<slnum>"))
3530 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003531 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003532" call Decho("setl nomod",'~'.expand("<slnum>"))
3533" 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 +00003534 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3536 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003537 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003539 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003540 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003542 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003543 echo "Sorry, no predecessor directory exists yet"
3544 endif
3545
3546 elseif a:chg == 5
3547 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3551 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3552" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003553 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003554" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003555 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003556 sil! NetrwKeepj %d _
3557" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3558" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003559 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003560" 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 +02003561 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3563 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3566 if g:netrw_dirhistcnt < 0
3567 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 endif
3569 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003570 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003571 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003573 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003574 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003575
3576 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003577" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003578 if exists("s:netrwmarkfilelist_{curbufnr}")
3579 call s:NetrwBookmark(1)
3580 echo "removed marked files from bookmarks"
3581 else
3582 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003583 let iremove = v:count
3584 let dremove = g:netrw_bookmarklist[iremove - 1]
3585" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003586 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003587" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3588 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3589 echo "removed ".dremove." from g:netrw_bookmarklist"
3590" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003593 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003594 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003595 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003596 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003597" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003598endfun
3599
3600" ---------------------------------------------------------------------
3601" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003602" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003603" Sister function: s:NetrwBookHistSave()
3604fun! s:NetrwBookHistRead()
3605" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003606 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607" 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 +02003608 return
3609 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003610 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003611
3612 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003613 if !exists("s:netrw_initbookhist")
3614 let home = s:NetrwHome()
3615 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003616 if filereadable(s:NetrwFile(savefile))
3617" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003618 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003619 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003620
3621 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003622 if g:netrw_dirhistmax > 0
3623 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624 if filereadable(s:NetrwFile(savefile))
3625" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003626 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003627 endif
3628 let s:netrw_initbookhist= 1
3629 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003632
Bram Moolenaar97d62492012-11-15 21:28:22 +01003633 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003634" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3635" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003636" call Dret("s:NetrwBookHistRead")
3637endfun
3638
3639" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003640" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641" Sister function: s:NetrwBookHistRead()
3642" I used to do this via viminfo but that appears to
3643" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003644" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3645" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003646" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003649 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003651 return
3652 endif
3653
Bram Moolenaar5c736222010-01-06 20:54:52 +01003654 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003656 1split
3657 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003658" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003659 if g:netrw_use_noswf
3660 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3661 else
3662 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3663 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003664 setl nocin noai noci magic nospell nohid wig= noaw
3665 setl ma noro write
3666 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003667 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668
Bram Moolenaar85850f32019-07-19 22:05:51 +02003669 " rename enew'd file: .netrwhist -- no attempt to merge
3670 " record dirhistmax and current dirhistcnt
3671 " save history
3672" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003673 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003674 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003675 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3676 if g:netrw_dirhistmax > 0
3677 let lastline = line("$")
3678 let cnt = g:netrw_dirhistcnt
3679 let first = 1
3680 while ( first || cnt != g:netrw_dirhistcnt )
3681 let lastline= lastline + 1
3682 if exists("g:netrw_dirhist_{cnt}")
3683 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3684" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3685 endif
3686 let first = 0
3687 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3688 if cnt < 0
3689 let cnt= cnt + g:netrw_dirhistmax
3690 endif
3691 endwhile
3692 exe "sil! w! ".savefile
3693" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3694 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003697 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 " merge and write .netrwbook
3701 let savefile= s:NetrwHome()."/.netrwbook"
3702
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003703 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003705 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 for bdm in booklist
3707 if index(g:netrw_bookmarklist,bdm) == -1
3708 call add(g:netrw_bookmarklist,bdm)
3709 endif
3710 endfor
3711 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 endif
3713
3714 " construct and save .netrwbook
3715 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003716 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003719
3720 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003721 let bgone= bufnr("%")
3722 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003723 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724
3725" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003726endfun
3727
3728" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003729" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3730" list of the contents of a local or remote directory. It is assumed that the
3731" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3732" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003733" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003734fun! s:NetrwBrowse(islocal,dirname)
3735 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003736" 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 +02003737" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3738" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3739" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003740
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003741 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3742 " This is useful when one edits a local file, then :e ., then :Rex
3743 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3744 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003745" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003747
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003748 " s:NetrwBrowse : initialize history {{{3
3749 if !exists("s:netrw_initbookhist")
3750 NetrwKeepj call s:NetrwBookHistRead()
3751 endif
3752
3753 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003754 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003756" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 else
3758 let dirname= a:dirname
3759 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003760
Bram Moolenaar85850f32019-07-19 22:05:51 +02003761 " repoint t:netrw_lexbufnr if appropriate
3762 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3763" call Decho("set repointlexbufnr to true!")
3764 let repointlexbufnr= 1
3765 endif
3766
3767 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003768 if exists("s:netrw_skipbrowse")
3769 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003770" 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 +01003771" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772 return
3773 endif
3774 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003775 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776" call Dret("s:NetrwBrowse : missing shellescape()")
3777 return
3778 endif
3779 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003780 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781" call Dret("s:NetrwBrowse : missing fnameescape()")
3782 return
3783 endif
3784
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003785 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003787
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003788 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003789 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3790 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3791" call Decho("clearing marked files",'~'.expand("<slnum>"))
3792 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003794 endif
3795
3796 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003797 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003798" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3799" 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 +02003800 if s:NetrwLcd(dirname)
3801" call Dret("s:NetrwBrowse : lcd failure")
3802 return
3803 endif
3804 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003805" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003808 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003809" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003810 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003811" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003812 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003813 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003814 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003815" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003816
3817 " remove any filetype indicator from end of dirname, except for the
3818 " "this is a directory" indicator (/).
3819 " There shouldn't be one of those here, anyway.
3820 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003821" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 call s:RemotePathAnalysis(dirname)
3823
3824 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3825 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003826 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003828" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 let b:netrw_curdir = dirname
3830 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003831 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3833 sil call netrw#NetRead(2,url)
3834 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003835" call Decho("url<".url.">",'~'.expand("<slnum>"))
3836" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3837" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003838 if s:path =~ '.bz2'
3839 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3840 elseif s:path =~ '.gz'
3841 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3842 elseif s:path =~ '.gz'
3843 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3844 else
3845 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3846 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847 endif
3848
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003849 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003850 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003851 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003853 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" 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 +00003855
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856" call Dret("s:NetrwBrowse : file<".s:fname.">")
3857 return
3858 endif
3859
Bram Moolenaaradc21822011-04-01 18:03:16 +02003860 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861 call s:UseBufWinVars()
3862
3863 " set up some variables {{{3
3864 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003865 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866 let s:last_sort_by = g:netrw_sort_by
3867
3868 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870
Bram Moolenaar97d62492012-11-15 21:28:22 +01003871 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003873 let svpos = winsaveview()
3874" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003875 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876
Bram Moolenaar446cb832008-06-24 21:56:24 +00003877 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003878 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3879 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3880" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3881" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3882 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3883 else
3884" " call Decho("2match none",'~'.expand("<slnum>"))
3885 2match none
3886 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003887 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003888 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003889 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003891 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892" 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 +01003893" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 return
3895 endif
3896
3897 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003899 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003900 if b:netrw_curdir =~ '[/\\]$'
3901 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3902 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003903 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3904 let b:netrw_curdir= b:netrw_curdir."/"
3905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 if b:netrw_curdir == ''
3907 if has("amiga")
3908 " On the Amiga, the empty string connotes the current directory
3909 let b:netrw_curdir= getcwd()
3910 else
3911 " under unix, when the root directory is encountered, the result
3912 " from the preceding substitute is an empty string.
3913 let b:netrw_curdir= '/'
3914 endif
3915 endif
3916 if !a:islocal && b:netrw_curdir !~ '/$'
3917 let b:netrw_curdir= b:netrw_curdir.'/'
3918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920
3921 " ------------
3922 " (local only) {{{3
3923 " ------------
3924 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003925" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003926
3927 " Set up ShellCmdPost handling. Append current buffer to browselist
3928 call s:LocalFastBrowser()
3929
3930 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3931 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003932" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3933" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003935 if s:NetrwLcd(b:netrw_curdir)
3936" call Dret("s:NetrwBrowse : lcd failure")
3937 return
3938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939 endif
3940 endif
3941
3942 " --------------------------------
3943 " remote handling: {{{3
3944 " --------------------------------
3945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947
Bram Moolenaar97d62492012-11-15 21:28:22 +01003948 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" 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 +02003950 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3954 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3955 if dirname !~ '/$'
3956 let dirname= dirname.'/'
3957 endif
3958 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003959" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003961 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963 endif
3964
3965 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3966 if dirname !~ dirpat
3967 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003968 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003970 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003972 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" 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 +00003974" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3975 return
3976 endif
3977 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003979 endif " (additional remote handling)
3980
Bram Moolenaar85850f32019-07-19 22:05:51 +02003981 " -------------------------------
3982 " Perform Directory Listing: {{{3
3983 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003984 NetrwKeepj call s:NetrwMaps(a:islocal)
3985 NetrwKeepj call s:NetrwCommands(a:islocal)
3986 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003988 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003989 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003990" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3991
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992 " If there is a rexposn: restore position with rexposn
3993 " Otherwise : set rexposn
3994 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003995" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3996 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3997 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3998 NetrwKeepj exe w:netrw_bannercnt
3999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000 else
4001 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4002 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004003 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004004 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004006 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004007 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004008
Bram Moolenaar85850f32019-07-19 22:05:51 +02004009 " repoint t:netrw_lexbufnr if appropriate
4010 if exists("repointlexbufnr")
4011 let t:netrw_lexbufnr= bufnr("%")
4012" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4013 endif
4014
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015 " restore position
4016 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004017" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4018 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004019 endif
4020
Bram Moolenaara6878372014-03-22 21:02:50 +01004021 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004022 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4023 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4025" 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 +02004026" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004027 return
4028endfun
4029
4030" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4032" may not apply correctly; ie. netrw's idea of the current directory may
4033" differ from vim's. This function insures that netrw's idea of the current
4034" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004037" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4038" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4039" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4040" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4041" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042
4043 " clean up any leading treedepthstring
4044 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4045 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004046" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004047 else
4048 let fname= a:fname
4049 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050
4051 if g:netrw_keepdir
4052 " vim's idea of the current directory possibly may differ from netrw's
4053 if !exists("b:netrw_curdir")
4054 let b:netrw_curdir= getcwd()
4055 endif
4056
4057 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004058 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062 else
4063 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004064 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004065" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004066 endif
4067
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004068 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004070 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004071" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072 else
4073 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004074 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076 endif
4077 else
4078 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004079 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4081" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4082" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083 endif
4084
Bram Moolenaar85850f32019-07-19 22:05:51 +02004085" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004086 return ret
4087endfun
4088
4089" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004090" s:NetrwFileInfo: supports qf (query for file information) {{{2
4091fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004092" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004093 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004094 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004095 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004096 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004097 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004098 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004099 let lsopt= "-lsadh --si"
4100 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004101 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004102
4103 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004106
Bram Moolenaara6878372014-03-22 21:02:50 +01004107 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004110
4111 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004114
Bram Moolenaar446cb832008-06-24 21:56:24 +00004115 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004119 endif
4120 else
4121 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4123 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004124 let fname= substitute(a:fname,".$","","")
4125 else
4126 let fname= a:fname
4127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 let t = getftime(s:NetrwFile(fname))
4129 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004130 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004131 let sz= s:NetrwHumanReadable(sz)
4132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4134" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135 endif
4136 else
4137 echo "sorry, \"qf\" not supported yet for remote files"
4138 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004139 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140" call Dret("s:NetrwFileInfo")
4141endfun
4142
4143" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004144" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4145fun! s:NetrwFullPath(filename)
4146" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4147 let filename= a:filename
4148 if filename !~ '^/'
4149 let filename= resolve(getcwd().'/'.filename)
4150 endif
4151 if filename != "/" && filename =~ '/$'
4152 let filename= substitute(filename,'/$','','')
4153 endif
4154" " call Dret("s:NetrwFullPath <".filename.">")
4155 return filename
4156endfun
4157
4158" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004159" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004160" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" 1=re-used buffer (buffer not cleared)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162fun! s:NetrwGetBuffer(islocal,dirname)
4163" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" 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 +02004165" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4166" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 let dirname= a:dirname
4168
4169 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004171 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004172" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004173 let s:netrwbuf= {}
4174 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004175" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4176" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4177
4178 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4179 let bufnum = -1
4180
4181 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4182 if has_key(s:netrwbuf,"NetrwTreeListing")
4183 let bufnum= s:netrwbuf["NetrwTreeListing"]
4184 else
4185 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4186 endif
4187" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4188 if !bufexists(bufnum)
4189 call remove(s:netrwbuf,"NetrwTreeListing"])
4190 let bufnum= -1
4191 endif
4192 elseif bufnr("NetrwTreeListing") != -1
4193 let bufnum= bufnr("NetrwTreeListing")
4194" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4195 else
4196" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4197 let bufnum= -1
4198 endif
4199
4200 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004201 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004202" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004203 if !bufexists(bufnum)
4204 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4205 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004207
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004209" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004210 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004212" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4213
4214 " highjack the current buffer if
4215 " it has the desired name
4216 " it is empty
4217" call Decho("deciding if I can highjack the current buffer#".bufnr("%"),'~'.expand("<slnum>"))
4218" call Decho("..dirname<".dirname.">",'~'.expand("<slnum>"))
4219" call Decho("..bufname<".bufname("%").">",'~'.expand("<slnum>"))
4220" call Decho("..getline($)<".getline("$").">",'~'.expand("<slnum>"))
4221 if dirname == bufname("%") && line("$") == 1 && getline("%") == ""
4222" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4223 return 0
4224 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004225
4226 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004227 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004228" 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 +00004229 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004230" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004231 " name the buffer
4232 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4233 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004234" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004235 let w:netrw_treebufnr = bufnr("%")
4236 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004237 if g:netrw_use_noswf
4238 setl nobl bt=nofile noswf
4239 else
4240 setl nobl bt=nofile
4241 endif
4242 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4243 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4244 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4245 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004246" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004247 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004248 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004249 " enter the new buffer into the s:netrwbuf dictionary
4250 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4251" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4252" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004254" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255
4256 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004257" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004259 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004260 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004261" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4262 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004264" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4265 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004266 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004267" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004268 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004269 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004270 endif
4271 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004273 if line("$") <= 1 && getline(1) == ""
4274 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004275 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004276" 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>"))
4277" 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 +01004278" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4279 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004280
Bram Moolenaar97d62492012-11-15 21:28:22 +01004281 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004282" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004283 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284 sil NetrwKeepj %d _
4285" 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>"))
4286" 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 +01004287" 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 +00004288 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004289
Bram Moolenaar446cb832008-06-24 21:56:24 +00004290 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4292" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004293 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" 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>"))
4297" 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 +01004298" 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 +00004299 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004300
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004302" 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>"))
4303" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4304" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 return 1
4306 endif
4307 endif
4308
4309 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4310 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4311 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4312 " med 1 D H
4313 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004314" 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 +00004315 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004316 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004317 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318
4319 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4321" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4322 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004324" 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>"))
4325" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4326" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 return 0
4328endfun
4329
4330" ---------------------------------------------------------------------
4331" s:NetrwGetcwd: get the current directory. {{{2
4332" Change backslashes to forward slashes, if any.
4333" If doesc is true, escape certain troublesome characters
4334fun! s:NetrwGetcwd(doesc)
4335" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4336 let curdir= substitute(getcwd(),'\\','/','ge')
4337 if curdir !~ '[\/]$'
4338 let curdir= curdir.'/'
4339 endif
4340 if a:doesc
4341 let curdir= fnameescape(curdir)
4342 endif
4343" call Dret("NetrwGetcwd <".curdir.">")
4344 return curdir
4345endfun
4346
4347" ---------------------------------------------------------------------
4348" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4349fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4351" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4352 let keepsol= &l:sol
4353 setl nosol
4354
Bram Moolenaar446cb832008-06-24 21:56:24 +00004355 call s:UseBufWinVars()
4356
4357 " insure that w:netrw_liststyle is set up
4358 if !exists("w:netrw_liststyle")
4359 if exists("g:netrw_liststyle")
4360 let w:netrw_liststyle= g:netrw_liststyle
4361 else
4362 let w:netrw_liststyle= s:THINLIST
4363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 endif
4366
4367 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4368 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004369" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004370 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 let dirname= "./"
4372 let curline= getline('.')
4373
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004374 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004375 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 let s:netrw_skipbrowse= 1
4377 echo 'Pressing "s" also works'
4378
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004379 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380 let s:netrw_skipbrowse= 1
4381 echo 'Press "S" to edit sorting sequence'
4382
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004383 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004384 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004387 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004388 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 let s:netrw_skipbrowse= 1
4390 echo 'Pressing "a" also works'
4391
4392 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004393 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 endif
4395
4396 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004397" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004398 NetrwKeepj norm! 0
4399 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400
4401 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004402" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004403 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4405
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004406 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004407" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004408 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004409 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004410
4411 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004412" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004413 let dirname= getline('.')
4414
4415 if !exists("b:netrw_cpf")
4416 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004417 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 +01004418 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 endif
4421
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004422" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4425" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004427 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 else
4429 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004430 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 endif
4432 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004433 let eofname= filestart + b:netrw_cpf + 1
4434 if eofname <= col("$")
4435 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004436 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004437 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004438 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004439 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let dirname = @a
4441 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004442" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004444" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 endif
4446
4447 " symlinks are indicated by a trailing "@". Remove it before further processing.
4448 let dirname= substitute(dirname,"@$","","")
4449
4450 " executables are indicated by a trailing "*". Remove it before further processing.
4451 let dirname= substitute(dirname,"\*$","","")
4452
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004453 let &l:sol= keepsol
4454
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455" call Dret("s:NetrwGetWord <".dirname.">")
4456 return dirname
4457endfun
4458
4459" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004460" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4461" g:netrw_bufsettings will be used after the listing is produced.
4462" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463fun! s:NetrwListSettings(islocal)
4464" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" 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 +00004466 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004467" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4468 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4469 setl bt=nofile nobl ma nonu nowrap noro nornu
4470 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004472 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004474" call Dredir("ls!","s:NetrwListSettings")
4475" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004476 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004477 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004479 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004481 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" 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 +00004484" call Dret("s:NetrwListSettings")
4485endfun
4486
4487" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004488" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489" islocal=0: remote browsing
4490" =1: local browsing
4491fun! s:NetrwListStyle(islocal)
4492" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004493
Bram Moolenaar97d62492012-11-15 21:28:22 +01004494 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 let fname = s:NetrwGetWord()
4496 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004497 let svpos = winsaveview()
4498" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004500" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4501" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4502" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004503
Bram Moolenaar85850f32019-07-19 22:05:51 +02004504 " repoint t:netrw_lexbufnr if appropriate
4505 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4506" call Decho("set repointlexbufnr to true!")
4507 let repointlexbufnr= 1
4508 endif
4509
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 if w:netrw_liststyle == s:THINLIST
4511 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("use one column 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 elseif w:netrw_liststyle == s:LONGLIST
4516 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004517" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4519
4520 elseif w:netrw_liststyle == s:WIDELIST
4521 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4524
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004525 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4528
4529 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004530 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531 let g:netrw_liststyle = s:THINLIST
4532 let w:netrw_liststyle = g:netrw_liststyle
4533 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4534 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004535 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004536" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537
4538 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004539" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4540 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004541 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004542" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004543 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004544" 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 +00004545
4546 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004547" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004548 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4549 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550
Bram Moolenaar85850f32019-07-19 22:05:51 +02004551 " repoint t:netrw_lexbufnr if appropriate
4552 if exists("repointlexbufnr")
4553 let t:netrw_lexbufnr= bufnr("%")
4554" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4555 endif
4556
Bram Moolenaar13600302014-05-22 18:26:40 +02004557 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004558" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4559 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004560 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561
4562" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4563endfun
4564
4565" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004566" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4567fun! s:NetrwBannerCtrl(islocal)
4568" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4569
Bram Moolenaar97d62492012-11-15 21:28:22 +01004570 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004571 " toggle the banner (enable/suppress)
4572 let g:netrw_banner= !g:netrw_banner
4573
4574 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004575 let svpos= winsaveview()
4576" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004577 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4578
4579 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004580 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4581 let fname= s:NetrwGetWord()
4582 sil NetrwKeepj $
4583 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4584" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4585 if result <= 0 && exists("w:netrw_bannercnt")
4586 exe "NetrwKeepj ".w:netrw_bannercnt
4587 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004588 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004589 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004590" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4591endfun
4592
4593" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004594" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4595"
4596" No bang: enters files/directories into Netrw's bookmark system
4597" No argument and in netrw buffer:
4598" if there are marked files: bookmark marked files
4599" otherwise : bookmark file/directory under cursor
4600" No argument and not in netrw buffer: bookmarks current open file
4601" Has arguments: globs them individually and bookmarks them
4602"
4603" With bang: deletes files/directories from Netrw's bookmark system
4604fun! s:NetrwBookmark(del,...)
4605" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4606 if a:0 == 0
4607 if &ft == "netrw"
4608 let curbufnr = bufnr("%")
4609
4610 if exists("s:netrwmarkfilelist_{curbufnr}")
4611 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004613 let svpos = winsaveview()
4614" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004616 for fname in s:netrwmarkfilelist_{curbufnr}
4617 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4618 endfor
4619 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4620 call s:NetrwUnmarkList(curbufnr,curdir)
4621 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004622" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4623 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004624 else
4625 let fname= s:NetrwGetWord()
4626 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4627 endif
4628
4629 else
4630 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004631" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004632 let fname= expand("%")
4633 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4634 endif
4635
4636 else
4637 " bookmark specified files
4638 " attempts to infer if working remote or local
4639 " by deciding if the current file begins with an url
4640 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004641 let islocal= expand("%") !~ '^\a\{3,}://'
4642" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004643 let i = 1
4644 while i <= a:0
4645 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004646 if v:version > 704 || (v:version == 704 && has("patch656"))
4647 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004648 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004649 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004650 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004651 else
4652 let mbfiles= [a:{i}]
4653 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004654" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004656" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004657 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4658 endfor
4659 let i= i + 1
4660 endwhile
4661 endif
4662
4663 " update the menu
4664 call s:NetrwBookmarkMenu()
4665
4666" call Dret("s:NetrwBookmark")
4667endfun
4668
4669" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004670" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4671" .2.[cnt] for bookmarks, and
4672" .3.[cnt] for history
4673" (see s:NetrwMenu())
4674fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004675 if !exists("s:netrw_menucnt")
4676 return
4677 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004678" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004679
4680 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004681 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004682 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004683" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004684 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4685 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004686 endif
4687 if !exists("s:netrw_initbookhist")
4688 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004689 endif
4690
4691 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004692 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004693 let cnt= 1
4694 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004695" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004696 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004697
4698 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004699 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004700
4701 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004702 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 +01004703 let cnt= cnt + 1
4704 endfor
4705
4706 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004707
4708 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004709 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004710 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004711 let first = 1
4712 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004713 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004714 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004715 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004716 if exists("g:netrw_dirhist_{cnt}")
4717 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004719 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4720 endif
4721 let first = 0
4722 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4723 if cnt < 0
4724 let cnt= cnt + g:netrw_dirhistmax
4725 endif
4726 endwhile
4727 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004728
Bram Moolenaar9964e462007-05-05 17:54:07 +00004729 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004731endfun
4732
4733" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004734" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4735" directory and a new directory name. Also, if the
4736" "new directory name" is actually a file,
4737" NetrwBrowseChgDir() edits the file.
4738fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4739" 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 +01004740" 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 +00004741
Bram Moolenaar97d62492012-11-15 21:28:22 +01004742 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004743 if !exists("b:netrw_curdir")
4744 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4745 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004746 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004747" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4748" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004749" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004750" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004751 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004753" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754
Bram Moolenaar97d62492012-11-15 21:28:22 +01004755 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004756" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004757 call s:SavePosn(s:netrw_posn)
4758 NetrwKeepj call s:NetrwOptionsSave("s:")
4759 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004760 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004761 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004762 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004763 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004764 endif
4765 let newdir = a:newdir
4766 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004767 let dorestore = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004768" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004769" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004770
4771 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004772" 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 +01004773 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004774" 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 +01004775 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004776 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004777" 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 +01004778 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004779" 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 +02004780 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004781 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004782 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" 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 +01004785 endif
4786 endif
4787" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004788" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004789 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004790
Bram Moolenaar446cb832008-06-24 21:56:24 +00004791 " set up o/s-dependent directory recognition pattern
4792 if has("amiga")
4793 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004794 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795 let dirpat= '[\/]$'
4796 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004797" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004798
4799 if dirname !~ dirpat
4800 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004801 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004802 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004803" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804 endif
4805
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004806" 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 +01004807 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 " ------------------------------
4809 " NetrwBrowseChgDir: edit a file {{{3
4810 " ------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004811" call Decho('(s:NetrwBrowseChgDir) edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004812
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004814 let s:rexposn_{bufnr("%")}= winsaveview()
4815" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004816" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4817" 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 +01004818
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004820" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4821" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004822 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4824" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4825 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004826 if dirname =~ '/$'
4827 let dirname= dirname.newdir
4828 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004829 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004830 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4832" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004833 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004834" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004835 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004836 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004837 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004838 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004839" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004840 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004841 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004842" 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 +02004843 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004844 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004845 if !exists("s:didsplit")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004846" 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 +01004847 if type(g:netrw_browse_split) == 3
4848 " open file in server
4849 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004851 call s:NetrwServerEdit(a:islocal,dirname)
4852" call Dret("s:NetrwBrowseChgDir")
4853 return
4854 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004855 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004857 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004858 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004859 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004860 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004861 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004863 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004865 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004866 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004867 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004868 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004869 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004871 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004873 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004874 if !exists("b:netrw_curdir")
4875 let b:netrw_curdir= getcwd()
4876 endif
4877 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004882 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004884 return
4885 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004886 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004887 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004888 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004889" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 call s:NetrwMenu(0)
4891 " optional change to window
4892 if g:netrw_chgwin >= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004893" call Decho("edit-a-file: changing window to #".g:netrw_chgwin,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004894 if winnr("$")+1 == g:netrw_chgwin
4895 " if g:netrw_chgwin is set to one more than the last window, then
4896 " vertically split the last window to make that window available.
4897 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004898 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004899 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004900 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004901 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004902 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004903 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004904 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004905 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004906 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004907
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 " the point where netrw actually edits the (local) file
4909 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004910 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004912" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004913 " some like c-^ to return to the last edited file
4914 " others like c-^ to return to the netrw buffer
4915 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004916 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004917 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004918 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004919 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004920" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004921 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004922 if &hidden || &bufhidden == "hide"
4923 " file came from vim's hidden storage. Don't "restore" options with it.
4924 let dorestore= 0
4925 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004926 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004928 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930
4931 " handle g:Netrw_funcref -- call external-to-netrw functions
4932 " This code will handle g:Netrw_funcref as an individual function reference
4933 " or as a list of function references. It will ignore anything that's not
4934 " a function reference. See :help Funcref for information about function references.
4935 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004936" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004938" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004939 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004942 for Fncref in g:Netrw_funcref
4943 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004944 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004945 endif
4946 endfor
4947 endif
4948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 endif
4950
4951 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004952 " ----------------------------------------------------
4953 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4954 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004955" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004956 let dirname = newdir
4957 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004958 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004959 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960
4961 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 " ---------------------------------------------
4963 " NetrwBrowseChgDir: refresh the directory list {{{3
4964 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004965" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004966 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968
4969 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004970 " --------------------------------------
4971 " NetrwBrowseChgDir: go up one directory {{{3
4972 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004973" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004974
4975 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4976 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004977" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4978" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004979 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004980 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 endif
4982
4983 if has("amiga")
4984 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004985" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004986 if a:islocal
4987 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4988 let dirname= substitute(dirname,'/$','','')
4989 else
4990 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993
Bram Moolenaar8d043172014-01-23 14:24:41 +01004994 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4995 " windows
4996 if a:islocal
4997 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4998 if dirname == ""
4999 let dirname= '/'
5000 endif
5001 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005002 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005003 endif
5004 if dirname =~ '^\a:$'
5005 let dirname= dirname.'/'
5006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005007" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005008
Bram Moolenaar446cb832008-06-24 21:56:24 +00005009 else
5010 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005011" 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 +00005012 if a:islocal
5013 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5014 if dirname == ""
5015 let dirname= '/'
5016 endif
5017 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005018 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005019 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005021 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005022 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005023 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005024
5025 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005026 " --------------------------------------
5027 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5028 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005029" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5031" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005032 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005034" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5035 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005037 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005039 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005040 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042
5043 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005044" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005046" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047 let haskey= 1
5048 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005049" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005050 endif
5051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005053" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055 if has_key(w:netrw_treedict,treedir."/")
5056 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005057" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005058 let haskey = 1
5059 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061 endif
5062 endif
5063
5064 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005065" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066 if !haskey && treedir =~ '/$'
5067 let treedir= substitute(treedir,'/$','','')
5068 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005069" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070 let haskey = 1
5071 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005072" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 endif
5074 endif
5075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077 if haskey
5078 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005081" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5082" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005083 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084 else
5085 " go down one directory
5086 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5088" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005089 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005090 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005092 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005093
5094 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005095 " ----------------------------------------
5096 " NetrwBrowseChgDir: Go down one directory {{{3
5097 " ----------------------------------------
5098 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005100 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005101 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005102 endif
5103
Bram Moolenaar97d62492012-11-15 21:28:22 +01005104 " --------------------------------------
5105 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5106 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005107 if dorestore
5108 " dorestore is zero'd when a local file was hidden or bufhidden;
5109 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005111 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005112" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005114 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005115 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005117 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5119" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005120 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" 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 +02005122 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5124" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005125 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005126" 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 +02005127 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005128 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005129 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005130 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005131
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5133 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005134endfun
5135
5136" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005137" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5138" for thin, long, and wide: cursor placed just after banner
5139" for tree, keeps cursor on current filename
5140fun! s:NetrwBrowseUpDir(islocal)
5141" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005142 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5143 " this test needed because occasionally this function seems to be incorrectly called
5144 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005146 " directories.
5147" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5148 return
5149 endif
5150
Bram Moolenaara6878372014-03-22 21:02:50 +01005151 norm! 0
5152 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005153" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005154 let curline= getline(".")
5155 let swwline= winline() - 1
5156 if exists("w:netrw_treetop")
5157 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005158 elseif exists("b:netrw_curdir")
5159 let w:netrw_treetop= b:netrw_curdir
5160 else
5161 let w:netrw_treetop= getcwd()
5162 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005163 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005164 let curfile = getline(".")
5165 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005166 if a:islocal
5167 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5168 else
5169 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5170 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005171" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5172" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5173 if w:netrw_treetop == '/'
5174 keepj call search('^\M'.curfile,"w")
5175 elseif curfile == '../'
5176 keepj call search('^\M'.curfile,"wb")
5177 else
5178" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5179 while 1
5180 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5181 let treepath= s:NetrwTreePath(w:netrw_treetop)
5182" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5183 if treepath == curpath
5184 break
5185 endif
5186 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005187 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188
Bram Moolenaara6878372014-03-22 21:02:50 +01005189 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005191 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192 if exists("b:netrw_curdir")
5193 let curdir= b:netrw_curdir
5194 else
5195 let curdir= expand(getcwd())
5196 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005197 if a:islocal
5198 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5199 else
5200 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5201 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005202 call s:RestorePosn(s:netrw_posn)
5203 let curdir= substitute(curdir,'^.*[\/]','','')
5204 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005205 endif
5206" call Dret("s:NetrwBrowseUpDir")
5207endfun
5208
5209" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005210" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005211" given filename; typically this means given their extension.
5212" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005213fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005214 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005215" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005216
Bram Moolenaar91359012019-11-30 17:57:03 +01005217 if a:remote == 0 && isdirectory(a:fname)
5218 " if its really just a local directory, then do a "gf" instead
5219" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
5220" call Decho("..appears to be a local directory; using gf instead",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005221 norm! gf
Bram Moolenaar91359012019-11-30 17:57:03 +01005222" call Dret("netrw#BrowseX")
5223 return
5224 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5225 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5226" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5227" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5228" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5229" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5230 norm! gf
5231" call Dret("netrw#BrowseX")
5232 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005233 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005234" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005235
Bram Moolenaar97d62492012-11-15 21:28:22 +01005236 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005237 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005238" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005239
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005240 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5241 let awkeep = &aw
5242 set noaw
5243
Bram Moolenaar5c736222010-01-06 20:54:52 +01005244 " special core dump handler
5245 if a:fname =~ '/core\(\.\d\+\)\=$'
5246 if exists("g:Netrw_corehandler")
5247 if type(g:Netrw_corehandler) == 2
5248 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005249" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005250 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005251 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005252 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005253" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005254 for Fncref in g:Netrw_corehandler
5255 if type(FncRef) == 2
5256 call FncRef(a:fname)
5257 endif
5258 endfor
5259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005260" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005261 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005262 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005263 let &aw= awkeep
5264" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005265 return
5266 endif
5267 endif
5268
Bram Moolenaar446cb832008-06-24 21:56:24 +00005269 " set up the filename
5270 " (lower case the extension, make a local copy of a remote file)
5271 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5272 if has("win32") || has("win95") || has("win64") || has("win16")
5273 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005274 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275 if exten =~ "[\\/]"
5276 let exten= ""
5277 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005278" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005279
Bram Moolenaar446cb832008-06-24 21:56:24 +00005280 if a:remote == 1
5281 " create a local copy
Bram Moolenaar46973992017-12-14 19:56:46 +01005282" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005283 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005284 call netrw#NetRead(3,a:fname)
5285 " attempt to rename tempfile
5286 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005287 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005288" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5289" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005290 if s:netrw_tmpfile != newname && newname != ""
5291 if rename(s:netrw_tmpfile,newname) == 0
5292 " renaming succeeded
5293" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5294 let fname= newname
5295 else
5296 " renaming failed
5297" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5298 let fname= s:netrw_tmpfile
5299 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005300 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005301 let fname= s:netrw_tmpfile
5302 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005303 else
Bram Moolenaar46973992017-12-14 19:56:46 +01005304" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005305 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005306 " special ~ handler for local
5307 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005308" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5309 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005310 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005311 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005312" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5313" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005314
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005315 " set up redirection (avoids browser messages)
5316 " by default, g:netrw_suppress_gx_mesg is true
5317 if g:netrw_suppress_gx_mesg
5318 if &srr =~ "%s"
5319 if (has("win32") || has("win95") || has("win64") || has("win16"))
5320 let redir= substitute(&srr,"%s","nul","")
5321 else
5322 let redir= substitute(&srr,"%s","/dev/null","")
5323 endif
5324 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5325 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005326 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005327 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005328 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005329 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005330" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005331
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005332 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005333 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005334" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005335 if g:netrw_browsex_viewer =~ '\s'
5336 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5337 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5338 let oviewer = ''
5339 let cnt = 1
5340 while !executable(viewer) && viewer != oviewer
5341 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5342 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5343 let cnt = cnt + 1
5344 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005345" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005346 endwhile
5347 else
5348 let viewer = g:netrw_browsex_viewer
5349 let viewopt = ""
5350 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005351" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005352 endif
5353
5354 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005355" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005357" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005358 let ret= netrwFileHandlers#Invoke(exten,fname)
5359
5360 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005361" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005362 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005363 let ret= v:shell_error
5364
5365 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005366" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005367 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005368 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005369 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005370 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371 else
5372 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5373 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005374 let ret= v:shell_error
5375
Bram Moolenaar97d62492012-11-15 21:28:22 +01005376 elseif has("win32unix")
5377 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005378" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005379 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005380" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005381 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005382 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005383" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005384 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005385 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005386" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005387 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005388 else
5389 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5390 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005391 let ret= v:shell_error
5392
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005393 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005394" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005395 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396 let ret= v:shell_error
5397
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005398 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005399" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005400 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir)
5401 let ret= v:shell_error
5402
Bram Moolenaar85850f32019-07-19 22:05:51 +02005403 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005404" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5405 if a:fname =~ '^https\=://'
5406 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5407 let use_ctrlo= 0
5408" call Decho("(COMBAK) fname<".fname.">")
5409" call Decho("(COMBAK) a:fname<".a:fname.">")
5410 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5411
5412 else
5413 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5414 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005415 let ret= v:shell_error
5416
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005417 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005418" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005419 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420 let ret= v:shell_error
5421
5422 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005423" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005424 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005425 let ret= v:shell_error
5426
5427 else
5428 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005429" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430 let ret= netrwFileHandlers#Invoke(exten,fname)
5431 endif
5432
5433 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5434 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005435" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 let ret= netrwFileHandlers#Invoke(exten,fname)
5437 endif
5438
Bram Moolenaarc236c162008-07-13 17:41:49 +00005439 " restoring redraw! after external file handlers
5440 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441
5442 " cleanup: remove temporary file,
5443 " delete current buffer if success with handler,
5444 " return to prior buffer (directory listing)
5445 " Feb 12, 2008: had to de-activiate removal of
5446 " temporary file because it wasn't getting seen.
5447" if a:remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005448"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005449" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450" endif
5451
5452 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005453 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005455 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005457 if use_ctrlo
5458 exe "sil! NetrwKeepj norm! \<c-o>"
5459 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005461" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005462 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005463 let @@ = ykeep
5464 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005466" call Dret("netrw#BrowseX")
5467endfun
5468
5469" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005470" netrw#GX: gets word under cursor for gx support {{{2
5471" See also: netrw#BrowseXVis
5472" netrw#BrowseX
5473fun! netrw#GX()
5474" call Dfunc("netrw#GX()")
5475 if &ft == "netrw"
5476 let fname= s:NetrwGetWord()
5477 else
5478 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5479 endif
5480" call Dret("netrw#GX <".fname.">")
5481 return fname
5482endfun
5483
5484" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005485" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5486fun! netrw#BrowseXVis()
5487" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005488 let akeep = @a
5489 norm! gv"ay
5490 let gxfile= @a
5491 let @a = akeep
5492 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005493" call Dret("netrw#BrowseXVis")
5494endfun
5495
5496" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005497" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5498" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5499" to become an unlisted buffer, so in that case don't bwipe it.
5500fun! s:NetrwBufRename(newname)
5501" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5502" call Dredir("ls!","s:NetrwBufRename (before rename)")
5503 let oldbufname= bufname(bufnr("%"))
5504" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5505
5506 if oldbufname != a:newname
5507" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5508 let b:junk= 1
5509" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5510 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
5511" call Dredir("ls!","s:NetrwBufRename (before bwipe)")
5512 let oldbufnr= bufnr(oldbufname)
5513" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5514" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5515 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5516" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5517 exe "bwipe! ".oldbufnr
5518" else " Decho
5519" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
5520 endif
5521" call Dredir("ls!","s:NetrwBufRename (after rename)")
5522" else " Decho
5523" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5524 endif
5525
5526" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5527endfun
5528
5529" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005530" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005531fun! netrw#CheckIfRemote(...)
5532" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5533 if a:0 > 0
5534 let curfile= a:1
5535 else
5536 let curfile= expand("%")
5537 endif
5538" call Decho("curfile<".curfile.">")
5539 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005540" call Dret("netrw#CheckIfRemote 1")
5541 return 1
5542 else
5543" call Dret("netrw#CheckIfRemote 0")
5544 return 0
5545 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005546endfun
5547
5548" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005549" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5550fun! s:NetrwChgPerm(islocal,curdir)
5551" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005552 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005553 call inputsave()
5554 let newperm= input("Enter new permission: ")
5555 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005556 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5557 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5558" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005559 call system(chgperm)
5560 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005561 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005562 endif
5563 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005564 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005565 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005566 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005567" call Dret("s:NetrwChgPerm")
5568endfun
5569
5570" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005571" s:CheckIfKde: checks if kdeinit is running {{{2
5572" Returns 0: kdeinit not running
5573" 1: kdeinit is running
5574fun! s:CheckIfKde()
5575" call Dfunc("s:CheckIfKde()")
5576 " seems kde systems often have gnome-open due to dependencies, even though
5577 " gnome-open's subsidiary display tools are largely absent. Kde systems
5578 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5579 if !exists("s:haskdeinit")
5580 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005581 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005582 if v:shell_error
5583 let s:haskdeinit = 0
5584 endif
5585 else
5586 let s:haskdeinit= 0
5587 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005588" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005589 endif
5590
5591" call Dret("s:CheckIfKde ".s:haskdeinit)
5592 return s:haskdeinit
5593endfun
5594
5595" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005596" s:NetrwClearExplore: clear explore variables (if any) {{{2
5597fun! s:NetrwClearExplore()
5598" call Dfunc("s:NetrwClearExplore()")
5599 2match none
5600 if exists("s:explore_match") |unlet s:explore_match |endif
5601 if exists("s:explore_indx") |unlet s:explore_indx |endif
5602 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5603 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5604 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5605 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5606 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5607 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5608 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5609" redraw!
5610 echo " "
5611 echo " "
5612" call Dret("s:NetrwClearExplore")
5613endfun
5614
5615" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005616" s:NetrwExploreListUniq: {{{2
5617fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005618" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005619
5620 " this assumes that the list is already sorted
5621 let newexplist= []
5622 for member in a:explist
5623 if !exists("uniqmember") || member != uniqmember
5624 let uniqmember = member
5625 let newexplist = newexplist + [ member ]
5626 endif
5627 endfor
5628
Bram Moolenaar15146672011-10-20 22:22:38 +02005629" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005630 return newexplist
5631endfun
5632
5633" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005634" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5635fun! s:NetrwForceChgDir(islocal,newdir)
5636" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005637 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005638 if a:newdir !~ '/$'
5639 " ok, looks like force is needed to get directory-style treatment
5640 if a:newdir =~ '@$'
5641 let newdir= substitute(a:newdir,'@$','/','')
5642 elseif a:newdir =~ '[*=|\\]$'
5643 let newdir= substitute(a:newdir,'.$','/','')
5644 else
5645 let newdir= a:newdir.'/'
5646 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005647" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005648 else
5649 " should already be getting treatment as a directory
5650 let newdir= a:newdir
5651 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005652 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005653 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005654 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005655" call Dret("s:NetrwForceChgDir")
5656endfun
5657
5658" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005659" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005660" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5661" expr : this is the expression to follow the directory. Will use s:ComposePath()
5662" pare =1: remove the current directory from the resulting glob() filelist
5663" =0: leave the current directory in the resulting glob() filelist
5664fun! s:NetrwGlob(direntry,expr,pare)
5665" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005666 if netrw#CheckIfRemote()
5667 keepalt 1sp
5668 keepalt enew
5669 let keep_liststyle = w:netrw_liststyle
5670 let w:netrw_liststyle = s:THINLIST
5671 if s:NetrwRemoteListing() == 0
5672 keepj keepalt %s@/@@
5673 let filelist= getline(1,$)
5674 q!
5675 else
5676 " remote listing error -- leave treedict unchanged
5677 let filelist= w:netrw_treedict[a:direntry]
5678 endif
5679 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005680 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5681 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5682 if a:pare
5683 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5684 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005685 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005686 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5687 if a:pare
5688 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5689 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005690 endif
5691" call Dret("s:NetrwGlob ".string(filelist))
5692 return filelist
5693endfun
5694
5695" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005696" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5697fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005698" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005699 if a:newfile =~ '[/@*=|\\]$'
5700 let newfile= substitute(a:newfile,'.$','','')
5701 else
5702 let newfile= a:newfile
5703 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005704 if a:islocal
5705 call s:NetrwBrowseChgDir(a:islocal,newfile)
5706 else
5707 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5708 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005709" call Dret("s:NetrwForceFile")
5710endfun
5711
5712" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005713" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5714" and switches the hiding mode. The actual hiding is done by
5715" s:NetrwListHide().
5716" g:netrw_hide= 0: show all
5717" 1: show not-hidden files
5718" 2: show hidden files only
5719fun! s:NetrwHide(islocal)
5720" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005721 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005722 let svpos= winsaveview()
5723" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005724
5725 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005726" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5727" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005728
5729 " hide the files in the markfile list
5730 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005731" 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 +00005732 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5733 " remove fname from hiding list
5734 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5735 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5736 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005737" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005738 else
5739 " append fname to hiding list
5740 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5741 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5742 else
5743 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5744 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005745" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005746 endif
5747 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005748 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005749 let g:netrw_hide= 1
5750
5751 else
5752
5753 " switch between show-all/show-not-hidden/show-hidden
5754 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005755 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005756 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005757 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005758 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005759" call Dret("NetrwHide")
5760 return
5761 endif
5762 endif
5763
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005764 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005765" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5766 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005767 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005768" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005769endfun
5770
5771" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005772" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5773fun! s:NetrwHideEdit(islocal)
5774" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5775
5776 let ykeep= @@
5777 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005778 let svpos= winsaveview()
5779" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005780
5781 " get new hiding list from user
5782 call inputsave()
5783 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5784 call inputrestore()
5785 let g:netrw_list_hide= newhide
5786" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5787
5788 " refresh the listing
5789 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5790
5791 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005792" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5793 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005794 let @@= ykeep
5795
5796" call Dret("NetrwHideEdit")
5797endfun
5798
5799" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005800" s:NetrwHidden: invoked by "gh" {{{2
5801fun! s:NetrwHidden(islocal)
5802" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005803 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005805 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005806" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005807
5808 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005809 " remove .file pattern from hiding list
5810" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005811 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005812 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005813" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005814 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5815 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005816" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005817 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5818 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005819 if g:netrw_list_hide =~ '^,'
5820 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5821 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005822
5823 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005824 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005825" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5826 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005827 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005828" call Dret("s:NetrwHidden")
5829endfun
5830
5831" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005832" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5833fun! s:NetrwHome()
5834 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005835 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005836 else
5837 " go to vim plugin home
5838 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005839 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005840 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005841 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005842 let home= basehome."/.vim"
5843 break
5844 endif
5845 endfor
5846 if home == ""
5847 " just pick the first directory
5848 let home= substitute(&rtp,',.*$','','')
5849 endif
5850 if (has("win32") || has("win95") || has("win64") || has("win16"))
5851 let home= substitute(home,'/','\\','g')
5852 endif
5853 endif
5854 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005855 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005856" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005857 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005858" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005859 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005860 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005861" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005862 call mkdir(home)
5863 endif
5864 endif
5865 let g:netrw_home= home
5866 return home
5867endfun
5868
5869" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5871fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005872 if exists("s:netrwdrag")
5873 return
5874 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005875 if &ft != "netrw"
5876 return
5877 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005878" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005879
Bram Moolenaar97d62492012-11-15 21:28:22 +01005880 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005881 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005882 while getchar(0) != 0
5883 "clear the input stream
5884 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005885 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005886 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005887 let mouse_lnum = v:mouse_lnum
5888 let wlastline = line('w$')
5889 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005890" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5891" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005892 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5893 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005894 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005895" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5896 return
5897 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005898 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005899 " 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 +01005900 " without this test when its disabled.
5901 " 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 +01005902" 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 +01005903 if v:mouse_col > virtcol('.')
5904 let @@= ykeep
5905" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5906 return
5907 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005908
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 if a:islocal
5910 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005911 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005912 endif
5913 else
5914 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005915 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005916 endif
5917 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005918 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919" call Dret("s:NetrwLeftmouse")
5920endfun
5921
5922" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005923" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5924fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005925 if &ft != "netrw"
5926 return
5927 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005928" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5929 call s:NetrwMarkFileTgt(a:islocal)
5930" call Dret("s:NetrwCLeftmouse")
5931endfun
5932
5933" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005934" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5935" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005937" a:islocal=2 : <c-r> used, remote
5938" a:islocal=3 : <c-r> used, local
5939fun! s:NetrwServerEdit(islocal,fname)
5940" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5941 let islocal = a:islocal%2 " =0: remote =1: local
5942 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005943" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005944
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005945 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005946 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005947 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005948" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005949 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005950 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5952 unlet s:netrw_browse_split_{winnr()}
5953 endif
5954 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5955" call Dret("s:NetrwServerEdit")
5956 return
5957 endif
5958
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005959" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005960 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005961" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005962
5963 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005964" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005965 let srvrname = g:netrw_browse_split[0]
5966 let tabnum = g:netrw_browse_split[1]
5967 let winnum = g:netrw_browse_split[2]
5968
5969 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005970" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005971
5972 if !ctrlr
5973 " user must have closed the server window and the user did not use <c-r>, but
5974 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005975" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005976 if exists("g:netrw_browse_split")
5977 unlet g:netrw_browse_split
5978 endif
5979 let g:netrw_browse_split= 0
5980 if exists("s:netrw_browse_split_".winnr())
5981 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5982 endif
5983 call s:NetrwBrowseChgDir(islocal,a:fname)
5984" call Dret("s:NetrwServerEdit")
5985 return
5986
5987 elseif has("win32") && executable("start")
5988 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005989" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005990 call system("start gvim --servername ".srvrname)
5991
5992 else
5993 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005994" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005995 call system("gvim --servername ".srvrname)
5996 endif
5997 endif
5998
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005999" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006000 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6001 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006002 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003
6004 else
6005
6006 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6007
6008 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006009" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006010 if exists("g:netrw_browse_split")
6011 unlet g:netrw_browse_split
6012 endif
6013 let g:netrw_browse_split= 0
6014 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6015" call Dret("s:NetrwServerEdit")
6016 return
6017
6018 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006020 if has("win32") && executable("start")
6021 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006022" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006023 call system("start gvim --servername ".g:netrw_servername)
6024 else
6025 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006026" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006027 call system("gvim --servername ".g:netrw_servername)
6028 endif
6029 endif
6030 endif
6031
6032 while 1
6033 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006034" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6035 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006036 break
6037 catch /^Vim\%((\a\+)\)\=:E241/
6038 sleep 200m
6039 endtry
6040 endwhile
6041
6042 if exists("g:netrw_browse_split")
6043 if type(g:netrw_browse_split) != 3
6044 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6045 endif
6046 unlet g:netrw_browse_split
6047 endif
6048 let g:netrw_browse_split= [g:netrw_servername,1,1]
6049 endif
6050
6051 else
6052 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6053 endif
6054
6055" call Dret("s:NetrwServerEdit")
6056endfun
6057
6058" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006059" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6060fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006061 if &ft != "netrw"
6062 return
6063 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006064" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006065
Bram Moolenaar8d043172014-01-23 14:24:41 +01006066 let s:ngw= s:NetrwGetWord()
6067 call s:NetrwMarkFile(a:islocal,s:ngw)
6068
6069" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006070endfun
6071
6072" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006073" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6074" Used to mark multiple files.
6075fun! s:NetrwSLeftdrag(islocal)
6076" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6077 if !exists("s:netrwdrag")
6078 let s:netrwdrag = winnr()
6079 if a:islocal
6080 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006081 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006082 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006083 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006084 endif
6085 let ngw = s:NetrwGetWord()
6086 if !exists("s:ngw") || s:ngw != ngw
6087 call s:NetrwMarkFile(a:islocal,ngw)
6088 endif
6089 let s:ngw= ngw
6090" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6091endfun
6092
6093" ---------------------------------------------------------------------
6094" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6095fun! s:NetrwSLeftrelease(islocal)
6096" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6097 if exists("s:netrwdrag")
6098 nunmap <s-leftrelease>
6099 let ngw = s:NetrwGetWord()
6100 if !exists("s:ngw") || s:ngw != ngw
6101 call s:NetrwMarkFile(a:islocal,ngw)
6102 endif
6103 if exists("s:ngw")
6104 unlet s:ngw
6105 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006106 unlet s:netrwdrag
6107 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006108" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006109endfun
6110
6111" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006112" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6113" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006114fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115" 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 +02006116" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006117 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006118
6119 " 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 +02006120 " How-it-works: take the hiding command, convert it into a range.
6121 " Duplicate characters don't matter.
6122 " Remove all such characters from the '/~@#...890' string.
6123 " Use the first character left as a separator character.
6124" call Decho("find a character not in the hide string to use as a separator")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006125 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006126 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
6127" call Decho("sep=".sep," (sep not in hide string)'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006128
6129 while listhide != ""
6130 if listhide =~ ','
6131 let hide = substitute(listhide,',.*$','','e')
6132 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6133 else
6134 let hide = listhide
6135 let listhide = ""
6136 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01006137" call Decho("..extracted from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
6138 if g:netrw_sort_by =~ '^[ts]'
6139 if hide =~ '^\^'
6140" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6141 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6142 elseif hide =~ '^\\(\^'
6143 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6144 endif
6145" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6146 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006147
6148 " Prune the list by hiding any files which match
Bram Moolenaar91359012019-11-30 17:57:03 +01006149" 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 +00006150 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006151" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006153 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006154" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006155 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006156 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006157" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006158 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006159
Bram Moolenaar446cb832008-06-24 21:56:24 +00006160 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006161 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006162" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006164" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006165 endif
6166
Bram Moolenaaradc21822011-04-01 18:03:16 +02006167 " remove any blank lines that have somehow remained.
6168 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006169 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006170
Bram Moolenaar97d62492012-11-15 21:28:22 +01006171 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006172" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006173endfun
6174
6175" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006176" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006177" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006178fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006179" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006180
Bram Moolenaar97d62492012-11-15 21:28:22 +01006181 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 " get name of new directory from user. A bare <CR> will skip.
6183 " if its currently a directory, also request will be skipped, but with
6184 " a message.
6185 call inputsave()
6186 let newdirname= input("Please give directory name: ")
6187 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006189
6190 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006191 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006192" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006193 return
6194 endif
6195
6196 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006197" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006198
6199 " Local mkdir:
6200 " sanity checks
6201 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006202" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6203 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006204 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006205 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006206 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006207 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006208" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006209 return
6210 endif
6211 if s:FileReadable(fullnewdir)
6212 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006213 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006215 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006216" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006217 return
6218 endif
6219
6220 " requested new local directory is neither a pre-existing file or
6221 " directory, so make it!
6222 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006223 if has("unix")
6224 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6225 else
6226 call mkdir(fullnewdir,"p")
6227 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006228 else
6229 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006230 if s:NetrwLcd(b:netrw_curdir)
6231" call Dret("s:NetrwMakeDir : lcd failure")
6232 return
6233 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006234" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006235 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006236 if v:shell_error != 0
6237 let @@= ykeep
6238 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 +01006239" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006240 return
6241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006242 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006243" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006244 if s:NetrwLcd(netrw_origdir)
6245" call Dret("s:NetrwBrowse : lcd failure")
6246 return
6247 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248 endif
6249 endif
6250
6251 if v:shell_error == 0
6252 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006253" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006254 let svpos= winsaveview()
6255" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006257" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6258 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006259 elseif !exists("g:netrw_quiet")
6260 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6261 endif
6262" redraw!
6263
6264 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006265 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006266" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6268 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006269 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270 if v:shell_error == 0
6271 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006272 let svpos= winsaveview()
6273" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006274 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006275" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6276 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 endif
6280" redraw!
6281
6282 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006283 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006284 let svpos= winsaveview()
6285" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006286" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006287 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006288" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006289 let remotepath= b:netrw_fname
6290 else
6291 let remotepath= ""
6292 endif
6293 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006295" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6296 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006297
Bram Moolenaar446cb832008-06-24 21:56:24 +00006298 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006299 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006300 let svpos= winsaveview()
6301" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006302" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006303 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006304" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006305 let remotepath= b:netrw_fname
6306 else
6307 let remotepath= ""
6308 endif
6309 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006310 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006311" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6312 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 endif
6314
Bram Moolenaar97d62492012-11-15 21:28:22 +01006315 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006316" call Dret("s:NetrwMakeDir")
6317endfun
6318
6319" ---------------------------------------------------------------------
6320" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6321fun! s:TreeSqueezeDir(islocal)
6322" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6323 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6324 " its a tree-listing style
6325 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006326 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006327 let depth = strchars(substitute(curdepth,' ','','g'))
6328 let srch = -1
6329" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6330" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006331" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006332" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6333 if depth >= 2
6334 NetrwKeepj norm! 0
6335 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6336 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6337" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6338" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6339 elseif depth == 1
6340 NetrwKeepj norm! 0
6341 let treedepthchr= substitute(s:treedepthstring,' ','','')
6342 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6343" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6344 endif
6345 if srch > 0
6346" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6347 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6348 exe srch
6349 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006350 endif
6351" call Dret("s:TreeSqueezeDir")
6352endfun
6353
6354" ---------------------------------------------------------------------
6355" s:NetrwMaps: {{{2
6356fun! s:NetrwMaps(islocal)
6357" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6358
Bram Moolenaar85850f32019-07-19 22:05:51 +02006359 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006360 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006362 if !hasmapto("<Plug>NetrwReturn")
6363 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006364" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006365 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6366 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006368 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6369 endif
6370 endif
6371 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006372" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006373 endif
6374
Bram Moolenaar85850f32019-07-19 22:05:51 +02006375 " generate default <Plug> maps {{{3
6376 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006377 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006378 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6379 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6380 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6381 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6382 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6383 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6384 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6385 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6386 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6387 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6388" ---------------------------------------------------------------------
6389" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6390" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6391" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6392" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6393" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6394" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6395" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6396" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6397" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6398" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6399" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6400" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6401" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6402" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6403" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6404" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6405" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6406" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6407" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6408" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6409" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6410" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6411" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6412" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6413" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6414" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6415" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6416" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6417" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6418" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6419" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6420" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6421" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6422" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6423" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6424" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6425" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6426" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6427" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6428" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6429" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6430" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6431" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6432" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6433" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6434" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6435" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6436
Bram Moolenaara6878372014-03-22 21:02:50 +01006437 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006438" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006439 " local normal-mode maps {{{3
6440 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6441 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6442 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6443 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6444 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6445 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6446 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6447 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6448 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6449 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6450 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6451" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006452 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6453 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6454 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006455 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006456 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006457 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6458 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6459 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6460 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6462 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6463 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6464 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6465 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6466 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6467 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6468 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6469 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6470 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6471 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6472 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6473 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006474 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006475 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006476 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6477 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6478 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6479 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6480 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006481 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006482 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006483 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6484 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6486 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6487 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006488 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006489 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006490 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6491 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006492 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006493 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006494 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6495 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6496 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006497 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6498 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006499
6500 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 +01006501 if !hasmapto('<Plug>NetrwHideEdit')
6502 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006503 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006504 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006505 if !hasmapto('<Plug>NetrwRefresh')
6506 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006507 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006508 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 +01006509 if s:didstarstar || !mapcheck("<s-down>","n")
6510 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006511 endif
6512 if s:didstarstar || !mapcheck("<s-up>","n")
6513 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006514 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006515 if !hasmapto('<Plug>NetrwTreeSqueeze')
6516 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006517 endif
6518 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006519 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6520 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006521 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6522 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6523 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6524 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6525 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6526 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6527 imap <buffer> <leftmouse> <Plug>ILeftmouse
6528 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006529 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006530 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006531 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006532 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006533 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006534 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006535 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6536 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006537 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006538 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6539 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6540 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6541 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6542 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6543 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6544 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006545 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6546
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006547 " support user-specified maps
6548 call netrw#UserMaps(1)
6549
Bram Moolenaar85850f32019-07-19 22:05:51 +02006550 else
6551 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006553 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006554 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6555 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6556 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6557 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6558 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6559 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6560 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6561 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6562 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6563 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6565" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006566 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6567 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6568 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6569 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6570 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6571 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6572 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6573 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006574 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006575 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006576 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6577 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6578 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6579 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6581 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6582 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6583 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6584 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6585 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6586 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006588 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6590 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6591 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6592 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006594 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6595 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6596 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6597 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006598 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006599 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6600 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006601 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006602 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 +01006603 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6604 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6605 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6606 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6608 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6609 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6610 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6611 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006612 if !hasmapto('<Plug>NetrwHideEdit')
6613 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006614 endif
6615 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6616 if !hasmapto('<Plug>NetrwRefresh')
6617 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006618 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 if !hasmapto('<Plug>NetrwTreeSqueeze')
6620 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006621 endif
6622 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006623
6624 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006625 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006626
6627 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6628 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6630 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6631 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6632 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6633 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6634 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6635 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6636 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6637 nmap <middlemouse> <Plug>NetrwMiddlemouse
6638 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6639 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6640 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6641 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006642 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6645 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006646 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006647 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6648 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6649 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6650 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6651 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6652 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6653 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006654 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006655
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006656 " support user-specified maps
6657 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006658 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006659
6660" call Dret("s:NetrwMaps")
6661endfun
6662
6663" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006664" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006665" If -buffer, the command is only available from within netrw buffers
6666" Otherwise, the command is available from any window, so long as netrw
6667" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006668fun! s:NetrwCommands(islocal)
6669" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6670
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006671 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6672 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006673 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 +01006674 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006675 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006677 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006678 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006679 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006680
6681" call Dret("s:NetrwCommands")
6682endfun
6683
6684" ---------------------------------------------------------------------
6685" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6686" glob()ing only works with local files
6687fun! s:NetrwMarkFiles(islocal,...)
6688" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 let curdir = s:NetrwGetCurdir(a:islocal)
6690 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006691 while i <= a:0
6692 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006693 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006694 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006696 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006698 else
6699 let mffiles= [a:{i}]
6700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006702 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 call s:NetrwMarkFile(a:islocal,mffile)
6705 endfor
6706 let i= i + 1
6707 endwhile
6708" call Dret("s:NetrwMarkFiles")
6709endfun
6710
6711" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006713fun! s:NetrwMarkTarget(...)
6714" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6715 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 let curdir = s:NetrwGetCurdir(1)
6717 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006718 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006719 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6720 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006722" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006723 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6725 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006726 let svpos = winsaveview()
6727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006728 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006729" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6730 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006731" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006732endfun
6733
6734" ---------------------------------------------------------------------
6735" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6736" mark and unmark files. If a markfile list exists,
6737" then the rename and delete functions will use it instead
6738" of whatever may happen to be under the cursor at that
6739" moment. When the mouse and gui are available,
6740" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006741"
6742" Creates two lists
6743" s:netrwmarkfilelist -- holds complete paths to all marked files
6744" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6745"
6746" Creates a marked file match string
6747" s:netrwmarfilemtch_# -- used with 2match to display marked files
6748"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006749" Creates a buffer version of islocal
6750" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006751fun! s:NetrwMarkFile(islocal,fname)
6752" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006753" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006754
6755 " sanity check
6756 if empty(a:fname)
6757" call Dret("s:NetrwMarkFile : emtpy fname")
6758 return
6759 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006761
Bram Moolenaar97d62492012-11-15 21:28:22 +01006762 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006763 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006764 if a:fname =~ '^\a'
6765 let leader= '\<'
6766 else
6767 let leader= ''
6768 endif
6769 if a:fname =~ '\a$'
6770 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6771 else
6772 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6773 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006774
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006776 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006777" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6778" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6779" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006780 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006781
6782 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006783 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006785 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006786 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787
6788 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006789 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6792 if s:netrwmarkfilelist_{curbufnr} == []
6793 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006795 call s:NetrwUnmarkList(curbufnr,curdir)
6796 else
6797 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006799 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006800 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006801 for fname in s:netrwmarkfilelist_{curbufnr}
6802 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006803 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006804 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006806 endif
6807 let first= 0
6808 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006809" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006810 endif
6811 endif
6812
6813 else
6814 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006816
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006817" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006818 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6820" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006821
6822 " build initial markfile matching pattern
6823 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006825 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006826 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006827 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006828" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006829 endif
6830
6831 " handle global markfilelist
6832 if exists("s:netrwmarkfilelist")
6833 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6834 if index(s:netrwmarkfilelist,dname) == -1
6835 " append new filename to global markfilelist
6836 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006837" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006838 else
6839 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006840" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6841" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006843" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006844 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006845" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006846 unlet s:netrwmarkfilelist
6847 endif
6848 endif
6849 else
6850 " initialize new global-directory markfilelist
6851 let s:netrwmarkfilelist= []
6852 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 endif
6855
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006857 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6858 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6859" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6860 if exists("g:did_drchip_netrwlist_syntax")
6861 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6862 endif
6863 else
6864" " call Decho("2match none",'~'.expand("<slnum>"))
6865 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006866 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006867 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006868 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006869" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6870" 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 +00006871endfun
6872
6873" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006874" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6875" mA: move the argument list to marked file list (tomflist=1)
6876" Uses the global marked file list
6877fun! s:NetrwMarkFileArgList(islocal,tomflist)
6878" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6879
6880 let svpos = winsaveview()
6881" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6882 let curdir = s:NetrwGetCurdir(a:islocal)
6883 let curbufnr = bufnr("%")
6884
6885 if a:tomflist
6886 " mA: move argument list to marked file list
6887 while argc()
6888 let fname= argv(0)
6889" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6890 exe "argdel ".fnameescape(fname)
6891 call s:NetrwMarkFile(a:islocal,fname)
6892 endwhile
6893
6894 else
6895 " ma: move marked file list to argument list
6896 if exists("s:netrwmarkfilelist")
6897
6898 " for every filename in the marked list
6899 for fname in s:netrwmarkfilelist
6900" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6901 exe "argadd ".fnameescape(fname)
6902 endfor " for every file in the marked list
6903
6904 " unmark list and refresh
6905 call s:NetrwUnmarkList(curbufnr,curdir)
6906 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6907" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6908 NetrwKeepj call winrestview(svpos)
6909 endif
6910 endif
6911
6912" call Dret("s:NetrwMarkFileArgList")
6913endfun
6914
6915" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6917" compress/decompress files using the programs
6918" in g:netrw_compress and g:netrw_uncompress,
6919" using g:netrw_compress_suffix to know which to
6920" do. By default:
6921" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006922" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923fun! s:NetrwMarkFileCompress(islocal)
6924" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006925 let svpos = winsaveview()
6926" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006927 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006928 let curbufnr = bufnr("%")
6929
Bram Moolenaarff034192013-04-24 18:51:19 +02006930 " sanity check
6931 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006932 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006933" call Dret("s:NetrwMarkFileCompress")
6934 return
6935 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006937
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006939
6940 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006942 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006944 if exists("g:netrw_decompress['".sfx."']")
6945 " fname has a suffix indicating that its compressed; apply associated decompression routine
6946 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006947" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006948 let exe= netrw#WinPath(exe)
6949 if a:islocal
6950 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006953 call system(exe." ".fname)
6954 if v:shell_error
6955 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006956 endif
6957 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006958 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6959 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006961
Bram Moolenaarff034192013-04-24 18:51:19 +02006962 endif
6963 unlet sfx
6964
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 if exists("exe")
6966 unlet exe
6967 elseif a:islocal
6968 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006969 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006970 if v:shell_error
6971 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 else
6974 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006975 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006976 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006977 endfor " for every file in the marked list
6978
Bram Moolenaar446cb832008-06-24 21:56:24 +00006979 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006980 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006981" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6982 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 endif
6984" call Dret("s:NetrwMarkFileCompress")
6985endfun
6986
6987" ---------------------------------------------------------------------
6988" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6989" If no marked files, then set up directory as the
6990" target. Currently does not support copying entire
6991" directories. Uses the local-buffer marked file list.
6992" Returns 1=success (used by NetrwMarkFileMove())
6993" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006994fun! s:NetrwMarkFileCopy(islocal,...)
6995" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6996
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006997 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006998 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006999 if b:netrw_curdir !~ '/$'
7000 if !exists("b:netrw_curdir")
7001 let b:netrw_curdir= curdir
7002 endif
7003 let b:netrw_curdir= b:netrw_curdir."/"
7004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005
Bram Moolenaarff034192013-04-24 18:51:19 +02007006 " sanity check
7007 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007008 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007009" call Dret("s:NetrwMarkFileCopy")
7010 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007011 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007012" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007013
Bram Moolenaar446cb832008-06-24 21:56:24 +00007014 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007015 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007016" call Dret("s:NetrwMarkFileCopy 0")
7017 return 0
7018 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007019" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007021 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007022 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007023" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007024 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007025 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7026" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7027 return
7028 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007029
7030 " copy marked files while within the same directory (ie. allow renaming)
7031 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7032 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7033 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007034" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007035 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007036 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7037 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007038" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007039 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007040 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007041 let oldname = a:1
7042 else
7043 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007044" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007045 let s:recursive= 1
7046 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7047 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7048 if ret == 0
7049 break
7050 endif
7051 endfor
7052 unlet s:recursive
7053 call s:NetrwUnmarkList(curbufnr,curdir)
7054" call Dret("s:NetrwMarkFileCopy ".ret)
7055 return ret
7056 endif
7057
7058 call inputsave()
7059 let newname= input("Copy ".oldname." to : ",oldname,"file")
7060 call inputrestore()
7061 if newname == ""
7062" call Dret("s:NetrwMarkFileCopy 0")
7063 return 0
7064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007065 let args= s:ShellEscape(oldname)
7066 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007067 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007068 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7069 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007070 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7072 let args= substitute(args,'/','\\','g')
7073 let tgt = substitute(tgt, '/','\\','g')
7074 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007075 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7076 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7077 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7078 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7079" call Decho("args <".args.">",'~'.expand("<slnum>"))
7080" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007081 if isdirectory(s:NetrwFile(args))
7082" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007083 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007084" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007085 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7086 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7087 " contents to a target. One must append the source directory name to the target to get xcopy to
7088 " do the right thing.
7089 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007091 endif
7092 else
7093 let copycmd= g:netrw_localcopycmd
7094 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007095 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007096 let copycmd = substitute(copycmd,'\s.*$','','')
7097 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 let copycmd = netrw#WinPath(copycmd).copycmdargs
7099 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007100 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102" call Decho("args <".args.">",'~'.expand("<slnum>"))
7103" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7104" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7105" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007106 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007107 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007108 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007109 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 +01007110 else
7111 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7112 endif
7113" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007114 return 0
7115 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007116
7117 elseif a:islocal && !s:netrwmftgt_islocal
7118 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007119" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007120 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007121
7122 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007123 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007124" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007125 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126
7127 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007128 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007129" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007130 let curdir = getcwd()
7131 let tmpdir = s:GetTempfile("")
7132 if tmpdir !~ '/'
7133 let tmpdir= curdir."/".tmpdir
7134 endif
7135 if exists("*mkdir")
7136 call mkdir(tmpdir)
7137 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007138 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007139 if v:shell_error != 0
7140 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 +01007141" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007142 return
7143 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007146 if s:NetrwLcd(tmpdir)
7147" call Dret("s:NetrwMarkFileCopy : lcd failure")
7148 return
7149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007150 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007151 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007152 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007153 if getcwd() == tmpdir
7154 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007155 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007157 if s:NetrwLcd(curdir)
7158" call Dret("s:NetrwMarkFileCopy : lcd failure")
7159 return
7160 endif
7161 if v:version < 704 || (v:version == 704 && !has("patch1107"))
7162 call s:NetrwExe("sil !".g:netrw_localrmdir.g:netrw_localrmdiropt." ".s:ShellEscape(tmpdir,1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 if v:shell_error != 0
7164 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
7165" " call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".s:ShellEscape(tmpdir,1) )
7166 return
7167 endif
7168 else
7169 if delete(tmpdir,"d")
7170 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
7171 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007172 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007173 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007174 if s:NetrwLcd(curdir)
7175" call Dret("s:NetrwMarkFileCopy : lcd failure")
7176 return
7177 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007178 endif
7179 endif
7180 endif
7181
7182 " -------
7183 " cleanup
7184 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007185" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007186 " remove markings from local buffer
7187 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007188" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7189" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7190" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7191" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7192" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7193" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7194 if exists("s:recursive")
7195" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7196 else
7197" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007198 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007199 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007200 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007201 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007202 else
7203 " refresh local and targets for fast browsing
7204 if !exists("s:recursive")
7205 " remove markings from local buffer
7206" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7207 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7208 endif
7209
7210 " refresh buffers
7211 if s:netrwmftgt_islocal
7212" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7213 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7214 endif
7215 if a:islocal && s:netrwmftgt != curdir
7216" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7217 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7218 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220
Bram Moolenaar446cb832008-06-24 21:56:24 +00007221" call Dret("s:NetrwMarkFileCopy 1")
7222 return 1
7223endfun
7224
7225" ---------------------------------------------------------------------
7226" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7227" invoke vim's diff mode on the marked files.
7228" Either two or three files can be so handled.
7229" Uses the global marked file list.
7230fun! s:NetrwMarkFileDiff(islocal)
7231" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7232 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007233
Bram Moolenaarff034192013-04-24 18:51:19 +02007234 " sanity check
7235 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007236 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007237" call Dret("s:NetrwMarkFileDiff")
7238 return
7239 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007240 let curdir= s:NetrwGetCurdir(a:islocal)
7241" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007242
Bram Moolenaara6878372014-03-22 21:02:50 +01007243 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007245 for fname in s:netrwmarkfilelist
7246 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007248" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007249 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007250 diffthis
7251 elseif cnt == 2 || cnt == 3
7252 vsplit
7253 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007254" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007255 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 diffthis
7257 else
7258 break
7259 endif
7260 endfor
7261 call s:NetrwUnmarkList(curbufnr,curdir)
7262 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007263
Bram Moolenaar446cb832008-06-24 21:56:24 +00007264" call Dret("s:NetrwMarkFileDiff")
7265endfun
7266
7267" ---------------------------------------------------------------------
7268" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7269" Uses global markfilelist
7270fun! s:NetrwMarkFileEdit(islocal)
7271" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007273 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007274 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007275
7276 " sanity check
7277 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007279" call Dret("s:NetrwMarkFileEdit")
7280 return
7281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007282" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007283
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284 if exists("s:netrwmarkfilelist_{curbufnr}")
7285 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007286 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007287 " unmark markedfile list
7288" call s:NetrwUnmarkList(curbufnr,curdir)
7289 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007290" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007291 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007293 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007294
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295" call Dret("s:NetrwMarkFileEdit")
7296endfun
7297
7298" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007299" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007300fun! s:NetrwMarkFileQFEL(islocal,qfel)
7301" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7302 call s:NetrwUnmarkAll()
7303 let curbufnr= bufnr("%")
7304
7305 if !empty(a:qfel)
7306 for entry in a:qfel
7307 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007308" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007309 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007311 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7312 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7313 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7314 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007315" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007316 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7317 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007318" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007319 endif
7320 endfor
7321 echo "(use me to edit marked files)"
7322 else
7323 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7324 endif
7325
7326" call Dret("s:NetrwMarkFileQFEL")
7327endfun
7328
7329" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007330" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7331" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7332" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7333fun! s:NetrwMarkFileExe(islocal,enbloc)
7334" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007335 let svpos = winsaveview()
7336" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338 let curbufnr = bufnr("%")
7339
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007340 if a:enbloc == 0
7341 " individually apply command to files, one at a time
7342 " sanity check
7343 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7344 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7345" call Dret("s:NetrwMarkFileExe")
7346 return
7347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007348" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007349
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 if exists("s:netrwmarkfilelist_{curbufnr}")
7351 " get the command
7352 call inputsave()
7353 let cmd= input("Enter command: ","","file")
7354 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007356 if cmd == ""
7357" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7358 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007360
7361 " apply command to marked files, individually. Substitute: filename -> %
7362 " If no %, then append a space and the filename to the command
7363 for fname in s:netrwmarkfilelist_{curbufnr}
7364 if a:islocal
7365 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007366 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007367 endif
7368 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007369 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007370 endif
7371 if cmd =~ '%'
7372 let xcmd= substitute(cmd,'%',fname,'g')
7373 else
7374 let xcmd= cmd.' '.fname
7375 endif
7376 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007377" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007378 let ret= system(xcmd)
7379 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007381 let ret= s:RemoteSystem(xcmd)
7382 endif
7383 if v:shell_error < 0
7384 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7385 break
7386 else
7387 echo ret
7388 endif
7389 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390
7391 " unmark marked file list
7392 call s:NetrwUnmarkList(curbufnr,curdir)
7393
7394 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007396" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7397 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007398 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007399 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007401
7402 else " apply command to global list of files, en bloc
7403
7404 call inputsave()
7405 let cmd= input("Enter command: ","","file")
7406 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007407" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007408 if cmd == ""
7409" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7410 return
7411 endif
7412 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007413 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007414 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007415 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007416 endif
7417 if a:islocal
7418 call system(cmd)
7419 if v:shell_error < 0
7420 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7421 endif
7422 else
7423 let ret= s:RemoteSystem(cmd)
7424 endif
7425 call s:NetrwUnmarkAll()
7426
7427 " refresh the listing
7428 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007429" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7430 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007431
7432 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007433
Bram Moolenaar446cb832008-06-24 21:56:24 +00007434" call Dret("s:NetrwMarkFileExe")
7435endfun
7436
7437" ---------------------------------------------------------------------
7438" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7439" as the marked file(s) (toggles suffix presence)
7440" Uses the local marked file list.
7441fun! s:NetrwMarkHideSfx(islocal)
7442" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007443 let svpos = winsaveview()
7444" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445 let curbufnr = bufnr("%")
7446
7447 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7448 if exists("s:netrwmarkfilelist_{curbufnr}")
7449
7450 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007452 " construct suffix pattern
7453 if fname =~ '\.'
7454 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7455 else
7456 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7457 endif
7458 " determine if its in the hiding list or not
7459 let inhidelist= 0
7460 if g:netrw_list_hide != ""
7461 let itemnum = 0
7462 let hidelist= split(g:netrw_list_hide,',')
7463 for hidepat in hidelist
7464 if sfxpat == hidepat
7465 let inhidelist= 1
7466 break
7467 endif
7468 let itemnum= itemnum + 1
7469 endfor
7470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472 if inhidelist
7473 " remove sfxpat from list
7474 call remove(hidelist,itemnum)
7475 let g:netrw_list_hide= join(hidelist,",")
7476 elseif g:netrw_list_hide != ""
7477 " append sfxpat to non-empty list
7478 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7479 else
7480 " set hiding list to sfxpat
7481 let g:netrw_list_hide= sfxpat
7482 endif
7483 endfor
7484
7485 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007487" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7488 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007489 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007490 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007491 endif
7492
7493" call Dret("s:NetrwMarkHideSfx")
7494endfun
7495
7496" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007498" Uses the local marked-file list.
7499fun! s:NetrwMarkFileVimCmd(islocal)
7500" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007501 let svpos = winsaveview()
7502" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007504 let curbufnr = bufnr("%")
7505
Bram Moolenaarff034192013-04-24 18:51:19 +02007506 " sanity check
7507 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007509" call Dret("s:NetrwMarkFileVimCmd")
7510 return
7511 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007512" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007513
Bram Moolenaar15146672011-10-20 22:22:38 +02007514 if exists("s:netrwmarkfilelist_{curbufnr}")
7515 " get the command
7516 call inputsave()
7517 let cmd= input("Enter vim command: ","","file")
7518 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007519" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007520 if cmd == ""
7521" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7522 return
7523 endif
7524
7525 " apply command to marked files. Substitute: filename -> %
7526 " If no %, then append a space and the filename to the command
7527 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007529 if a:islocal
7530 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007531 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007532" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007533 exe cmd
7534 exe "sil! keepalt wq!"
7535 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007536" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007538 endif
7539 endfor
7540
7541 " unmark marked file list
7542 call s:NetrwUnmarkList(curbufnr,curdir)
7543
7544 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007545 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007546" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7547 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007548 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007549 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007551
Bram Moolenaar15146672011-10-20 22:22:38 +02007552" call Dret("s:NetrwMarkFileVimCmd")
7553endfun
7554
7555" ---------------------------------------------------------------------
7556" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7557" as the marked file(s) (toggles suffix presence)
7558" Uses the local marked file list.
7559fun! s:NetrwMarkHideSfx(islocal)
7560" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007561 let svpos = winsaveview()
7562" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007563 let curbufnr = bufnr("%")
7564
7565 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7566 if exists("s:netrwmarkfilelist_{curbufnr}")
7567
7568 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007569" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007570 " construct suffix pattern
7571 if fname =~ '\.'
7572 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7573 else
7574 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7575 endif
7576 " determine if its in the hiding list or not
7577 let inhidelist= 0
7578 if g:netrw_list_hide != ""
7579 let itemnum = 0
7580 let hidelist= split(g:netrw_list_hide,',')
7581 for hidepat in hidelist
7582 if sfxpat == hidepat
7583 let inhidelist= 1
7584 break
7585 endif
7586 let itemnum= itemnum + 1
7587 endfor
7588 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007589" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007590 if inhidelist
7591 " remove sfxpat from list
7592 call remove(hidelist,itemnum)
7593 let g:netrw_list_hide= join(hidelist,",")
7594 elseif g:netrw_list_hide != ""
7595 " append sfxpat to non-empty list
7596 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7597 else
7598 " set hiding list to sfxpat
7599 let g:netrw_list_hide= sfxpat
7600 endif
7601 endfor
7602
7603 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007604 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007605" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7606 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007607 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007608 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007609 endif
7610
7611" call Dret("s:NetrwMarkHideSfx")
7612endfun
7613
7614" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7616" Uses the global markfilelist
7617fun! s:NetrwMarkFileGrep(islocal)
7618" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007619 let svpos = winsaveview()
7620" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007621 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007622 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007623
7624 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007625" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007626 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007627" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007628 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007629 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007630" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007631 let netrwmarkfilelist= "*"
7632 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007633
Bram Moolenaarff034192013-04-24 18:51:19 +02007634 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007635" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007636 call inputsave()
7637 let pat= input("Enter pattern: ","")
7638 call inputrestore()
7639 let patbang = ""
7640 if pat =~ '^!'
7641 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007642 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007643 endif
7644 if pat =~ '^\i'
7645 let pat = escape(pat,'/')
7646 let pat = '/'.pat.'/'
7647 else
7648 let nonisi = pat[0]
7649 endif
7650
7651 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007653 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007654 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007655 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007656 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007657" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7658 return
7659 endtry
7660 echo "(use :cn, :cp to navigate, :Rex to return)"
7661
7662 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007663" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7664 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007665
7666 if exists("nonisi")
7667 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007668" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007669 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007670 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007671 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007672 endif
7673
7674" call Dret("s:NetrwMarkFileGrep")
7675endfun
7676
7677" ---------------------------------------------------------------------
7678" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7679" uses the global marked file list
7680" s:netrwmfloc= 0: target directory is remote
7681" = 1: target directory is local
7682fun! s:NetrwMarkFileMove(islocal)
7683" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007684 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007685 let curbufnr = bufnr("%")
7686
7687 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007688 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007689 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007690" call Dret("s:NetrwMarkFileMove")
7691 return
7692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007693" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007694
Bram Moolenaar446cb832008-06-24 21:56:24 +00007695 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007696 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007697" call Dret("s:NetrwMarkFileCopy 0")
7698 return 0
7699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007701
7702 if a:islocal && s:netrwmftgt_islocal
7703 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007704" call Decho("move from local to local",'~'.expand("<slnum>"))
7705" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007706 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007707 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7708" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7709 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007710 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007711 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007712" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007713 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007714 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007715" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007716 if g:netrw_localmovecmd =~ '\s'
7717 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7718 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7719 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007720" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007721 else
7722 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007723" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007724 endif
7725 else
7726 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007727" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007728 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007729 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007730 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7731 let fname= substitute(fname,'/','\\','g')
7732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007733" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007734 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007735 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007736 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007737 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 +01007738 else
7739 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7740 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007741 break
7742 endif
7743 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744
7745 elseif a:islocal && !s:netrwmftgt_islocal
7746 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007747" call Decho("move from local to remote",'~'.expand("<slnum>"))
7748" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007750 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752 for fname in mflist
7753 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7754 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7755 endfor
7756 unlet mflist
7757
7758 elseif !a:islocal && s:netrwmftgt_islocal
7759 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007760" call Decho("move from remote to local",'~'.expand("<slnum>"))
7761" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007763 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007764" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007765 for fname in mflist
7766 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7767 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7768 endfor
7769 unlet mflist
7770
7771 elseif !a:islocal && !s:netrwmftgt_islocal
7772 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7774" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007775 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007776 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007777" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 for fname in mflist
7779 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7780 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7781 endfor
7782 unlet mflist
7783 endif
7784
7785 " -------
7786 " cleanup
7787 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007789
7790 " remove markings from local buffer
7791 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7792
7793 " refresh buffers
7794 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007795" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007796 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007797 endif
7798 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007799" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007800 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007802 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007803" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007804 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806
Bram Moolenaar446cb832008-06-24 21:56:24 +00007807" call Dret("s:NetrwMarkFileMove")
7808endfun
7809
7810" ---------------------------------------------------------------------
7811" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7812" using the hardcopy command. Local marked-file list only.
7813fun! s:NetrwMarkFilePrint(islocal)
7814" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7815 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007816
7817 " sanity check
7818 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007819 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007820" call Dret("s:NetrwMarkFilePrint")
7821 return
7822 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7824 let curdir= s:NetrwGetCurdir(a:islocal)
7825
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 if exists("s:netrwmarkfilelist_{curbufnr}")
7827 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007828 call s:NetrwUnmarkList(curbufnr,curdir)
7829 for fname in netrwmarkfilelist
7830 if a:islocal
7831 if g:netrw_keepdir
7832 let fname= s:ComposePath(curdir,fname)
7833 endif
7834 else
7835 let fname= curdir.fname
7836 endif
7837 1split
7838 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007840 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842 hardcopy
7843 q
7844 endfor
7845 2match none
7846 endif
7847" call Dret("s:NetrwMarkFilePrint")
7848endfun
7849
7850" ---------------------------------------------------------------------
7851" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7852" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007853" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007854fun! s:NetrwMarkFileRegexp(islocal)
7855" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7856
7857 " get the regular expression
7858 call inputsave()
7859 let regexp= input("Enter regexp: ","","file")
7860 call inputrestore()
7861
7862 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007863 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007864" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007865 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007867 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007868 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007869 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007870 else
7871 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007872 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007873 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007874" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007875
7876 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007877 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007878 if fname =~ '^'.fnameescape(curdir)
7879" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7880 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7881 else
7882" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7883 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7884 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007885 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007886
7887 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889
7890 " convert displayed listing into a filelist
7891 let eikeep = &ei
7892 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007894 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007896 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007897 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007898 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007899 sil NetrwKeepj norm! "ap
7900 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007901 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007902 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007903 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007904 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007905 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007906 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007907 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007908 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007909 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007910 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007911 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7912 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007913 call histdel("/",-1)
7914 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915 endif
7916 " convert regexp into the more usual glob-style format
7917 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007919 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007920 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 let filelist= getline(1,line("$"))
7922 q!
7923 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 endfor
7926 unlet filelist
7927 let @a = areg
7928 let &ei = eikeep
7929 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007930 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931
7932" call Dret("s:NetrwMarkFileRegexp")
7933endfun
7934
7935" ---------------------------------------------------------------------
7936" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7937" Uses the local marked file list.
7938fun! s:NetrwMarkFileSource(islocal)
7939" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7940 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007941
7942 " sanity check
7943 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007944 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007945" call Dret("s:NetrwMarkFileSource")
7946 return
7947 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7949 let curdir= s:NetrwGetCurdir(a:islocal)
7950
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 if exists("s:netrwmarkfilelist_{curbufnr}")
7952 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 call s:NetrwUnmarkList(curbufnr,curdir)
7954 for fname in netrwmarkfilelist
7955 if a:islocal
7956 if g:netrw_keepdir
7957 let fname= s:ComposePath(curdir,fname)
7958 endif
7959 else
7960 let fname= curdir.fname
7961 endif
7962 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007963" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007964 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965 endfor
7966 2match none
7967 endif
7968" call Dret("s:NetrwMarkFileSource")
7969endfun
7970
7971" ---------------------------------------------------------------------
7972" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7973" Uses the global markfilelist
7974fun! s:NetrwMarkFileTag(islocal)
7975" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007976 let svpos = winsaveview()
7977" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007978 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 let curbufnr = bufnr("%")
7980
Bram Moolenaarff034192013-04-24 18:51:19 +02007981 " sanity check
7982 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007983 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007984" call Dret("s:NetrwMarkFileTag")
7985 return
7986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007987" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007988
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7991 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992 call s:NetrwUnmarkAll()
7993
7994 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995
7996" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7997 call system(g:netrw_ctags." ".netrwmarkfilelist)
7998 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007999 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8000 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008001
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008003 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008004 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 let curdir= b:netrw_curdir
8006 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008007 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008009" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008011 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 wq!
8013 endif
8014 2match none
8015 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008016" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8017 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 endif
8019
8020" call Dret("s:NetrwMarkFileTag")
8021endfun
8022
8023" ---------------------------------------------------------------------
8024" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008025" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008026" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008028" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008030" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8031 let svpos = winsaveview()
8032" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008033 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 let hadtgt = exists("s:netrwmftgt")
8035 if !exists("w:netrw_bannercnt")
8036 let w:netrw_bannercnt= b:netrw_bannercnt
8037 endif
8038
8039 " set up target
8040 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008041" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008042 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8043 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008045 unlet s:netrwmftgt s:netrwmftgt_islocal
8046 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008047 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008048 endif
8049 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008050" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8051 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008052" call Dret("s:NetrwMarkFileTgt : removed target")
8053 return
8054 else
8055 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008056" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008057 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058
8059 else
8060 " get word under cursor.
8061 " * If directory, use it for the target.
8062 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008063" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 let curword= s:NetrwGetWord()
8065 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008066 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008067 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069 elseif !a:islocal && tgtdir =~ '/$'
8070 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008071" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 else
8073 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008074" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 endif
8076 endif
8077 if a:islocal
8078 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8079 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 endif
8082 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8085 endif
8086 let s:netrwmftgt_islocal= a:islocal
8087
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008088 " need to do refresh so that the banner will be updated
8089 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008090 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008091" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008092 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008094" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008095 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8097 else
8098 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8099 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008100" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8101 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008102 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008103 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008104 endif
8105
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008106" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8107" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008108" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8109endfun
8110
8111" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8113fun! s:NetrwGetCurdir(islocal)
8114" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8115
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008116 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008117 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8118" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8119 elseif !exists("b:netrw_curdir")
8120 let b:netrw_curdir= getcwd()
8121" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8122 endif
8123
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008124" 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 +01008125 if b:netrw_curdir !~ '\<\a\{3,}://'
8126 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008127" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008128 if g:netrw_keepdir == 0
8129 call s:NetrwLcd(curdir)
8130 endif
8131 endif
8132
8133" call Dret("s:NetrwGetCurdir <".curdir.">")
8134 return b:netrw_curdir
8135endfun
8136
8137" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008138" s:NetrwOpenFile: query user for a filename and open it {{{2
8139fun! s:NetrwOpenFile(islocal)
8140" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008141 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008142 call inputsave()
8143 let fname= input("Enter filename: ")
8144 call inputrestore()
8145 if fname !~ '[/\\]'
8146 if exists("b:netrw_curdir")
8147 if exists("g:netrw_quiet")
8148 let netrw_quiet_keep = g:netrw_quiet
8149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150 let g:netrw_quiet = 1
8151 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008152 let s:rexposn_{bufnr("%")}= winsaveview()
8153" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008154 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008155 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008156 else
8157 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8158 endif
8159 if exists("netrw_quiet_keep")
8160 let g:netrw_quiet= netrw_quiet_keep
8161 else
8162 unlet g:netrw_quiet
8163 endif
8164 endif
8165 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008166 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008167 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008168 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008169" call Dret("s:NetrwOpenFile")
8170endfun
8171
8172" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8174" For the mapping to this function be made via
8175" netrwPlugin, you'll need to have had
8176" g:netrw_usetab set to non-zero.
8177fun! netrw#Shrink()
8178" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8179 let curwin = winnr()
8180 let wiwkeep = &wiw
8181 set wiw=1
8182
8183 if &ft == "netrw"
8184 if winwidth(0) > g:netrw_wiw
8185 let t:netrw_winwidth= winwidth(0)
8186 exe "vert resize ".g:netrw_wiw
8187 wincmd l
8188 if winnr() == curwin
8189 wincmd h
8190 endif
8191" call Decho("vert resize 0",'~'.expand("<slnum>"))
8192 else
8193 exe "vert resize ".t:netrw_winwidth
8194" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8195 endif
8196
8197 elseif exists("t:netrw_lexbufnr")
8198 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8199 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8200 let t:netrw_winwidth= winwidth(0)
8201 exe "vert resize ".g:netrw_wiw
8202 wincmd l
8203 if winnr() == curwin
8204 wincmd h
8205 endif
8206" call Decho("vert resize 0",'~'.expand("<slnum>"))
8207 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8208 exe "vert resize ".t:netrw_winwidth
8209" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8210 else
8211 call netrw#Lexplore(0,0)
8212 endif
8213
8214 else
8215 call netrw#Lexplore(0,0)
8216 endif
8217 let wiw= wiwkeep
8218
8219" call Dret("netrw#Shrink")
8220endfun
8221
8222" ---------------------------------------------------------------------
8223" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8224fun! s:NetSortSequence(islocal)
8225" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8226
8227 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008228 let svpos= winsaveview()
8229" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230 call inputsave()
8231 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8232 call inputrestore()
8233
8234 " refresh the listing
8235 let g:netrw_sort_sequence= newsortseq
8236 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008237" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8238 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239 let @@= ykeep
8240
8241" call Dret("NetSortSequence")
8242endfun
8243
8244" ---------------------------------------------------------------------
8245" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8246" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008247" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008248fun! s:NetrwUnmarkList(curbufnr,curdir)
8249" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8250
8251 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008252 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008253 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8254 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8255 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8256 call remove(s:netrwmarkfilelist,idx) " remove from global list
8257 endfor
8258 if s:netrwmarkfilelist == []
8259 unlet s:netrwmarkfilelist
8260 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008261
Bram Moolenaar446cb832008-06-24 21:56:24 +00008262 " getting rid of the local marked-file lists is easy
8263 unlet s:netrwmarkfilelist_{a:curbufnr}
8264 endif
8265 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8266 unlet s:netrwmarkfilemtch_{a:curbufnr}
8267 endif
8268 2match none
8269" call Dret("s:NetrwUnmarkList")
8270endfun
8271
8272" ---------------------------------------------------------------------
8273" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8274fun! s:NetrwUnmarkAll()
8275" call Dfunc("s:NetrwUnmarkAll()")
8276 if exists("s:netrwmarkfilelist")
8277 unlet s:netrwmarkfilelist
8278 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008279 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008280 2match none
8281" call Dret("s:NetrwUnmarkAll")
8282endfun
8283
8284" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008285" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286fun! s:NetrwUnmarkAll2()
8287" call Dfunc("s:NetrwUnmarkAll2()")
8288 redir => netrwmarkfilelist_let
8289 let
8290 redir END
8291 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008292 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008293 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8294 for flist in netrwmarkfilelist_list
8295 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8296 unlet s:netrwmarkfilelist_{curbufnr}
8297 unlet s:netrwmarkfilemtch_{curbufnr}
8298 endfor
8299" call Dret("s:NetrwUnmarkAll2")
8300endfun
8301
8302" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008303" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8304"
8305" Marked files are in two types of lists:
8306" s:netrwmarkfilelist -- holds complete paths to all marked files
8307" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8308"
8309" Marked files suitable for use with 2match are in:
8310" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311fun! s:NetrwUnMarkFile(islocal)
8312" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008313 let svpos = winsaveview()
8314" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008315 let curbufnr = bufnr("%")
8316
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008317 " unmark marked file list
8318 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8319 if exists("s:netrwmarkfilelist")
8320" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008321 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008322 endif
8323
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008324 let ibuf= 1
8325 while ibuf < bufnr("$")
8326 if exists("s:netrwmarkfilelist_".ibuf)
8327 unlet s:netrwmarkfilelist_{ibuf}
8328 unlet s:netrwmarkfilemtch_{ibuf}
8329 endif
8330 let ibuf = ibuf + 1
8331 endwhile
8332 2match none
8333
Bram Moolenaar446cb832008-06-24 21:56:24 +00008334" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008335"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8336call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008337" call Dret("s:NetrwUnMarkFile")
8338endfun
8339
8340" ---------------------------------------------------------------------
8341" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8342fun! s:NetrwMenu(domenu)
8343
8344 if !exists("g:NetrwMenuPriority")
8345 let g:NetrwMenuPriority= 80
8346 endif
8347
Bram Moolenaaradc21822011-04-01 18:03:16 +02008348 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008349" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8350
8351 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008352" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008353 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008354 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8355 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8356 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8357 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8358 if g:netrw_dirhistmax > 0
8359 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8360 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8361 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8362 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8363 else
8364 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8365 endif
8366 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8367 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8368 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8369 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8370 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8371 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8372 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8373 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8374 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8375 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8376 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8377 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8378 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8379 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8380 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 +01008381 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 +02008382 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8383 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8384 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8385 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8386 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8387 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8388 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8389 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8390 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8391 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8392 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8393 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8394 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8395 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8396 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8397 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8398 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8399 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8400 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8401 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8402 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8403 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8404 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8405 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8406 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8407 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8408 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8409 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8410 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8411 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>'
8412 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>'
8413 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>'
8414 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8415 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>'
8416 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>'
8417 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 +01008418 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 +02008419 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8420 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008422 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8423 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424
8425 elseif !a:domenu
8426 let s:netrwcnt = 0
8427 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008428 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429 exe curwin."wincmd w"
8430
8431 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008432" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008433 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008434" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008435 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436 endif
8437 endif
8438" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008439 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440 endif
8441
8442endfun
8443
8444" ---------------------------------------------------------------------
8445" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8446" Used by the O maps (as <SID>NetrwObtain())
8447fun! s:NetrwObtain(islocal)
8448" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8449
Bram Moolenaar97d62492012-11-15 21:28:22 +01008450 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008452 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008453 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8455 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008456 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008458 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459
8460" call Dret("NetrwObtain")
8461endfun
8462
8463" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8465" If there's only one window, then the window will first be split.
8466" Returns:
8467" choice = 0 : didn't have to choose
8468" choice = 1 : saved modified file in window first
8469" choice = 2 : didn't save modified file, opened window
8470" choice = 3 : cancel open
8471fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008472" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008473
Bram Moolenaar97d62492012-11-15 21:28:22 +01008474 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008476 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008477
8478 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008479 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008480 let lastwinnr = winnr("$")
8481 let curword = s:NetrwGetWord()
8482 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008483 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008484 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008485" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486
Bram Moolenaar8d043172014-01-23 14:24:41 +01008487 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008488 if lastwinnr == 1
8489 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008490" 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 +02008491 " g:netrw_preview=0: preview window shown in a horizontally split window
8492 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008494 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008495 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008496" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008497 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008498 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008499 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008500 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008501" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008502 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008503 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008504 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008505" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008506
8507 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008508 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008509 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008510 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008512" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008513
8514 " prevwinnr: the window number of the "prev" window
8515 " prevbufnr: the buffer number of the buffer in the "prev" window
8516 " bnrcnt : the qty of windows open on the "prev" buffer
8517 let prevwinnr = winnr()
8518 let prevbufnr = bufnr("%")
8519 let prevbufname = bufname("%")
8520 let prevmod = &mod
8521 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008522 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008523" 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 +01008524
8525 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008526 " and it doesn't appear in any other extant window, then ask the
8527 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008528 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008529" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008530 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008531" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008532 exe prevwinnr."wincmd w"
8533
8534 if bnrcnt == 1 && &hidden == 0
8535 " only one copy of the modified buffer in a window, and
8536 " hidden not set, so overwriting will lose the modified file. Ask first...
8537 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008538" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008539 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008540
8541 if choice == 1
8542 " Yes -- write file & then browse
8543 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008544 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008545 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008546 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008547 exe origwin."wincmd w"
8548 let &ei = eikeep
8549 let @@ = ykeep
8550" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008551 return choice
8552 endif
8553
8554 elseif choice == 2
8555 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008556" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008557 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558
8559 else
8560 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008561" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008562 exe origwin."wincmd w"
8563 let &ei= eikeep
8564 let @@ = ykeep
8565" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 return choice
8567 endif
8568 endif
8569 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008570 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571 endif
8572
8573 " restore b:netrw_curdir (window split/enew may have lost it)
8574 let b:netrw_curdir= curdir
8575 if a:islocal < 2
8576 if a:islocal
8577 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8578 else
8579 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8580 endif
8581 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008582 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008583" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 return choice
8585endfun
8586
8587" ---------------------------------------------------------------------
8588" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8589" Always assumed to be local -> remote
8590" call s:NetrwUpload(filename, target)
8591" call s:NetrwUpload(filename, target, fromdirectory)
8592fun! s:NetrwUpload(fname,tgt,...)
8593" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8594
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008595 if a:tgt =~ '^\a\{3,}://'
8596 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008597 else
8598 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008600" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601
8602 if a:0 > 0
8603 let fromdir= a:1
8604 else
8605 let fromdir= getcwd()
8606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008607" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608
8609 if type(a:fname) == 1
8610 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008611" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008613" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8614 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8615" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616 if a:tgt =~ '/$'
8617 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008619 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008621" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008622 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008623" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 endif
8625 q!
8626
8627 elseif type(a:fname) == 3
8628 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 let curdir= getcwd()
8631 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008632 if s:NetrwLcd(fromdir)
8633" call Dret("s:NetrwUpload : lcd failure")
8634 return
8635 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008636 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008637 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if exists("g:netrw_port") && g:netrw_port != ""
8639 let useport= " ".g:netrw_scpport." ".g:netrw_port
8640 else
8641 let useport= ""
8642 endif
8643 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8644 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008645 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 +02008646 if s:NetrwLcd(curdir)
8647" call Dret("s:NetrwUpload : lcd failure")
8648 return
8649 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650
8651 elseif a:tgt =~ '^ftp:'
8652 call s:NetrwMethod(a:tgt)
8653
8654 if b:netrw_method == 2
8655 " handle uploading a list of files via ftp+.netrc
8656 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008657 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008658" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008660 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008661" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008662
8663 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008664 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008665" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 endif
8667
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008668 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008669" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670
Bram Moolenaaradc21822011-04-01 18:03:16 +02008671 if tgtdir == ""
8672 let tgtdir= '/'
8673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008674 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008675" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008676
8677 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008678 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8679" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008680 endfor
8681
8682 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683 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 +00008684 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008685" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8686 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687 endif
8688 " 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 +01008689 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008690 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008691 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8692 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8693 else
8694 bw!|q
8695 endif
8696
8697 elseif b:netrw_method == 3
8698 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8699 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008700 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008702 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008703
8704 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008705 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008706" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008707 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008708 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008709" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710 endif
8711
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008712 if exists("g:netrw_uid") && g:netrw_uid != ""
8713 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008714 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008715" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008716 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008717 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008719" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008720 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008721 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008723 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 endif
8725
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008726 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008727" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008728
8729 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008730 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008731" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732 endif
8733
8734 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008735 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008736" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737 endif
8738
8739 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008740 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008741" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 endfor
8743
8744 " perform ftp:
8745 " -i : turns off interactive prompting from ftp
8746 " -n unix : DON'T use <.netrc>, even though it exists
8747 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008748 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008749 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750 " 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 +01008751 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008752 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008753 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8754 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008755 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008756 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8757 let &debug = debugkeep
8758 let mod = 1
8759 else
8760 bw!|q
8761 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008762 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008763" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008764 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 endif
8766 else
8767 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8768 endif
8769 endif
8770
8771" call Dret("s:NetrwUpload")
8772endfun
8773
8774" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008775" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776fun! s:NetrwPreview(path) range
8777" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008778" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8779" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008780 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008781 NetrwKeepj call s:NetrwOptionsSave("s:")
8782 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8783 NetrwKeepj call s:NetrwOptionsSafe(1)
8784 else
8785 NetrwKeepj call s:NetrwOptionsSafe(0)
8786 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008788" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008790" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8791 if g:netrw_preview
8792 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008793 let pvhkeep = &pvh
8794 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8795 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008796" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8797 else
8798 " horizontal split
8799 let pvhkeep = &pvh
8800 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8801 let &pvh = winheight(0) - winsz
8802" 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 +02008803 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008804 " g:netrw_preview g:netrw_alto
8805 " 1 : vert 1: top -- preview window is vertically split off and on the left
8806 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8807 " 0 : 1: top -- preview window is horizontally split off and on the top
8808 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8809 "
8810 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowse() check via
8811 " the BufEnter event set up in netrwPlugin.vim
8812" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8813 let eikeep = &ei
8814 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008815 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008816 let &ei= eikeep
8817" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008818 if exists("pvhkeep")
8819 let &pvh= pvhkeep
8820 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008823 endif
8824 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 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 +00008826 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008827 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008828 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829" call Dret("NetrwPreview")
8830endfun
8831
8832" ---------------------------------------------------------------------
8833" s:NetrwRefresh: {{{2
8834fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008835" 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 +00008836 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008837 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008838" call Decho("setl ma noro",'~'.expand("<slnum>"))
8839" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008840 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008841 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8842 if !exists("w:netrw_treetop")
8843 if exists("b:netrw_curdir")
8844 let w:netrw_treetop= b:netrw_curdir
8845 else
8846 let w:netrw_treetop= getcwd()
8847 endif
8848 endif
8849 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8850 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008851
8852 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008853 let screenposn = winsaveview()
8854" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008855
8856" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8857" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8858 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008859 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008864
8865 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008866" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8867 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008870 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8871 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8872" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8873 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8874 else
8875" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8876 2match none
8877 endif
8878 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879
Bram Moolenaar97d62492012-11-15 21:28:22 +01008880" restore
8881 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008883endfun
8884
8885" ---------------------------------------------------------------------
8886" s:NetrwRefreshDir: refreshes a directory by name {{{2
8887" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008888" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008890" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008891 if g:netrw_fastbrowse == 0
8892 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008895" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896
8897 if tgtwin > 0
8898 " tgtwin is being displayed, so refresh it
8899 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008900" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008902 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903 exe curwin."wincmd w"
8904
8905 elseif bufnr(a:dirname) > 0
8906 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8908 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008909 endif
8910
8911 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008912" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008914 endif
8915" call Dret("s:NetrwRefreshDir")
8916endfun
8917
8918" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008919" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8920" window number to do its editing in.
8921" Supports [count]C where the count, if present, is used to specify
8922" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008923fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008924" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008926" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008927 if a:1 == "" " :NetrwC win#
8928 let g:netrw_chgwin= winnr()
8929 else " :NetrwC
8930 let g:netrw_chgwin= a:1
8931 endif
8932 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008933 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008934 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008935 let g:netrw_chgwin= winnr()
8936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008937 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008938" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008939endfun
8940
8941" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8943" What this function does is to compute a priority for the patterns
8944" in the g:netrw_sort_sequence. It applies a substitute to any
8945" "files" that satisfy each pattern, putting the priority / in
8946" front. An "*" pattern handles the default priority.
8947fun! s:NetrwSetSort()
8948" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008949 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008950 if w:netrw_liststyle == s:LONGLIST
8951 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8952 else
8953 let seqlist = g:netrw_sort_sequence
8954 endif
8955 " sanity check -- insure that * appears somewhere
8956 if seqlist == ""
8957 let seqlist= '*'
8958 elseif seqlist !~ '\*'
8959 let seqlist= seqlist.',*'
8960 endif
8961 let priority = 1
8962 while seqlist != ""
8963 if seqlist =~ ','
8964 let seq = substitute(seqlist,',.*$','','e')
8965 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8966 else
8967 let seq = seqlist
8968 let seqlist = ""
8969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008970 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008971 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008972 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008973 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008974 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008975 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008976 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008977" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008978
8979 " sanity check
8980 if w:netrw_bannercnt > line("$")
8981 " apparently no files were left after a Hiding pattern was used
8982" call Dret("SetSort : no files left after hiding")
8983 return
8984 endif
8985 if seq == '*'
8986 let starpriority= spriority
8987 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008988 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008989 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990 " sometimes multiple sorting patterns will match the same file or directory.
8991 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008992 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8993 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 endif
8995 let priority = priority + 1
8996 endwhile
8997 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008998 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8999 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009000 endif
9001
9002 " Following line associated with priority -- items that satisfy a priority
9003 " pattern get prefixed by ###/ which permits easy sorting by priority.
9004 " Sometimes files can satisfy multiple priority patterns -- only the latest
9005 " priority pattern needs to be retained. So, at this point, these excess
9006 " priority prefixes need to be removed, but not directories that happen to
9007 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009008 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9009 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009010 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009011
9012" call Dret("SetSort")
9013endfun
9014
Bram Moolenaarff034192013-04-24 18:51:19 +02009015" ---------------------------------------------------------------------
9016" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9017" Implements [count]Tb (bookhist<b>)
9018" [count]Th (bookhist<h>)
9019" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009020fun! s:NetrwSetTgt(islocal,bookhist,choice)
9021" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009022
9023 if a:bookhist == 'b'
9024 " supports choosing a bookmark as a target using a qb-generated list
9025 let choice= a:choice - 1
9026 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009027 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009028 else
9029 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9030 endif
9031
9032 elseif a:bookhist == 'h'
9033 " supports choosing a history stack entry as a target using a qb-generated list
9034 let choice= (a:choice % g:netrw_dirhistmax) + 1
9035 if exists("g:netrw_dirhist_".choice)
9036 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009037 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009038 else
9039 echomsg "Sorry, history#".a:choice." not available!"
9040 endif
9041 endif
9042
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009043 " refresh the display
9044 if !exists("b:netrw_curdir")
9045 let b:netrw_curdir= getcwd()
9046 endif
9047 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9048
Bram Moolenaarff034192013-04-24 18:51:19 +02009049" call Dret("s:NetrwSetTgt")
9050endfun
9051
Bram Moolenaar446cb832008-06-24 21:56:24 +00009052" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009053" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054fun! s:NetrwSortStyle(islocal)
9055" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009056 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009057 let svpos= winsaveview()
9058" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009060 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 +01009061 NetrwKeepj norm! 0
9062 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009063" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9064 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065
9066" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9067endfun
9068
9069" ---------------------------------------------------------------------
9070" s:NetrwSplit: mode {{{2
9071" =0 : net and o
9072" =1 : net and t
9073" =2 : net and v
9074" =3 : local and o
9075" =4 : local and t
9076" =5 : local and v
9077fun! s:NetrwSplit(mode)
9078" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9079
Bram Moolenaar97d62492012-11-15 21:28:22 +01009080 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 call s:SaveWinVars()
9082
9083 if a:mode == 0
9084 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009085 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009086 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009088 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 NetrwKeepj call s:RestoreWinVars()
9091 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009092 unlet s:didsplit
9093
9094 elseif a:mode == 1
9095 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009096 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009097" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098 tabnew
9099 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100 NetrwKeepj call s:RestoreWinVars()
9101 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009102 unlet s:didsplit
9103
9104 elseif a:mode == 2
9105 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009106 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009107 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009108" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009109 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009110 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009111 NetrwKeepj call s:RestoreWinVars()
9112 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009113 unlet s:didsplit
9114
9115 elseif a:mode == 3
9116 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009117 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009118 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009119" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009120 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009121 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009122 NetrwKeepj call s:RestoreWinVars()
9123 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009124 unlet s:didsplit
9125
9126 elseif a:mode == 4
9127 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009129 let eikeep = &ei
9130 let netrw_winnr = winnr()
9131 let netrw_line = line(".")
9132 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009133 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009134 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009135 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009136 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9137 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009138 let &ei = eikeep
9139 let netrw_curdir = s:NetrwTreeDir(0)
9140" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009142 let b:netrw_curdir = netrw_curdir
9143 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009144 NetrwKeepj call s:RestoreWinVars()
9145 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009146 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009147 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009148 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9149 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009150 let &ei= eikeep
9151 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 unlet s:didsplit
9153
9154 elseif a:mode == 5
9155 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009156 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009157 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009158" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009159 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 NetrwKeepj call s:RestoreWinVars()
9162 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009163 unlet s:didsplit
9164
9165 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009166 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009167 endif
9168
Bram Moolenaar97d62492012-11-15 21:28:22 +01009169 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170" call Dret("s:NetrwSplit")
9171endfun
9172
9173" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009174" s:NetrwTgtMenu: {{{2
9175fun! s:NetrwTgtMenu()
9176 if !exists("s:netrw_menucnt")
9177 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009178 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009179" call Dfunc("s:NetrwTgtMenu()")
9180
9181 " the following test assures that gvim is running, has menus available, and has menus enabled.
9182 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9183 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009184" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009185 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9186 endif
9187 if !exists("s:netrw_initbookhist")
9188 call s:NetrwBookHistRead()
9189 endif
9190
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009191 " try to cull duplicate entries
9192 let tgtdict={}
9193
Bram Moolenaarff034192013-04-24 18:51:19 +02009194 " target bookmarked places
9195 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009196" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009197 let cnt= 1
9198 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009199 if has_key(tgtdict,bmd)
9200 let cnt= cnt + 1
9201 continue
9202 endif
9203 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009204 let ebmd= escape(bmd,g:netrw_menu_escape)
9205 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009206" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009207 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 +02009208 let cnt= cnt + 1
9209 endfor
9210 endif
9211
9212 " target directory browsing history
9213 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009214" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009215 let histcnt = 1
9216 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009217 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009218 if exists("g:netrw_dirhist_{histcnt}")
9219 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009220 if has_key(tgtdict,histentry)
9221 let histcnt = histcnt + 1
9222 continue
9223 endif
9224 let tgtdict[histentry] = histcnt
9225 let ehistentry = escape(histentry,g:netrw_menu_escape)
9226" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009227 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 +02009228 endif
9229 let histcnt = histcnt + 1
9230 endwhile
9231 endif
9232 endif
9233" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009234endfun
9235
9236" ---------------------------------------------------------------------
9237" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9238" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009239fun! s:NetrwTreeDir(islocal)
9240" 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 +02009241" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9242" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9243" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009244
Bram Moolenaar8d043172014-01-23 14:24:41 +01009245 if exists("s:treedir")
9246 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
9247 let treedir= s:treedir
9248 unlet s:treedir
9249" call Dret("s:NetrwTreeDir ".treedir)
9250 return treedir
9251 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252
Bram Moolenaar8d043172014-01-23 14:24:41 +01009253 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9254 let b:netrw_curdir= getcwd()
9255 endif
9256 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009257" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009258
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009259 let s:treecurpos= winsaveview()
9260" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9261
9262 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009263" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9264" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009265
9266 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009267 let curline= substitute(getline('.'),"\t -->.*$",'','')
9268 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009269" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009270 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009271" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9272 elseif curline =~ '@$'
9273" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9274 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9275" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 let treedir= ""
9279 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009280
9281 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009282" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9283" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009284" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009285 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009286" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009288" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9289 sil! NetrwKeepj %d _
9290" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009292" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009293" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 endif
9295
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009297 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9298" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009299
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9301" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9302" let newdir = w:netrw_treetop.'/'.potentialdir
9303" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9304" let treedir = s:NetrwTreePath(newdir)
9305" let w:netrw_treetop = newdir
9306" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9307" else
9308" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009310" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009311 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312
9313 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009315" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009317" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009318 return treedir
9319endfun
9320
9321" ---------------------------------------------------------------------
9322" s:NetrwTreeDisplay: recursive tree display {{{2
9323fun! s:NetrwTreeDisplay(dir,depth)
9324" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9325
9326 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009327 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328
9329 " install ../ and shortdir
9330 if a:depth == ""
9331 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009332" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009334 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335 if a:dir == w:netrw_treetop
9336 let shortdir= a:dir
9337 else
9338 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9339 endif
9340 call setline(line("$")+1,a:depth.shortdir)
9341 else
9342 let shortdir= substitute(a:dir,'^.*/','','e')
9343 call setline(line("$")+1,a:depth.shortdir.'/')
9344 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009345" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346
9347 " append a / to dir if its missing one
9348 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009349
9350 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009351 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009352" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009353
Bram Moolenaar85850f32019-07-19 22:05:51 +02009354 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9355 if g:netrw_hide == 1
9356 " hide given patterns
9357 let listhide= split(g:netrw_list_hide,',')
9358" call Decho("listhide=".string(listhide))
9359 for pat in listhide
9360 call filter(w:netrw_treedict[dir],'v:val !~ "'.pat.'"')
9361 endfor
9362
9363 elseif g:netrw_hide == 2
9364 " show given patterns (only)
9365 let listhide= split(g:netrw_list_hide,',')
9366" call Decho("listhide=".string(listhide))
9367 let entries=[]
9368 for entry in w:netrw_treedict[dir]
9369 for pat in listhide
9370 if entry =~ pat
9371 call add(entries,entry)
9372 break
9373 endif
9374 endfor
9375 endfor
9376 let w:netrw_treedict[dir]= entries
9377 endif
9378 if depth != ""
9379 " always remove "." and ".." entries when there's depth
9380 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9381 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9382 endif
9383
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009384" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009386 if dir =~ '/$'
9387 let direntry= substitute(dir.entry,'[@/]$','','e')
9388 else
9389 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9390 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009392 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009394 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009395 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9397 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9398 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9399" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009400 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009401 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009402" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009403 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009404 endif
9405 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009406" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009407
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408" call Dret("NetrwTreeDisplay")
9409endfun
9410
9411" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009412" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9413fun! s:NetrwRefreshTreeDict(dir)
9414" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009415 if !exists("w:netrw_treedict")
9416" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9417 return
9418 endif
9419
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009420 for entry in w:netrw_treedict[a:dir]
9421 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9422" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9423
9424 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9425" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9426 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009427 let liststar = s:NetrwGlob(direntry,'*',1)
9428 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009429 let w:netrw_treedict[direntry] = liststar + listdotstar
9430" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9431
9432 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9433" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9434 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009435 let liststar = s:NetrwGlob(direntry.'/','*',1)
9436 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009437 let w:netrw_treedict[direntry]= liststar + listdotstar
9438" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9439
9440 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9441" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9442 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009443 let liststar = s:NetrwGlob(direntry.'/','*',1)
9444 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009445" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9446
9447 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009448" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009449 endif
9450 endfor
9451" call Dret("s:NetrwRefreshTreeDict")
9452endfun
9453
9454" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009458 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9461" 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>"))
9462" 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 +00009463
9464 " update the treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho("update the treetop",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009466 if !exists("w:netrw_treetop")
9467 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
9470 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009472 endif
9473
Bram Moolenaar446cb832008-06-24 21:56:24 +00009474 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475 " insure that we have a treedict, albeit empty
9476" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009477 let w:netrw_treedict= {}
9478 endif
9479
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009480 " update the dictionary for the current directory
9481" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009482" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009483 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009485" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009486 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009487
9488 " if past banner, record word
9489 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9490 let fname= expand("<cword>")
9491 else
9492 let fname= ""
9493 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009494" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9495" 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 +00009496
9497 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009498 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009499" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009500
9501 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9502 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009503" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009504 1d
9505 endwhile
9506
Bram Moolenaar13600302014-05-22 18:26:40 +02009507 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009508
9509" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009510 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 endif
9512endfun
9513
9514" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009515" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009516" Normally, treetop is w:netrw_treetop, but a
9517" user of the function ( netrw#SetTreetop() )
9518" wipes that out prior to calling this function
9519fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009520" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9521 if line(".") < w:netrw_bannercnt + 2
9522 let treedir= a:treetop
9523 if treedir !~ '/$'
9524 let treedir= treedir.'/'
9525 endif
9526" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9527 return treedir
9528 endif
9529
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009530 let svpos = winsaveview()
9531" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009532 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009533" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9536 let curline= getline('.')
9537" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9538 if curline =~ '/$'
9539" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9540 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9541" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9542 elseif curline =~ '@\s\+-->'
9543" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9544 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9545 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9546" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009547 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009548" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009549 let treedir= ""
9550 endif
9551 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009552" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9553" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009554 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9555 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9556 let treedir= dirname.treedir
9557 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009558" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009559 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009560" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009561 if a:treetop =~ '/$'
9562 let treedir= a:treetop.treedir
9563 else
9564 let treedir= a:treetop.'/'.treedir
9565 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009566" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009567 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009568" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9570 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009571" call Dret("s:NetrwTreePath <".treedir.">")
9572 return treedir
9573endfun
9574
9575" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576" s:NetrwWideListing: {{{2
9577fun! s:NetrwWideListing()
9578
9579 if w:netrw_liststyle == s:WIDELIST
9580" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9581 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009582 " cpf: characters per filename
9583 " fpl: filenames per line
9584 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009585 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009586 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588 let b:netrw_cpf= 0
9589 if line("$") >= w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009590 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9591 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009593 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594" call Dret("NetrwWideListing")
9595 return
9596 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009597 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009598" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599
9600 " determine qty files per line (fpl)
9601 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9602 if w:netrw_fpl <= 0
9603 let w:netrw_fpl= 1
9604 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009606
9607 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009608 " fpc: files per column of wide listing
9609 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9612 let newcolstart = w:netrw_bannercnt + fpc
9613 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009614" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009615 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009616" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009617 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009618 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009619 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 while line("$") >= newcolstart
9621 if newcolend > line("$") | let newcolend= line("$") | endif
9622 let newcolqty= newcolend - newcolstart
9623 exe newcolstart
9624 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009625 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009626 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009627 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h\"ax'.w:netrw_bannercnt.'G$\"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009628 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009629 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009630 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009631 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009632 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009633" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009634 if @* != keepregstar | sil! let @* = keepregstar | endif
9635 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009636 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009637 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9638 NetrwKeepj call histdel("/",-1)
9639 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9640 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009641" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009642 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009643 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009644" 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 +00009645" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009646 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009647 else
9648 if hasmapto("w","n")
9649 sil! nunmap <buffer> w
9650 endif
9651 if hasmapto("b","n")
9652 sil! nunmap <buffer> b
9653 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654 endif
9655
9656endfun
9657
9658" ---------------------------------------------------------------------
9659" s:PerformListing: {{{2
9660fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9662" 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 +02009663" 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>"))
9664 sil! NetrwKeepj %d _
9665" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666
Bram Moolenaar15146672011-10-20 22:22:38 +02009667 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009669 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009670
Bram Moolenaar85850f32019-07-19 22:05:51 +02009671 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009672 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009673" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674
9675" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009676" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009677" endif " Decho
9678
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009680 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9681 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009682" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9683 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 endif
9685
9686 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009687 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009688
9689 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009690 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009691" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009692 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693 if exists("g:netrw_pchk")
9694 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9695 " failure detections.
9696 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009697 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9699 endif
9700 if exists("g:netrw_pchk")
9701 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9702 else
9703 let curdir= b:netrw_curdir
9704 endif
9705 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9706 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9707 else
9708 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009709 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009710 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009711 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009712 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009713" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009714 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009715 let w:netrw_bannercnt= 1
9716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009717" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9718" 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 +00009719
Bram Moolenaar85850f32019-07-19 22:05:51 +02009720 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009721 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009722 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009723 let sortby= sortby." reversed"
9724 endif
9725
9726 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009727 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009729 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009730" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009731 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009732 NetrwKeepj put ='\" Sorted by '.sortby
9733 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009734 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9735 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009736" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009737 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009738 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009739 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9740 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009741 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009742" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009743" 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 +00009744 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745
Bram Moolenaar85850f32019-07-19 22:05:51 +02009746 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009747 if g:netrw_banner
9748 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009749" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009750 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009751 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009752 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009753 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009754 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009755 endif
9756 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009757 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009759 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009760 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009761 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009762
9763 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009764 if g:netrw_banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02009765" 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 +01009766 if g:netrw_list_hide != "" && g:netrw_hide
9767 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009768 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009769 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009770 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009771 endif
9772 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009774 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009775
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009776" 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 +01009777 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009778" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009779 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009780" 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 +01009781 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009782 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009783" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" 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 +00009785 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009786
9787 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009788 if g:netrw_banner
9789 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009790 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009791" 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 +01009792" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" 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 +01009794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009797" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009799 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009801 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009802 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" 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 +01009804" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9805 return
9806 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808
9809 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009810 if !exists("w:netrw_bannercnt")
9811 let w:netrw_bannercnt= 0
9812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9814" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9815" 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 +01009816
Bram Moolenaar5c736222010-01-06 20:54:52 +01009817 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818" call Decho("manipulate directory listing (hide)",'~'.expand("<slnum>"))
9819" 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 +00009820 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009821 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009823 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009826 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009828" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830
Bram Moolenaar5c736222010-01-06 20:54:52 +01009831 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009833 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009834 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009835 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009836 else
9837 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009838 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 endif
9840 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009841
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009843" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009844 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9845 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009847 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009848 " exten: sort by extension
9849 " The histdel(...,-1) calls remove the last search from the search history
9850" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009851 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9852 NetrwKeepj call histdel("/",-1)
9853 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9854 NetrwKeepj call histdel("/",-1)
9855 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9856 NetrwKeepj call histdel("/",-1)
9857 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9858" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009859 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860 " normal direction sorting
9861 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9862 else
9863 " reverse direction sorting
9864 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9865 endif
9866 endif
9867 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9868 NetrwKeepj call histdel("/",-1)
9869
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009871 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009872" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009873 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009874" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009875 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009878 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009880" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009881 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9882 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009883 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884 endif
9885
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009886 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009888 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009890 call histdel("/",-1)
9891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892 endif
9893 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894" 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 +00009895
9896 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9898" 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 +01009899 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" 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 +01009901 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" 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 +00009903
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009904 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009905 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009906" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009907 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 endif
9909
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9913 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009914 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9916 else
9917" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9918" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9919" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9920" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009921 endif
9922
9923 " record previous current directory
9924 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009925" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926
9927 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9929" 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 +01009930 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" 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 +02009932 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" 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 +00009934
9935 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009936" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009937 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" 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 +01009939 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009941 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9942 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009943" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009944" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945
Bram Moolenaar8d043172014-01-23 14:24:41 +01009946 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9948" 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 +01009949" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9950 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 unlet s:treecurpos
9952 endif
9953
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" 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>"))
9955" 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 +00009956" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9957endfun
9958
9959" ---------------------------------------------------------------------
9960" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009961fun! s:SetupNetrwStatusLine(statline)
9962" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9963
9964 if !exists("s:netrw_setup_statline")
9965 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009966" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009967
9968 if !exists("s:netrw_users_stl")
9969 let s:netrw_users_stl= &stl
9970 endif
9971 if !exists("s:netrw_users_ls")
9972 let s:netrw_users_ls= &laststatus
9973 endif
9974
9975 " set up User9 highlighting as needed
9976 let keepa= @a
9977 redir @a
9978 try
9979 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009981 if &bg == "dark"
9982 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9983 else
9984 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9985 endif
9986 endtry
9987 redir END
9988 let @a= keepa
9989 endif
9990
9991 " set up status line (may use User9 highlighting)
9992 " insure that windows have a statusline
9993 " make sure statusline is displayed
9994 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009995 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009998
9999" call Dret("SetupNetrwStatusLine : stl=".&stl)
10000endfun
10001
Bram Moolenaar85850f32019-07-19 22:05:51 +020010002" =========================================
10003" Remote Directory Browsing Support: {{{1
10004" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010005
10006" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010007" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10008" This function assumes that a long listing will be received. Size, time,
10009" and reverse sorts will be requested of the server but not otherwise
10010" enforced here.
10011fun! s:NetrwRemoteFtpCmd(path,listcmd)
10012" 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 +010010013" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010014 " sanity check: {{{3
10015 if !exists("w:netrw_method")
10016 if exists("b:netrw_method")
10017 let w:netrw_method= b:netrw_method
10018 else
10019 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10020" call Dret("NetrwRemoteFtpCmd")
10021 return
10022 endif
10023 endif
10024
10025 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10026 let ffkeep= &ff
10027 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010029
10030 " clear off any older non-banner lines " {{{3
10031 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010032" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10033 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010034
10035 ".........................................
10036 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10037 " ftp + <.netrc>: Method #2
10038 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010039 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010040 endif
10041 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010042 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010043" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010044 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010045 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010046" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010047 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" 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>"))
10049 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 +010010050 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010051" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10052 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 +010010053 endif
10054
10055 ".........................................
10056 elseif w:netrw_method == 3 " {{{3
10057 " ftp + machine,id,passwd,filename: Method #3
10058 setl ff=unix
10059 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010060 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010061 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010062 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010063 endif
10064
10065 " handle userid and password
10066 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010068 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10069 call NetUserPass("ftp:".host)
10070 endif
10071 if exists("g:netrw_uid") && g:netrw_uid != ""
10072 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010073 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010074 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010075 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010076 endif
10077 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010078 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010079 endif
10080 endif
10081
10082 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010084 endif
10085 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010086 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010088 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010089 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010090
10091 " perform ftp:
10092 " -i : turns off interactive prompting from ftp
10093 " -n unix : DON'T use <.netrc>, even though it exists
10094 " -n win32: quit being obnoxious about password
10095 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010097 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010098" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10100" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010101 endif
10102
10103 ".........................................
10104 elseif w:netrw_method == 9 " {{{3
10105 " sftp username@machine: Method #9
10106 " s:netrw_sftp_cmd
10107 setl ff=unix
10108
10109 " restore settings
10110 let &ff= ffkeep
10111" call Dret("NetrwRemoteFtpCmd")
10112 return
10113
10114 ".........................................
10115 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010116 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010117 endif
10118
10119 " cleanup for Windows " {{{3
10120 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010121 sil! NetrwKeepj %s/\r$//e
10122 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010123 endif
10124 if a:listcmd == "dir"
10125 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10127 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10128 NetrwKeepj call histdel("/",-1)
10129 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010130 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 +010010131 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10132 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010133 endif
10134 endif
10135
10136 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10137 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010138 exe 'NetrwKeepj '.w:netrw_bannercnt
10139 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010140 endif
10141 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010142 exe 'NetrwKeepj '.w:netrw_bannercnt
10143 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010144 endif
10145
10146 " restore settings " {{{3
10147 let &ff= ffkeep
10148" call Dret("NetrwRemoteFtpCmd")
10149endfun
10150
10151" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010152" s:NetrwRemoteListing: {{{2
10153fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010154" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010155
Bram Moolenaara6878372014-03-22 21:02:50 +010010156 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10157 let w:netrw_bannercnt= s:bannercnt
10158 endif
10159 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10160 let w:netrw_bannercnt= s:bannercnt
10161 endif
10162
Bram Moolenaar446cb832008-06-24 21:56:24 +000010163 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010164
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165 " sanity check:
10166 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010168 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010170 if !exists("g:netrw_quiet")
10171 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10172 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010173 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010174" call Dret("s:NetrwRemoteListing -1")
10175 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010176 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010177
Bram Moolenaar8d043172014-01-23 14:24:41 +010010178 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010180 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010181 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010182 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 +000010183 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010184 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 +000010185 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010186 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010187
Bram Moolenaar85850f32019-07-19 22:05:51 +020010188 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010189" call Dret("s:NetrwRemoteListing -1")
10190 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010191 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010192" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010193
Bram Moolenaar446cb832008-06-24 21:56:24 +000010194 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010195" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010196 let w:netrw_method= b:netrw_method
10197 endif
10198
Bram Moolenaar13600302014-05-22 18:26:40 +020010199 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010200 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010201" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010202 let s:method = "ftp"
10203 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010204 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010205 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010206 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010207 let listcmd= g:netrw_ftp_sizelist_cmd
10208 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010209" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010210 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010211" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010212
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 " report on missing file or directory messages
10214 if search('[Nn]o such file or directory\|Failed to change directory')
10215 let mesg= getline(".")
10216 if exists("w:netrw_bannercnt")
10217 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010218 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010219 setl noma
10220 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010221 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010222 call netrw#ErrorMsg(s:WARNING,mesg,96)
10223" call Dret("s:NetrwRemoteListing : -1")
10224 return -1
10225 endif
10226
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010227 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 +000010228 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010229" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010230 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010231
10232 " cleanup
10233 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010234 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10235 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010236 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010237 sil! NetrwKeepj %s/\r$//e
10238 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010239
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010240 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010241 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010242 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010243 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010244" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010245 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010246" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010247 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010248 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010249 exe "sil! NetrwKeepj ".line1
10250 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010251
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010252" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010253 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010255 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10256 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010257 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010258" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10260 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10261 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10262 NetrwKeepj call histdel("/",-1)
10263 NetrwKeepj call histdel("/",-1)
10264 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010265 endif
10266 endif
10267
Bram Moolenaar13600302014-05-22 18:26:40 +020010268 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010269 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010270" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010271 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010272" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010273 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010274" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10275 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010276 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10278 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10279 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10280 NetrwKeepj call histdel("/",-1)
10281 NetrwKeepj call histdel("/",-1)
10282 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010283 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10285 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010286 endif
10287 else
10288 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010289" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010290 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010291 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010292" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10293 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10294" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010295 endif
10296 endif
10297
10298 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010299 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010300" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010301 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10302 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010303 endif
10304 endif
10305
10306 if w:netrw_liststyle == s:LONGLIST
10307 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010308" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010309
10310 if s:method == "ftp"
10311 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010312 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010313 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010314 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010315 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010316 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010317 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010318 sil! NetrwKeepj 1
10319 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010320 let line2= line(".")
10321 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010322 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010323 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010324 endif
10325 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010326 exe "sil! NetrwKeepj ".line1
10327 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010328 endif
10329
10330 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010331" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 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 +000010333 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010334" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010335 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010336 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010337 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10338 NetrwKeepj call histdel("/",-1)
10339 NetrwKeepj call histdel("/",-1)
10340 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010341 endif
10342 endif
10343
10344" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010345" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010346" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010347
10348" call Dret("s:NetrwRemoteListing 0")
10349 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010350endfun
10351
Bram Moolenaar446cb832008-06-24 21:56:24 +000010352" ---------------------------------------------------------------------
10353" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10354fun! s:NetrwRemoteRm(usrhost,path) range
10355" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010356" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010357 let svpos= winsaveview()
10358" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010359
10360 let all= 0
10361 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10362 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010363" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364 for fname in s:netrwmarkfilelist_{bufnr("%")}
10365 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010366 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010368 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 let all= 1
10370 endif
10371 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010372 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373
10374 else
10375 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010376" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377
10378 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379 let keepsol = &l:sol
10380 setl nosol
10381 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382
10383 " remove multiple files and directories
10384 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010385 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010387 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010389 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 let all= 1
10391 endif
10392 let ctr= ctr + 1
10393 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010394 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 endif
10396
10397 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010399 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010400" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10401 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402
10403" call Dret("s:NetrwRemoteRm")
10404endfun
10405
10406" ---------------------------------------------------------------------
10407" s:NetrwRemoteRmFile: {{{2
10408fun! s:NetrwRemoteRmFile(path,rmfile,all)
10409" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10410
10411 let all= a:all
10412 let ok = ""
10413
10414 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10415 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010416" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 if !all
10418 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420 call inputsave()
10421 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10422 call inputrestore()
10423 echohl NONE
10424 if ok == ""
10425 let ok="no"
10426 endif
10427 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010428 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 let all= 1
10430 endif
10431 endif
10432
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010433 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010434" 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 +000010435 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010436" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010438 if path =~ '^\a\{3,}://'
10439 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010441 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10443 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010444" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449 let ok="q"
10450 else
10451 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010452" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10453" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10454" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010456 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462 if v:shell_error != 0
10463 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010464 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 +010010465 else
10466 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10467 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010468 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 endif
10473 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010474 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 endif
10477
10478 else
10479 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 if !all
10482 call inputsave()
10483 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10484 call inputrestore()
10485 if ok == ""
10486 let ok="no"
10487 endif
10488 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010489 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 let all= 1
10491 endif
10492 endif
10493
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010494 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010495 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 else
10498 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010499 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10500" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010501 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503
10504 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010505" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10506 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10507" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010508 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010509" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510
10511 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513 endif
10514 endif
10515 endif
10516
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010517 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 endif
10520 endif
10521
10522" call Dret("s:NetrwRemoteRmFile ".ok)
10523 return ok
10524endfun
10525
10526" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527" s:NetrwRemoteRename: rename a remote file or directory {{{2
10528fun! s:NetrwRemoteRename(usrhost,path) range
10529" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10530
10531 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010532 let svpos = winsaveview()
10533" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 let ctr = a:firstline
10535 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10536
10537 " rename files given by the markfilelist
10538 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10539 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 if exists("subfrom")
10542 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010543" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 else
10545 call inputsave()
10546 let newname= input("Moving ".oldname." to : ",oldname)
10547 call inputrestore()
10548 if newname =~ '^s/'
10549 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10550 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10551 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010552" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 endif
10554 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010557 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559 let oldname= s:ShellEscape(a:path.oldname)
10560 let newname= s:ShellEscape(a:path.newname)
10561" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010562 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 endif
10564
10565 endfor
10566 call s:NetrwUnMarkFile(1)
10567
10568 else
10569
10570 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010571 let keepsol= &l:sol
10572 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010574 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575
10576 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578
10579 call inputsave()
10580 let newname= input("Moving ".oldname." to : ",oldname)
10581 call inputrestore()
10582
10583 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10584 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10585 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586 let oldname= s:ShellEscape(a:path.oldname)
10587 let newname= s:ShellEscape(a:path.newname)
10588" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010589 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590 endif
10591
10592 let ctr= ctr + 1
10593 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010594 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 endif
10596
10597 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010598 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010599" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10600 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601
10602" call Dret("NetrwRemoteRename")
10603endfun
10604
Bram Moolenaar85850f32019-07-19 22:05:51 +020010605" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606" Local Directory Browsing Support: {{{1
10607" ==========================================
10608
10609" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010610" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010611" Should accept: file://localhost/etc/fstab
10612" file:///etc/fstab
10613" file:///c:/WINDOWS/clock.avi
10614" file:///c|/WINDOWS/clock.avi
10615" file://localhost/c:/WINDOWS/clock.avi
10616" file://localhost/c|/WINDOWS/clock.avi
10617" file://c:/foo.txt
10618" file:///c:/foo.txt
10619" 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 +020010620fun! netrw#FileUrlEdit(fname)
10621" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010622 let fname = a:fname
10623 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010625 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010627 endif
10628 if (has("win32") || has("win95") || has("win64") || has("win16"))
10629 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010631 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010633 endif
10634 endif
10635 let fname2396 = netrw#RFC2396(fname)
10636 let fname2396e= fnameescape(fname2396)
10637 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10638 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010640 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010642 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10643 endif
10644 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010645
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10647" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010648 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010649 exe 'NetrwKeepj keepalt edit '.plainfname
10650 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10651
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652" 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 +020010653" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010654 exe "sil doau BufReadPost ".fname2396e
10655endfun
10656
10657" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658" netrw#LocalBrowseCheck: {{{2
10659fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010660 " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(),
10661 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10662 "
10663 " unfortunate interaction -- split window debugging can't be used here, must use
10664 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10665 " another call to LocalBrowseCheck() when attempts to write
10666 " to the DBG buffer are made.
10667 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 " The &ft == "netrw" test was installed because the BufEnter event
10669 " would hit when re-entering netrw windows, creating unexpected
10670 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010671" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010672" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010673" 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 +020010674" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10676" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010677
Bram Moolenaar97d62492012-11-15 21:28:22 +010010678 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679 if isdirectory(s:NetrwFile(a:dirname))
10680" 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 +010010681
Bram Moolenaar97d62492012-11-15 21:28:22 +010010682 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10684" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010685 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010686
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010689 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010690
Bram Moolenaar5c736222010-01-06 20:54:52 +010010691 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010692" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010693 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010694 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" 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 +010010697" call Dret("netrw#LocalBrowseCheck")
10698 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010700
Bram Moolenaar85850f32019-07-19 22:05:51 +020010701 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010702 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10703 " AND IF the listing style is not a tree listing
10704 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010706 let ibuf = 1
10707 let buflast = bufnr("$")
10708 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010709 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10710 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010711 endif
10712 let ibuf= ibuf + 1
10713 endwhile
10714 endif
10715 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716" 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>"))
10717" 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 +000010718 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010719" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010720endfun
10721
10722" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010723" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724" performed any shell command. The idea is to cause all local-browsing
10725" buffers to be refreshed after a user has executed some shell command,
10726" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010727fun! s:LocalBrowseRefresh()
10728" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10730" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010731
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732 " determine which buffers currently reside in a tab
10733 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010734" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735 return
10736 endif
10737 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010738" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739 return
10740 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010741 if exists("s:netrw_events") && s:netrw_events == 1
10742 " s:LocalFastBrowser gets called (indirectly) from a
10743 let s:netrw_events= 2
10744" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10745 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010746 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 let itab = 1
10748 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010749 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010750 while itab <= tabpagenr("$")
10751 let buftablist = buftablist + tabpagebuflist()
10752 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010753 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10756" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10758 " | refresh any netrw window
10759 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010760 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 let ibl = 0
10762 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10765 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010766 " (ibuf not shown in a current window AND
10767 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010768" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10769 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 continue
10773 elseif index(tabpagebuflist(),ibuf) != -1
10774 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010775" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010777 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010778 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10779 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10780 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010783 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10784 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10785 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010786 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010787 endif
10788 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010789" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010790 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010791" call Decho("restore window: win_gotoid(".curwinid.")")
10792 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010793 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794
Bram Moolenaara6878372014-03-22 21:02:50 +010010795" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010796endfun
10797
10798" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010799" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10800"
10801" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010802" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010803" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10804" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010806"
10807" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10808" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010809" (re-using a buffer may not be as accurate)
10810"
10811" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
10812" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10813" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10814" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10815" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010816fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010817" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10818" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10819" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10820" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821
10822 " initialize browselist, a list of buffer numbers that the local browser has used
10823 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010824" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 let s:netrw_browselist= []
10826 endif
10827
10828 " append current buffer to fastbrowse list
10829 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010830" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 endif
10834
10835 " enable autocmd events to handle refreshing/removing local browser buffers
10836 " If local browse buffer is currently showing: refresh it
10837 " If local browse buffer is currently hidden : wipe it
10838 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10839 " =1 : medium speed, re-use directory listing for remote only
10840 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010841 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10842 let s:netrw_events= 1
10843 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 au!
10845 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010847 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010850 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 endif
10852 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853
10854 " user must have changed fastbrowse to its fast setting, so remove
10855 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010856 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010858 unlet s:netrw_events
10859 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 au!
10861 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010862 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010863 endif
10864
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010866endfun
10867
10868" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010869" s:LocalListing: does the job of "ls" for local directories {{{2
10870fun! s:LocalListing()
10871" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10873" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10874" 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 +010010875
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876" 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
10877" 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
10878" 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 +010010879
10880 " get the list of files contained in the current directory
10881 let dirname = b:netrw_curdir
10882 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010883 let filelist = s:NetrwGlob(dirname,"*",0)
10884 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010886
10887 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010889 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10890 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010891" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010892 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010894 endif
10895
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010896" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010898" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010899
10900 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10901 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10902 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10904" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" 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 +010010907
10908 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho(" ",'~'.expand("<slnum>"))
10910" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010911
10912 if getftype(filename) == "link"
10913 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010914" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010915 let pfile= filename."@"
10916
10917 elseif getftype(filename) == "socket"
10918 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010919" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010920 let pfile= filename."="
10921
10922 elseif getftype(filename) == "fifo"
10923 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010925 let pfile= filename."|"
10926
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010927 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010928 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010930 let pfile= filename."/"
10931
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010932 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010933 if (has("win32") || has("win95") || has("win64") || has("win16"))
10934 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10935 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010937 let pfile= filename."*"
10938 else
10939 " normal file
10940 let pfile= filename
10941 endif
10942 elseif executable(filename)
10943 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010944" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010945 let pfile= filename."*"
10946 else
10947 " normal file
10948 let pfile= filename
10949 endif
10950
10951 else
10952 " normal file
10953 let pfile= filename
10954 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010956
10957 if pfile =~ '//$'
10958 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010959" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010960 endif
10961 let pfile= strpart(pfile,dirnamelen)
10962 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
10964" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010965
10966 if w:netrw_liststyle == s:LONGLIST
10967 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010968 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010969 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010970 let sz= s:NetrwHumanReadable(sz)
10971 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010972 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
10973 let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010974" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010975 endif
10976
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010977 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010978 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010979 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010980" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010981 let t = getftime(filename)
10982 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010010983" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010984 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010985 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010986
10987 elseif g:netrw_sort_by =~ "^s"
10988 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010990 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010991 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010992 let sz= s:NetrwHumanReadable(sz)
10993 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010994 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010996 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010997 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010998
10999 else
11000 " sort by name
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011001" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011002 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011003 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011004" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011005 endfor
11006
11007 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011008 sil! NetrwKeepj g/^$/d
11009 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011010 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011012 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11013
11014" call Dret("s:LocalListing")
11015endfun
11016
11017" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011018" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11019fun! s:NetrwLocalExecute(cmd)
11020" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11021 let ykeep= @@
11022 " sanity check
11023 if !executable(a:cmd)
11024 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11025 let @@= ykeep
11026" call Dret("s:NetrwLocalExecute")
11027 return
11028 endif
11029
11030 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011034
11035 " strip any ansi escape sequences off
11036 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11037
11038 " show user the result(s)
11039 echomsg result
11040 let @@= ykeep
11041
11042" call Dret("s:NetrwLocalExecute")
11043endfun
11044
11045" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011046" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011047fun! s:NetrwLocalRename(path) range
11048" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11049
11050 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051 let ykeep = @@
11052 let ctr = a:firstline
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011053 let svpos = winsaveview()
11054" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055
11056 " rename files given by the markfilelist
11057 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11058 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011059" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011060 if exists("subfrom")
11061 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011062" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011063 else
11064 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067 if newname =~ ''
11068 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11069 let newname = substitute(newname,'^.*','','')
11070 elseif newname =~ ''
11071 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11072 let newname = substitute(newname,'[^/]*','','')
11073 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074 if newname =~ '^s/'
11075 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11076 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078 let newname = substitute(oldname,subfrom,subto,'')
11079 endif
11080 endif
11081 call rename(oldname,newname)
11082 endfor
11083 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084
Bram Moolenaar97d62492012-11-15 21:28:22 +010011085 else
11086
11087 " attempt to rename files/directories
11088 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011089 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011090
11091 " sanity checks
11092 if line(".") < w:netrw_bannercnt
11093 let ctr= ctr + 1
11094 continue
11095 endif
11096 let curword= s:NetrwGetWord()
11097 if curword == "./" || curword == "../"
11098 let ctr= ctr + 1
11099 continue
11100 endif
11101
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011102 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011103 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011105
11106 call inputsave()
11107 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11108 call inputrestore()
11109
11110 call rename(oldname,newname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011112
11113 let ctr= ctr + 1
11114 endwhile
11115 endif
11116
11117 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011119 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011120" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11121 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011122 let @@= ykeep
11123
11124" call Dret("NetrwLocalRename")
11125endfun
11126
11127" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011128" s:NetrwLocalRm: {{{2
11129fun! s:NetrwLocalRm(path) range
11130" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011132
11133 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011134 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011135 let ret = 0
11136 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011137 let svpos = winsaveview()
11138" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011139
11140 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11141 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011143 for fname in s:netrwmarkfilelist_{bufnr("%")}
11144 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011145 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011146 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011147 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011148 let all= 1
11149 endif
11150 endfor
11151 call s:NetrwUnMarkFile(1)
11152
11153 else
11154 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011156
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157 let keepsol= &l:sol
11158 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011159 let ctr = a:firstline
11160 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011161 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011162
11163 " sanity checks
11164 if line(".") < w:netrw_bannercnt
11165 let ctr= ctr + 1
11166 continue
11167 endif
11168 let curword= s:NetrwGetWord()
11169 if curword == "./" || curword == "../"
11170 let ctr= ctr + 1
11171 continue
11172 endif
11173 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011174 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011175 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011176 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011177 let all= 1
11178 endif
11179 let ctr= ctr + 1
11180 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011181 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011182 endif
11183
11184 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011185" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011186 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011187 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011188" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11189 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011190 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011191 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011192
11193" call Dret("s:NetrwLocalRm")
11194endfun
11195
11196" ---------------------------------------------------------------------
11197" s:NetrwLocalRmFile: remove file fname given the path {{{2
11198" Give confirmation prompt unless all==1
11199fun! s:NetrwLocalRmFile(path,fname,all)
11200" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011201
Bram Moolenaar446cb832008-06-24 21:56:24 +000011202 let all= a:all
11203 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011204 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11206" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011207
11208 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11209 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011210" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011211 if !all
11212 echohl Statement
11213 call inputsave()
11214 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11215 call inputrestore()
11216 echohl NONE
11217 if ok == ""
11218 let ok="no"
11219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011221 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011223 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011224 let all= 1
11225 endif
11226 endif
11227
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011228 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011229 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011230" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011231 endif
11232
11233 else
11234 " attempt to remove directory
11235 if !all
11236 echohl Statement
11237 call inputsave()
11238 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11239 call inputrestore()
11240 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11241 if ok == ""
11242 let ok="no"
11243 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011244 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011245 let all= 1
11246 endif
11247 endif
11248 let rmfile= substitute(rmfile,'[\/]$','','e')
11249
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011250 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011251 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011252" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11253 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11254" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011255
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011256 if v:shell_error != 0
11257" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11258 let errcode= s:NetrwDelete(rmfile)
11259" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011260
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011261 if errcode != 0
11262 if has("unix")
11263" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11264 call system("rm ".s:ShellEscape(rmfile))
11265 if v:shell_error != 0 && !exists("g:netrw_quiet")
11266 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11267 let ok="no"
11268 endif
11269 elseif !exists("g:netrw_quiet")
11270 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011271 let ok="no"
11272 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011273 endif
11274 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011275 else
11276 if delete(rmfile,"d")
11277 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11278 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011279 endif
11280 endif
11281 endif
11282
11283" call Dret("s:NetrwLocalRmFile ".ok)
11284 return ok
11285endfun
11286
Bram Moolenaar85850f32019-07-19 22:05:51 +020011287" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011288" Support Functions: {{{1
11289
Bram Moolenaar488c6512005-08-11 20:09:58 +000011290" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011291" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11292" 0: marked file list of current buffer
11293" 1: marked file target
11294fun! netrw#Access(ilist)
11295 if a:ilist == 0
11296 if exists("s:netrwmarkfilelist_".bufnr('%'))
11297 return s:netrwmarkfilelist_{bufnr('%')}
11298 else
11299 return "no-list-buf#".bufnr('%')
11300 endif
11301 elseif a:ilist == 1
11302 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011303 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011304endfun
11305
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011306" ---------------------------------------------------------------------
11307" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11308fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011309 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011310endfun
11311
Bram Moolenaara6878372014-03-22 21:02:50 +010011312" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011313" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11314" I expect this function to be used in
11315" :PChkAssert netrw#Expose("netrwmarkfilelist")
11316" for example.
11317fun! netrw#Expose(varname)
11318" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011319 if exists("s:".a:varname)
11320 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011321" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011322 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011323" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011324 if type(retval) == 3
11325 let retval = copy(retval)
11326 let i = 0
11327 while i < len(retval)
11328 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11329 let i = i + 1
11330 endwhile
11331 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011332" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011333 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011334 else
11335" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011336 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011337 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011338" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011339 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011340 endif
11341
11342" call Dret("netrw#Expose ".string(retval))
11343 return retval
11344endfun
11345
11346" ---------------------------------------------------------------------
11347" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11348fun! netrw#Modify(varname,newvalue)
11349" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11350 exe "let s:".a:varname."= ".string(a:newvalue)
11351" call Dret("netrw#Modify")
11352endfun
11353
11354" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011355" netrw#RFC2396: converts %xx into characters {{{2
11356fun! netrw#RFC2396(fname)
11357" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11358 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11359" call Dret("netrw#RFC2396 ".fname)
11360 return fname
11361endfun
11362
11363" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011364" netrw#UserMaps: supports user-specified maps {{{2
11365" see :help function()
11366"
11367" g:Netrw_UserMaps is a List with members such as:
11368" [[keymap sequence, function reference],...]
11369"
11370" The referenced function may return a string,
11371" refresh : refresh the display
11372" -other- : this string will be executed
11373" or it may return a List of strings.
11374"
11375" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011376" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011377" Related functions:
11378" netrw#Expose(varname) -- see s:varname variables
11379" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11380" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11381fun! netrw#UserMaps(islocal)
11382" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11383" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11384
11385 " set up usermaplist
11386 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11387" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11388 for umap in g:Netrw_UserMaps
11389" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11390" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11391 " if umap[0] is a string and umap[1] is a string holding a function name
11392 if type(umap[0]) == 1 && type(umap[1]) == 1
11393" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11394 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11395 else
11396 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11397 endif
11398 endfor
11399 endif
11400" call Dret("netrw#UserMaps")
11401endfun
11402
11403" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011404" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11405fun! netrw#WinPath(path)
11406" call Dfunc("netrw#WinPath(path<".a:path.">)")
11407 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11408 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011409 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011410 " remove trailing slash (Win95)
11411 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11412 " remove escaped spaces
11413 let path = substitute(path, '\ ', ' ', 'g')
11414 " convert slashes to backslashes
11415 let path = substitute(path, '/', '\', 'g')
11416 else
11417 let path= a:path
11418 endif
11419" call Dret("netrw#WinPath <".path.">")
11420 return path
11421endfun
11422
11423" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011424" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11425" cb : bl2mf=0 add marked files to buffer list
11426" cB : bl2mf=1 use bufferlist to mark files
11427" (mnemonic: cb = copy (marked files) to buffer list)
11428fun! s:NetrwBadd(islocal,bl2mf)
11429" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11430 if a:bl2mf
11431 " cB: add buffer list to marked files
11432 redir => bufl
11433 ls
11434 redir END
11435 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11436 for fname in bufl
11437 call s:NetrwMarkFile(a:islocal,fname)
11438 endfor
11439 else
11440 " cb: add marked files to buffer list
11441 for fname in s:netrwmarkfilelist_{bufnr("%")}
11442" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11443 exe "badd ".fnameescape(fname)
11444 endfor
11445 let curbufnr = bufnr("%")
11446 let curdir = s:NetrwGetCurdir(a:islocal)
11447 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11448 endif
11449" call Dret("s:NetrwBadd")
11450endfun
11451
11452" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011453" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11454fun! s:ComposePath(base,subdir)
11455" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11456
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011457 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011458" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011459 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011460 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011461 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011462 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011463 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011464 endif
11465
Bram Moolenaar85850f32019-07-19 22:05:51 +020011466 " COMBAK: test on windows with changing to root directory: :e C:/
11467 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011468" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011469 let ret= a:subdir
11470
Bram Moolenaar85850f32019-07-19 22:05:51 +020011471 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011472" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011473 if a:base =~ '[/\\]$'
11474 let ret= a:base.a:subdir
11475 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011476 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011477 endif
11478
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011479 elseif a:base =~ '^\a\{3,}://'
11480" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011481 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11482 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11483 if a:subdir == '../'
11484 if curpath =~ '[^/]/[^/]\+/$'
11485 let curpath= substitute(curpath,'[^/]\+/$','','')
11486 else
11487 let curpath=""
11488 endif
11489 let ret= urlbase.curpath
11490 else
11491 let ret= urlbase.curpath.a:subdir
11492 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011493" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11494" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11495" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011496
11497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011498" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011499 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11500 if a:base =~ '^//'
11501 " keeping initial '//' for the benefit of network share listing support
11502 let ret= '/'.ret
11503 endif
11504 let ret= simplify(ret)
11505 endif
11506
11507" call Dret("s:ComposePath ".ret)
11508 return ret
11509endfun
11510
11511" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011512" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11513" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11514fun! s:DeleteBookmark(fname)
11515" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11516 call s:MergeBookmarks()
11517
11518 if exists("g:netrw_bookmarklist")
11519 let indx= index(g:netrw_bookmarklist,a:fname)
11520 if indx == -1
11521 let indx= 0
11522 while indx < len(g:netrw_bookmarklist)
11523 if g:netrw_bookmarklist[indx] =~ a:fname
11524 call remove(g:netrw_bookmarklist,indx)
11525 let indx= indx - 1
11526 endif
11527 let indx= indx + 1
11528 endwhile
11529 else
11530 " remove exact match
11531 call remove(g:netrw_bookmarklist,indx)
11532 endif
11533 endif
11534
11535" call Dret("s:DeleteBookmark")
11536endfun
11537
11538" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011539" s:FileReadable: o/s independent filereadable {{{2
11540fun! s:FileReadable(fname)
11541" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11542
11543 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011544 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011545 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011546 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011547 endif
11548
11549" call Dret("s:FileReadable ".ret)
11550 return ret
11551endfun
11552
11553" ---------------------------------------------------------------------
11554" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11555" Places correct suffix on end of temporary filename,
11556" using the suffix provided with fname
11557fun! s:GetTempfile(fname)
11558" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11559
11560 if !exists("b:netrw_tmpfile")
11561 " get a brand new temporary filename
11562 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011563" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011564
Bram Moolenaarc236c162008-07-13 17:41:49 +000011565 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011566" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011567
Bram Moolenaar9964e462007-05-05 17:54:07 +000011568 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011569 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11570" 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 +010011571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011572" call Dret("s:GetTempfile getcwd<".getcwd().">")
11573 return ""
11574 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011575
Bram Moolenaar9964e462007-05-05 17:54:07 +000011576 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011577 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011578" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011579
Bram Moolenaar9964e462007-05-05 17:54:07 +000011580 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011581 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011582 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011583 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011584 if !exists("+shellslash") || !&ssl
11585 let tmpfile = substitute(tmpfile,'/','\','g')
11586 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011587 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011588 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011589 endif
11590 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011592 else
11593 " re-use temporary filename
11594 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011595" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011596 endif
11597
11598 " use fname's suffix for the temporary file
11599 if a:fname != ""
11600 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011601" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011602 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011603 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011604 elseif a:fname =~ '.txz$'
11605 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011606 else
11607 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11608 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011610 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011611" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011612 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011614 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11615 endif
11616 endif
11617
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011618" 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 +000011619" call Dret("s:GetTempfile <".tmpfile.">")
11620 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011621endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011622
11623" ---------------------------------------------------------------------
11624" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011625" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011626fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011627" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011628 if s:user == ""
11629 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11630 else
11631 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11632 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011633 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011634 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011635 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011636 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011637 else
11638 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11639 endif
11640" call Dret("s:MakeSshCmd <".sshcmd.">")
11641 return sshcmd
11642endfun
11643
11644" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011645" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11646fun! s:MakeBookmark(fname)
11647" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11648
11649 if !exists("g:netrw_bookmarklist")
11650 let g:netrw_bookmarklist= []
11651 endif
11652
11653 if index(g:netrw_bookmarklist,a:fname) == -1
11654 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011655 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011656 call add(g:netrw_bookmarklist,a:fname.'/')
11657 elseif a:fname !~ '/'
11658 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11659 else
11660 call add(g:netrw_bookmarklist,a:fname)
11661 endif
11662 call sort(g:netrw_bookmarklist)
11663 endif
11664
11665" call Dret("s:MakeBookmark")
11666endfun
11667
11668" ---------------------------------------------------------------------
11669" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11670fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011671" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011672 " get bookmarks from .netrwbook file
11673 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011674 if filereadable(s:NetrwFile(savefile))
11675" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011676 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011677" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011678 NetrwKeepj call delete(savefile)
11679 endif
11680" call Dret("s:MergeBookmarks")
11681endfun
11682
11683" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011684" s:NetrwBMShow: {{{2
11685fun! s:NetrwBMShow()
11686" call Dfunc("s:NetrwBMShow()")
11687 redir => bmshowraw
11688 menu
11689 redir END
11690 let bmshowlist = split(bmshowraw,'\n')
11691 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011692 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011693 if bmshowfuncs != []
11694 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011695 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011696 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011698 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011699 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011700" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11701endfun
11702
11703" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011704" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
11705fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011706 if !exists("w:netrw_liststyle")
11707 let w:netrw_liststyle= g:netrw_liststyle
11708 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011709" 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 +020011710
11711 if &ft != "netrw"
11712 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11713 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011715 let &l:cursorline = s:netrw_usercul
11716 let &l:cursorcolumn = s:netrw_usercuc
11717
11718 elseif g:netrw_cursor == 4
11719 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011720" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011721 setl cursorline
11722 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011723
11724 elseif g:netrw_cursor == 3
11725 " thin-long-tree: cursorline, user's cursorcolumn
11726 " wide : cursorline, cursorcolumn
11727 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011728" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011729 setl cursorline
11730 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011731 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011732" 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 +020011733 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011734 let &l:cursorcolumn = s:netrw_usercuc
11735 endif
11736
11737 elseif g:netrw_cursor == 2
11738 " thin-long-tree: cursorline, user's cursorcolumn
11739 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011740" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011741 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020011742 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011743
11744 elseif g:netrw_cursor == 1
11745 " thin-long-tree: user's cursorline, user's cursorcolumn
11746 " wide : cursorline, user's cursorcolumn
11747 let &l:cursorcolumn = s:netrw_usercuc
11748 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011749" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011750 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011751 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011752" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011753 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011754 endif
11755
11756 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011757 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011759 let &l:cursorline = s:netrw_usercul
11760 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011761 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011762
11763" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011764endfun
11765
11766" ---------------------------------------------------------------------
11767" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11768fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011769" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011770 if exists("s:netrw_usercul")
11771 let &l:cursorline = s:netrw_usercul
11772 endif
11773 if exists("s:netrw_usercuc")
11774 let &l:cursorcolumn = s:netrw_usercuc
11775 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011776" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11777endfun
11778
11779" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011780" s:NetrwDelete: Deletes a file. {{{2
11781" Uses Steve Hall's idea to insure that Windows paths stay
11782" acceptable. No effect on Unix paths.
11783" Examples of use: let result= s:NetrwDelete(path)
11784fun! s:NetrwDelete(path)
11785" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11786
Bram Moolenaar5c736222010-01-06 20:54:52 +010011787 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011788 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11789 if exists("+shellslash")
11790 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011791 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011792 let result = delete(path)
11793 let &shellslash = sskeep
11794 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011796 let result= delete(path)
11797 endif
11798 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011800 let result= delete(path)
11801 endif
11802 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011803 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011804 endif
11805
11806" call Dret("s:NetrwDelete ".result)
11807 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011808endfun
11809
11810" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011811" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011812fun! s:NetrwEnew(...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011813" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011817" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011818 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11819 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11820 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11821 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11822 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11823 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11824 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11825 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11826 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11827 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11828 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11829 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11830 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11831 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11832 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11833 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11834
Bram Moolenaar85850f32019-07-19 22:05:51 +020011835 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011837 " when tree listing uses file TreeListing... a new buffer is made.
11838 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011839 " COMBAK: this causes a problem, see P43
11840" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011841 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011842 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011843 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011844" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011845 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846
Bram Moolenaar446cb832008-06-24 21:56:24 +000011847 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011848" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011849 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11850 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11851 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11852 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11853 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11854 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11855 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11856 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11857 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11858 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11859 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11860 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11861 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11862 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11863 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11864 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11865
Bram Moolenaar5c736222010-01-06 20:54:52 +010011866 if a:0 > 0
11867 let b:netrw_curdir= a:1
11868 if b:netrw_curdir =~ '/$'
11869 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011870 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011871 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011872 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011873 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11874 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011875 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011876 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011877 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011878 endif
11879 endif
11880
Bram Moolenaar8d043172014-01-23 14:24:41 +010011881" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011882endfun
11883
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011884" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011885" s:NetrwExe: executes a string using "!" {{{2
11886fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011887" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011888 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020011889" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011890 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11891 set shell& shellcmdflag& shellxquote& shellxescape&
11892 set shellquote& shellpipe& shellredir& shellslash&
11893 exe a:cmd
11894 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11895 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011896" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 exe a:cmd
11898 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011899" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011900endfun
11901
11902" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011903" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11904fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011905 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011906" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011907 let curbuf = bufnr("%")
11908 let curwin = winnr()
11909 let iwin = 1
11910 while iwin <= winnr("$")
11911 exe iwin."wincmd w"
11912 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11913 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11914 let winvars= w:
11915 break
11916 endif
11917 let iwin= iwin + 1
11918 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011919 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011920 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011921" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011922 for k in keys(winvars)
11923 let w:{k}= winvars[k]
11924 endfor
11925 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011926" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011927 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011928endfun
11929
Bram Moolenaara6878372014-03-22 21:02:50 +010011930" ---------------------------------------------------------------------
11931" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011932" Returns: 0=success
11933" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011934fun! s:NetrwLcd(newdir)
11935" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
11936
Bram Moolenaar85850f32019-07-19 22:05:51 +020011937 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011938 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011939 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011940 catch /^Vim\%((\a\+)\)\=:E344/
11941 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11942 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011943 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011944 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11945 " forward slashes by earlier code; so check for both.
11946 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
11947 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11948 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011949 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011950 endif
11951 endif
11952 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011953 let err472= 1
11954 endtry
11955
11956 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011957 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11958 if exists("w:netrw_prvdir")
11959 let a:newdir= w:netrw_prvdir
11960 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011961 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011963 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964" 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 +010011965 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011967" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11968 return -1
11969 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011970
Bram Moolenaar85850f32019-07-19 22:05:51 +020011971" call Dret("s:NetrwLcd 0")
11972 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011973endfun
11974
Bram Moolenaar9964e462007-05-05 17:54:07 +000011975" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011976" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11977" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11978fun! s:NetrwSaveWordPosn()
11979" call Dfunc("NetrwSaveWordPosn()")
11980 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11981" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11982endfun
11983
11984" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011985" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11986" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11987fun! s:NetrwHumanReadable(sz)
11988" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11989
11990 if g:netrw_sizestyle == 'h'
11991 if a:sz >= 1000000000
11992 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11993 elseif a:sz >= 10000000
11994 let sz = printf("%d",a:sz/1000000)."m"
11995 elseif a:sz >= 1000000
11996 let sz = printf("%.1f",a:sz/1000000.0)."m"
11997 elseif a:sz >= 10000
11998 let sz = printf("%d",a:sz/1000)."k"
11999 elseif a:sz >= 1000
12000 let sz = printf("%.1f",a:sz/1000.0)."k"
12001 else
12002 let sz= a:sz
12003 endif
12004
12005 elseif g:netrw_sizestyle == 'H'
12006 if a:sz >= 1073741824
12007 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12008 elseif a:sz >= 10485760
12009 let sz = printf("%d",a:sz/1048576)."M"
12010 elseif a:sz >= 1048576
12011 let sz = printf("%.1f",a:sz/1048576.0)."M"
12012 elseif a:sz >= 10240
12013 let sz = printf("%d",a:sz/1024)."K"
12014 elseif a:sz >= 1024
12015 let sz = printf("%.1f",a:sz/1024.0)."K"
12016 else
12017 let sz= a:sz
12018 endif
12019
12020 else
12021 let sz= a:sz
12022 endif
12023
12024" call Dret("s:NetrwHumanReadable ".sz)
12025 return sz
12026endfun
12027
12028" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012029" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12030" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12031fun! s:NetrwRestoreWordPosn()
12032" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012033 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012034" call Dret("NetrwRestoreWordPosn")
12035endfun
12036
12037" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012038" s:RestoreBufVars: {{{2
12039fun! s:RestoreBufVars()
12040" call Dfunc("s:RestoreBufVars()")
12041
12042 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12043 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12044 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12045 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12046 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12047 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12048
12049" call Dret("s:RestoreBufVars")
12050endfun
12051
12052" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012053" s:RemotePathAnalysis: {{{2
12054fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012055" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012056
Bram Moolenaara6878372014-03-22 21:02:50 +010012057 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012058 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012059 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012060 let s:user = substitute(a:dirname,dirpat,'\3','')
12061 let s:machine = substitute(a:dirname,dirpat,'\4','')
12062 let s:port = substitute(a:dirname,dirpat,'\5','')
12063 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012064 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012065 if s:machine =~ '@'
12066 let dirpat = '^\(.*\)@\(.\{-}\)$'
12067 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12068 let s:machine = substitute(s:machine,dirpat,'\2','')
12069 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012070
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012071" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12072" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12073" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12074" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12075" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12076" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012077
12078" call Dret("s:RemotePathAnalysis")
12079endfun
12080
12081" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012082" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12083" Returns status
12084" Runs system() on
12085" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012086" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012087fun! s:RemoteSystem(cmd)
12088" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12089 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012090 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 +000012091 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012092 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012093 else
12094 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12095 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12096 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012097 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012098 else
12099 let cmd= cmd.' '
12100 endif
12101 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012102" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012103 let ret= system(cmd)
12104 endif
12105" call Dret("s:RemoteSystem ".ret)
12106 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012107endfun
12108
12109" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012110" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012111fun! s:RestoreWinVars()
12112" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012113 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12115 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12116 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12117 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12118 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12119 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12120 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12121 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12122 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12123 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12124 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12125 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012126 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12127 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012128 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12129 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12130 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12131" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012132endfun
12133
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012134" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012135" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12136"
12137" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12138" is true) and a command, :Rexplore, which call this function.
12139"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012140" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012141"
12142" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012143fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012144 if exists("s:netrwdrag")
12145 return
12146 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012147" 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 +010012148" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12149" 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 +010012150
12151 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012152 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012153" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012154 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012155 unlet w:netrw_rexfile
12156" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012157 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012158" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012159" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12160" 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 +020012161 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012162
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012163 " ---------------------------
12164 " :Rex issued while in a file
12165 " ---------------------------
12166
Bram Moolenaara6878372014-03-22 21:02:50 +010012167 " record current file so :Rex can return to it from netrw
12168 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012169" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012170
12171 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012172" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012173 return
12174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012175" 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 +020012176 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012177 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012178 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012179 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012180 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012181 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012182 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012183 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012185" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12186 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012187" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12188 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012189 if exists("s:rexposn_".bufnr('%'))
12190 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012191 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012192 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012193" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012194 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012195
Bram Moolenaar85850f32019-07-19 22:05:51 +020012196 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12197 if exists("s:explore_match")
12198 exe "2match netrwMarkFile /".s:explore_match."/"
12199 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012200 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012201
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012202" 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 +010012203" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012204endfun
12205
12206" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012207" s:SaveBufVars: save selected b: variables to s: variables {{{2
12208" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012209fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012210" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012211
12212 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12213 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12214 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12215 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12216 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12217 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12218
12219" call Dret("s:SaveBufVars")
12220endfun
12221
12222" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012223" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12224fun! s:SavePosn(posndict)
12225" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12226
Bram Moolenaar85850f32019-07-19 22:05:51 +020012227 if !exists("a:posndict[bufnr('%')]")
12228 let a:posndict[bufnr("%")]= []
12229 endif
12230" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12231 call add(a:posndict[bufnr("%")],winsaveview())
12232" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012233
12234" call Dret("s:SavePosn posndict")
12235 return a:posndict
12236endfun
12237
12238" ---------------------------------------------------------------------
12239" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12240fun! s:RestorePosn(posndict)
12241" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242 if exists("a:posndict")
12243 if has_key(a:posndict,bufnr("%"))
12244" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12245 let posnlen= len(a:posndict[bufnr("%")])
12246 if posnlen > 0
12247 let posnlen= posnlen - 1
12248" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12249 call winrestview(a:posndict[bufnr("%")][posnlen])
12250 call remove(a:posndict[bufnr("%")],posnlen)
12251" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12252 endif
12253 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012254 endif
12255" call Dret("s:RestorePosn")
12256endfun
12257
12258" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012259" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012260fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012261" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012262 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12263 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12264 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12265 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12266 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12267 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12268 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12269 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12270 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12271 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12272 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12273 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12274 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12275 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12276 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12277 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12278 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12279 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12280" call Dret("s:SaveWinVars")
12281endfun
12282
12283" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012284" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012285" To allow separate windows to have their own activities, such as
12286" Explore **/pattern, several variables have been made window-oriented.
12287" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012288" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012289" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012290fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012291" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012292 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12293 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12294 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12295 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12296 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12297 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12298 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12299 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12300 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12301 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12302" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012303endfun
12304
12305" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012306" s:SetRexDir: set directory for :Rexplore {{{2
12307fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012308" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012309 let w:netrw_rexdir = a:dirname
12310 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012311 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012312" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12313" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012314" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012315" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012316" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012317endfun
12318
12319" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012320" s:ShowLink: used to modify thin and tree listings to show links {{{2
12321fun! s:ShowLink()
12322" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012323" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12324" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012325 if exists("b:netrw_curdir")
12326 norm! $?\a
12327 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12328 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012329" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12330" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12331" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12332 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012333 let dirlen = strlen(b:netrw_curdir)
12334 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012335" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012336 endif
12337 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012338" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12339" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012340 setl noro ma
12341 call setline(".",modline)
12342 setl ro noma nomod
12343 endif
12344" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12345endfun
12346
12347" ---------------------------------------------------------------------
12348" s:ShowStyle: {{{2
12349fun! s:ShowStyle()
12350 if !exists("w:netrw_liststyle")
12351 let liststyle= g:netrw_liststyle
12352 else
12353 let liststyle= w:netrw_liststyle
12354 endif
12355 if liststyle == s:THINLIST
12356 return s:THINLIST.":thin"
12357 elseif liststyle == s:LONGLIST
12358 return s:LONGLIST.":long"
12359 elseif liststyle == s:WIDELIST
12360 return s:WIDELIST.":wide"
12361 elseif liststyle == s:TREELIST
12362 return s:TREELIST.":tree"
12363 else
12364 return 'n/a'
12365 endif
12366endfun
12367
12368" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012369" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12370" Solution from Nicolai Weibull, vim docs (:help strlen()),
12371" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012372fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012373" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12374
12375 if v:version >= 703 && exists("*strdisplaywidth")
12376 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012377
Bram Moolenaar8d043172014-01-23 14:24:41 +010012378 elseif type(g:Align_xstrlen) == 1
12379 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12380 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012381
Bram Moolenaar8d043172014-01-23 14:24:41 +010012382 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012383 " number of codepoints (Latin a + combining circumflex is two codepoints)
12384 " (comment from TM, solution from NW)
12385 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012386
Bram Moolenaar8d043172014-01-23 14:24:41 +010012387 elseif g:Align_xstrlen == 2
12388 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012389 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12390 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012391 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012392
Bram Moolenaar8d043172014-01-23 14:24:41 +010012393 elseif g:Align_xstrlen == 3
12394 " virtual length (counting, for instance, tabs as anything between 1 and
12395 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012396 " preceded by lam, one otherwise, etc.)
12397 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012398 let modkeep= &l:mod
12399 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012400 call setline(line("."),a:x)
12401 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012402 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012403 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012404 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012405
Bram Moolenaar446cb832008-06-24 21:56:24 +000012406 else
12407 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012408 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012409 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012410" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012411 return ret
12412endfun
12413
12414" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012415" s:ShellEscape: shellescape(), or special windows handling {{{2
12416fun! s:ShellEscape(s, ...)
12417 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12418 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12419 endif
12420 let f = a:0 > 0 ? a:1 : 0
12421 return shellescape(a:s, f)
12422endfun
12423
12424" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012425" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012426fun! s:TreeListMove(dir)
12427" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012428 let curline = getline('.')
12429 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12430 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12431 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12432 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12433 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12434 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12435" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12436" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12437" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12438" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12439" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12440 " COMBAK : need to handle when on a directory
12441 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012442 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012443 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012444 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012445 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012447 elseif a:dir == '[]' && nxtline != ''
12448 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012449" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012450 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12451 if nl != 0
12452 NetrwKeepj norm! k
12453 else
12454 NetrwKeepj norm! G
12455 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012457 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012458 endif
12459
12460" call Dret("s:TreeListMove")
12461endfun
12462
12463" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012464" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12465" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12466" can't be called except via emenu. But due to locale, that menu line may not be called
12467" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12468fun! s:UpdateBuffersMenu()
12469" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012470 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012471 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012472 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012473 catch /^Vim\%((\a\+)\)\=:E/
12474 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012475 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012476 endtry
12477 endif
12478" call Dret("s:UpdateBuffersMenu")
12479endfun
12480
12481" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012482" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012483" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012484fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012485" call Dfunc("s:UseBufWinVars()")
12486 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012487 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12488 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12489 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12490 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12491 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12492 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12493 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12494 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12495 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 +000012496" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012497endfun
12498
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012499" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012500" s:UserMaps: supports user-defined UserMaps {{{2
12501" * calls a user-supplied funcref(islocal,curdir)
12502" * interprets result
12503" See netrw#UserMaps()
12504fun! s:UserMaps(islocal,funcname)
12505" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12506
12507 if !exists("b:netrw_curdir")
12508 let b:netrw_curdir= getcwd()
12509 endif
12510 let Funcref = function(a:funcname)
12511 let result = Funcref(a:islocal)
12512
12513 if type(result) == 1
12514 " if result from user's funcref is a string...
12515" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12516 if result == "refresh"
12517" call Decho("refreshing display",'~'.expand("<slnum>"))
12518 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12519 elseif result != ""
12520" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12521 exe result
12522 endif
12523
12524 elseif type(result) == 3
12525 " if result from user's funcref is a List...
12526" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12527 for action in result
12528 if action == "refresh"
12529" call Decho("refreshing display",'~'.expand("<slnum>"))
12530 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12531 elseif action != ""
12532" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12533 exe action
12534 endif
12535 endfor
12536 endif
12537
12538" call Dret("s:UserMaps")
12539endfun
12540
Bram Moolenaar85850f32019-07-19 22:05:51 +020012541" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012542" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012543" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012544let &cpo= s:keepcpo
12545unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012546
Bram Moolenaar85850f32019-07-19 22:05:51 +020012547" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012548" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012549" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012550" vim:ts=8 fdm=marker